diff mercurial/hgweb/protocol.py @ 11623:31d0a6d50ee2

protocol: extract compression from streaming mechanics
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Fri, 16 Jul 2010 22:20:10 +0200
parents 1d48681b17a4
children cdeb861335d5
line wrap: on
line diff
--- a/mercurial/hgweb/protocol.py	Fri Jul 16 18:18:35 2010 +0200
+++ b/mercurial/hgweb/protocol.py	Fri Jul 16 22:20:10 2010 +0200
@@ -35,22 +35,21 @@
     def redirect(self):
         self.oldio = sys.stdout, sys.stderr
         sys.stderr = sys.stdout = cStringIO.StringIO()
-    def sendresponse(self, s):
-        self.req.respond(HTTP_OK, HGTYPE, length=len(s))
-        self.response = s
-    def sendchangegroup(self, cg):
-        self.req.respond(HTTP_OK, HGTYPE)
+    def groupchunks(self, cg):
         z = zlib.compressobj()
         while 1:
             chunk = cg.read(4096)
             if not chunk:
                 break
-            self.req.write(z.compress(chunk))
-        self.req.write(z.flush())
+            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:
-            self.req.write(chunk)
+            self.req.write(str(chunk))
     def sendpushresponse(self, ret):
         val = sys.stdout.getvalue()
         sys.stdout, sys.stderr = self.oldio