diff mercurial/hgweb/protocol.py @ 11625:cdeb861335d5

protocol: wrap non-string protocol responses in classes
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Tue, 20 Jul 2010 20:53:33 +0200
parents 31d0a6d50ee2
children 2f8adc60e013
line wrap: on
line diff
--- a/mercurial/hgweb/protocol.py	Fri Jul 16 22:20:19 2010 +0200
+++ b/mercurial/hgweb/protocol.py	Tue Jul 20 20:53:33 2010 +0200
@@ -48,13 +48,20 @@
         self.response = s
     def sendstream(self, source):
         self.req.respond(HTTP_OK, HGTYPE)
-        for chunk in source:
-            self.req.write(str(chunk))
-    def sendpushresponse(self, ret):
+        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' % (ret, val)
+        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',
@@ -66,5 +73,6 @@
 
 def call(repo, req, cmd):
     p = webproto(req)
-    wireproto.dispatch(repo, p, cmd)
-    yield p.response
+    rsp = wireproto.dispatch(repo, p, cmd)
+    webproto.handlers[rsp.__class__](p, rsp)
+    return [p.response]