# HG changeset patch # User Gregory Szorc # Date 2017-04-14 07:03:30 # Node ID 84569d2b3fb77f73eec0729141598420a6f5510d # Parent bf855efe5664feb70a630ba2663b262fc15282ad 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. diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py --- a/mercurial/httppeer.py +++ b/mercurial/httppeer.py @@ -31,30 +31,6 @@ httplib = util.httplib 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 @@ class httppeer(wireproto.wirepeer): 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 @@ class httppeer(wireproto.wirepeer): 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