# HG changeset patch # User Gregory Szorc <gregory.sz...@gmail.com> # Date 1492153410 25200 # Fri Apr 14 00:03:30 2017 -0700 # Node ID 8525abda8397f2a5a94edc5db2279549ef53b8e8 # Parent b8a66f70caadbe53bf2ea43b0be1d1d8acba94ad 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 _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel