Update urllib3 to 7b82da0fa3a13514d11a863e379e7541d0ec46ef
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Ian Cordasco · committed by Ian Cordasco · parent 3880cf1 · Browse files · 1 file·+34 added−18 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+34 added−18 removed
- other:+34 added−18 removed
Provenance
- Commit
73b9b69- Tree
b216c7d- Author
Ian Cordasco <ian.cordasco@rackspace.com>- Committer
Ian Cordasco <ian.cordasco@rackspace.com>- Parent
3880cf1
1 file changed+34 added−18 removed
modified:requests/packages/urllib3/response.py+34 added-18 removed
170 unmodified lines171 are encoded on the wire (e.g, compressed).172 """173 return self._fp_bytes_read174 175+ def _init_decoder(self):176+ """177+ Set-up the _decoder attribute if necessar.178+ """179+ # Note: content-encoding value should be case-insensitive, per RFC 7230180+ # Section 3.2181+ content_encoding = self.headers.get('content-encoding', '').lower()182+ if self._decoder is None:183+ if content_encoding in self.CONTENT_DECODERS:184+ self._decoder = _get_decoder(content_encoding)185+186+ def _decode(self, data, decode_content, flush_decoder):187+ """188+ Decode the data passed in and potentially flush the decoder.189+ """190+ try:191+ if decode_content and self._decoder:192+ data = self._decoder.decompress(data)193+ except (IOError, zlib.error) as e:194+ content_encoding = self.headers.get('content-encoding', '').lower()195+ raise DecodeError(196+ "Received response with content-encoding: %s, but "197+ "failed to decode it." % content_encoding, e)198+199+ if flush_decoder and decode_content and self._decoder:200+ buf = self._decoder.decompress(binary_type())201+ data += buf + self._decoder.flush()202+203+ return data204+205 def read(self, amt=None, decode_content=None, cache_content=False):206 """207 Similar to :meth:`httplib.HTTPResponse.read`, but with two additional208 parameters: ``decode_content`` and ``cache_content``.13 unmodified lines222 is useful if you want the ``.data`` property to continue working223 after having ``.read()`` the file object. (Overridden if ``amt`` is224 set.)225 """196- # Note: content-encoding value should be case-insensitive, per RFC 7230197- # Section 3.2198- content_encoding = self.headers.get('content-encoding', '').lower()199- if self._decoder is None:200- if content_encoding in self.CONTENT_DECODERS:201- self._decoder = _get_decoder(content_encoding)226+ self._init_decoder()227 if decode_content is None:228 decode_content = self.decode_content229 230 if self._fp is None:40 unmodified lines271 raise ProtocolError('Connection broken: %r' % e, e)272 273 self._fp_bytes_read += len(data)274 250- try:251- if decode_content and self._decoder:252- data = self._decoder.decompress(data)253- except (IOError, zlib.error) as e:254- raise DecodeError(255- "Received response with content-encoding: %s, but "256- "failed to decode it." % content_encoding, e)275+ data = self._decode(data, decode_content, flush_decoder)276 258- if flush_decoder and decode_content and self._decoder:259- buf = self._decoder.decompress(binary_type())260- data += buf + self._decoder.flush()261-277 if cache_content:278 self._body = data279 280 return data17 unmodified lines298 :param decode_content:299 If True, will attempt to decode the body based on the300 'content-encoding' header.301 """302+ self._init_decoder()303 if self.chunked:304 for line in self.read_chunked(amt):289- yield line305+ yield self._decode(line, decode_content, True)306 else:307 while not is_fp_closed(self._fp):308 data = self.read(amt=amt, decode_content=decode_content)309 135 unmodified lines