Show More
@@ -31,30 +31,6 b' httplib = util.httplib' | |||
|
31 | 31 | urlerr = util.urlerr |
|
32 | 32 | urlreq = util.urlreq |
|
33 | 33 | |
|
34 | # FUTURE: consider refactoring this API to use generators. This will | |
|
35 | # require a compression engine API to emit generators. | |
|
36 | def decompressresponse(response, engine): | |
|
37 | try: | |
|
38 | reader = engine.decompressorreader(response) | |
|
39 | except httplib.HTTPException: | |
|
40 | raise IOError(None, _('connection ended unexpectedly')) | |
|
41 | ||
|
42 | # We need to wrap reader.read() so HTTPException on subsequent | |
|
43 | # reads is also converted. | |
|
44 | # Ideally we'd use super() here. However, if ``reader`` isn't a new-style | |
|
45 | # class, this can raise: | |
|
46 | # TypeError: super() argument 1 must be type, not classobj | |
|
47 | origread = reader.read | |
|
48 | class readerproxy(reader.__class__): | |
|
49 | def read(self, *args, **kwargs): | |
|
50 | try: | |
|
51 | return origread(*args, **kwargs) | |
|
52 | except httplib.HTTPException: | |
|
53 | raise IOError(None, _('connection ended unexpectedly')) | |
|
54 | ||
|
55 | reader.__class__ = readerproxy | |
|
56 | return reader | |
|
57 | ||
|
58 | 34 | def encodevalueinheaders(value, header, limit): |
|
59 | 35 | """Encode a string value into multiple HTTP headers. |
|
60 | 36 | |
@@ -297,9 +273,11 b' class httppeer(wireproto.wirepeer):' | |||
|
297 | 273 | raise error.RepoError(_("'%s' sent a broken Content-Type " |
|
298 | 274 | "header (%s)") % (safeurl, proto)) |
|
299 | 275 | |
|
276 | # TODO consider switching to a decompression reader that uses | |
|
277 | # generators. | |
|
300 | 278 | if version_info == (0, 1): |
|
301 | 279 | if _compressible: |
|
302 |
return |
|
|
280 | return util.compengines['zlib'].decompressorreader(resp) | |
|
303 | 281 | return resp |
|
304 | 282 | elif version_info == (0, 2): |
|
305 | 283 | # application/mercurial-0.2 always identifies the compression |
@@ -307,13 +285,13 b' class httppeer(wireproto.wirepeer):' | |||
|
307 | 285 | elen = struct.unpack('B', resp.read(1))[0] |
|
308 | 286 | ename = resp.read(elen) |
|
309 | 287 | engine = util.compengines.forwiretype(ename) |
|
310 |
return decompress |
|
|
288 | return engine.decompressorreader(resp) | |
|
311 | 289 | else: |
|
312 | 290 | raise error.RepoError(_("'%s' uses newer protocol %s") % |
|
313 | 291 | (safeurl, version)) |
|
314 | 292 | |
|
315 | 293 | if _compressible: |
|
316 |
return |
|
|
294 | return util.compengines['zlib'].decompressorreader(resp) | |
|
317 | 295 | |
|
318 | 296 | return resp |
|
319 | 297 |
General Comments 0
You need to be logged in to leave comments.
Login now