# HG changeset patch # User Dirkjan Ochtman # Date 1279612597 -7200 # Node ID 2f8adc60e01328523052b1829ca9846ec1285f60 # Parent cdeb861335d5dbabc41367c1806dd41541476583 protocol: use generators instead of req.write() for hgweb stream responses diff -r cdeb861335d5 -r 2f8adc60e013 mercurial/hgweb/protocol.py --- a/mercurial/hgweb/protocol.py Tue Jul 20 20:53:33 2010 +0200 +++ b/mercurial/hgweb/protocol.py Tue Jul 20 09:56:37 2010 +0200 @@ -43,25 +43,6 @@ break yield z.compress(chunk) yield z.flush() - def sendresponse(self, s): - self.req.respond(HTTP_OK, HGTYPE, length=len(s)) - self.response = s - def sendstream(self, source): - self.req.respond(HTTP_OK, HGTYPE) - for chunk in source.gen: - self.req.write(chunk) - def sendpushresponse(self, rsp): - val = sys.stdout.getvalue() - sys.stdout, sys.stderr = self.oldio - self.req.respond(HTTP_OK, HGTYPE) - self.response = '%d\n%s' % (rsp.res, val) - - handlers = { - str: sendresponse, - wireproto.streamres: sendstream, - wireproto.pushres: sendpushresponse, - } - def _client(self): return 'remote:%s:%s:%s' % ( self.req.env.get('wsgi.url_scheme') or 'http', @@ -74,5 +55,14 @@ def call(repo, req, cmd): p = webproto(req) rsp = wireproto.dispatch(repo, p, cmd) - webproto.handlers[rsp.__class__](p, rsp) - return [p.response] + if isinstance(rsp, str): + req.respond(HTTP_OK, HGTYPE, length=len(rsp)) + return [rsp] + elif isinstance(rsp, wireproto.streamres): + req.respond(HTTP_OK, HGTYPE) + return rsp.gen + elif isinstance(rsp, wireproto.pushres): + val = sys.stdout.getvalue() + sys.stdout, sys.stderr = p.oldio + req.respond(HTTP_OK, HGTYPE) + return ['%d\n%s' % (rsp.res, val)]