changeset 32003:84569d2b3fb7

httppeer: eliminate decompressresponse() proxy Now that the response instance itself is wrapped with error handling, we no longer need this code. This code became dead with the previous patch because the added code catches HTTPException and re-raises as something else.
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 14 Apr 2017 00:03:30 -0700
parents bf855efe5664
children bd3cb917761a
files mercurial/httppeer.py
diffstat 1 files changed, 5 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/httppeer.py	Fri Apr 14 00:33:56 2017 -0700
+++ b/mercurial/httppeer.py	Fri Apr 14 00:03:30 2017 -0700
@@ -31,30 +31,6 @@
 urlerr = util.urlerr
 urlreq = util.urlreq
 
-# FUTURE: consider refactoring this API to use generators. This will
-# require a compression engine API to emit generators.
-def decompressresponse(response, engine):
-    try:
-        reader = engine.decompressorreader(response)
-    except httplib.HTTPException:
-        raise IOError(None, _('connection ended unexpectedly'))
-
-    # We need to wrap reader.read() so HTTPException on subsequent
-    # reads is also converted.
-    # Ideally we'd use super() here. However, if ``reader`` isn't a new-style
-    # class, this can raise:
-    # TypeError: super() argument 1 must be type, not classobj
-    origread = reader.read
-    class readerproxy(reader.__class__):
-        def read(self, *args, **kwargs):
-            try:
-                return origread(*args, **kwargs)
-            except httplib.HTTPException:
-                raise IOError(None, _('connection ended unexpectedly'))
-
-    reader.__class__ = readerproxy
-    return reader
-
 def encodevalueinheaders(value, header, limit):
     """Encode a string value into multiple HTTP headers.
 
@@ -297,9 +273,11 @@
                 raise error.RepoError(_("'%s' sent a broken Content-Type "
                                         "header (%s)") % (safeurl, proto))
 
+            # TODO consider switching to a decompression reader that uses
+            # generators.
             if version_info == (0, 1):
                 if _compressible:
-                    return decompressresponse(resp, util.compengines['zlib'])
+                    return util.compengines['zlib'].decompressorreader(resp)
                 return resp
             elif version_info == (0, 2):
                 # application/mercurial-0.2 always identifies the compression
@@ -307,13 +285,13 @@
                 elen = struct.unpack('B', resp.read(1))[0]
                 ename = resp.read(elen)
                 engine = util.compengines.forwiretype(ename)
-                return decompressresponse(resp, engine)
+                return engine.decompressorreader(resp)
             else:
                 raise error.RepoError(_("'%s' uses newer protocol %s") %
                                       (safeurl, version))
 
         if _compressible:
-            return decompressresponse(resp, util.compengines['zlib'])
+            return util.compengines['zlib'].decompressorreader(resp)
 
         return resp