Skip to content
Myr

Synchronize urllib3 to 1.10.4

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Cory Benfield · committed by Cory Benfield · parent 6acca21 · Browse files · 3 files+78 added−53 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+78 added−53 removed

  • other:+78 added−53 removed

3 files+78 added−53 removed

modified:requests/packages/urllib3/util/url.py+2 added
13 unmodified lines
14 slots = ()1516 def __new__(cls, scheme=None, auth=None, host=None, port=None, path=None,17 query=None, fragment=None):18 if path and not path.startswith('/'):19 path = '/' + path20 return super(Url, cls).__new__(cls, scheme, auth, host, port, path,21 query, fragment)2223 @property
191 unmodified lines
modified:requests/packages/urllib3/__init__.py+4 added-3 removed
2 unmodified lines
3"""45__author__ = 'Andrey Petrov (andrey.petrov@shazow.net)'6__license__ = 'MIT'7__version__ = '1.10.3'7__version__ = '1.10.4'8910from .connectionpool import (11 HTTPConnectionPool,
44 unmodified lines
565758import warnings59# SecurityWarning's always go off by default.60warnings.simplefilter('always', exceptions.SecurityWarning)60warnings.simplefilter('always', exceptions.SecurityWarning, append=True)61# InsecurePlatformWarning's don't vary between requests, so we keep it default.62warnings.simplefilter('default', exceptions.InsecurePlatformWarning)62warnings.simplefilter('default', exceptions.InsecurePlatformWarning,63 append=True)6465def disable_warnings(category=exceptions.HTTPWarning):66 """67 Helper for quickly disabling all urllib3 warnings.
2 unmodified lines
modified:requests/packages/urllib3/response.py+72 added-50 removed
124 unmodified lines
125126 # Are we using the chunked-style of transfer encoding?127 self.chunked = False128 self.chunk_left = None129 tr_enc = self.headers.get('transfer-encoding', '')130 if tr_enc.lower() == "chunked":129 tr_enc = self.headers.get('transfer-encoding', '').lower()130 # Don't incur the penalty of creating a list and then discarding it131 encodings = (enc.strip() for enc in tr_enc.split(","))132 if "chunked" in encodings:133 self.chunked = True134135 # We certainly don't want to preload content when the response is chunked.134 if not self.chunked:135 if preload_content and not self._body:136 self._body = self.read(decode_content=decode_content)136 if not self.chunked and preload_content and not self._body:137 self._body = self.read(decode_content=decode_content)138139 def get_redirect_location(self):140 """141 Should we redirect and where to?
37 unmodified lines
179 """180 # Note: content-encoding value should be case-insensitive, per RFC 7230181 # Section 3.2182 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)183 if self._decoder is None and content_encoding in self.CONTENT_DECODERS:184 self._decoder = _get_decoder(content_encoding)185186 def _decode(self, data, decode_content, flush_decoder):187 """188 Decode the data passed in and potentially flush the decoder.
109 unmodified lines
298 :param decode_content:299 If True, will attempt to decode the body based on the300 'content-encoding' header.301 """302 self._init_decoder()302 if self.chunked:304 for line in self.read_chunked(amt):305 yield self._decode(line, decode_content, True)303 for line in self.read_chunked(amt, decode_content=decode_content):304 yield line305 else:306 while not is_fp_closed(self._fp):307 data = self.read(amt=amt, decode_content=decode_content)308
76 unmodified lines
385 else:386 b[:len(temp)] = temp387 return len(temp)388390 def read_chunked(self, amt=None):391 # FIXME: Rewrite this method and make it a class with392 # a better structured logic.389 def _update_chunk_length(self):390 # First, we'll figure out length of a chunk and then391 # we'll try to read it from socket.392 if self.chunk_left is not None:393 return394 line = self._fp.fp.readline()395 line = line.split(b';', 1)[0]396 try:397 self.chunk_left = int(line, 16)398 except ValueError:399 # Invalid chunked protocol response, abort.400 self.close()401 raise httplib.IncompleteRead(line)402403 def _handle_chunk(self, amt):404 returned_chunk = None405 if amt is None:406 chunk = self._fp._safe_read(self.chunk_left)407 returned_chunk = chunk408 self._fp._safe_read(2) # Toss the CRLF at the end of the chunk.409 self.chunk_left = None410 elif amt < self.chunk_left:411 value = self._fp._safe_read(amt)412 self.chunk_left = self.chunk_left - amt413 returned_chunk = value414 elif amt == self.chunk_left:415 value = self._fp._safe_read(amt)416 self._fp._safe_read(2) # Toss the CRLF at the end of the chunk.417 self.chunk_left = None418 returned_chunk = value419 else: # amt > self.chunk_left420 returned_chunk = self._fp._safe_read(self.chunk_left)421 self._fp._safe_read(2) # Toss the CRLF at the end of the chunk.422 self.chunk_left = None423 return returned_chunk424425 def read_chunked(self, amt=None, decode_content=None):426 """427 Similar to :meth:`HTTPResponse.read`, but with an additional428 parameter: ``decode_content``.429430 :param decode_content:431 If True, will attempt to decode the body based on the432 'content-encoding' header.433 """434 self._init_decoder()435 # FIXME: Rewrite this method and make it a class with a better structured logic.436 if not self.chunked:437 raise ResponseNotChunked("Response is not chunked. "438 "Header 'transfer-encoding: chunked' is missing.")439440 if self._original_response and self._original_response._method.upper() == 'HEAD':441 # Don't bother reading the body of a HEAD request.442 # FIXME: Can we do this somehow without accessing private httplib _method?443 self._original_response.close()444 return445446 while True:397 # First, we'll figure out length of a chunk and then398 # we'll try to read it from socket.399 if self.chunk_left is None:400 line = self._fp.fp.readline()401 line = line.decode()402 # See RFC 7230: Chunked Transfer Coding.403 i = line.find(';')404 if i >= 0:405 line = line[:i] # Strip chunk-extensions.406 try:407 self.chunk_left = int(line, 16)408 except ValueError:409 # Invalid chunked protocol response, abort.410 self.close()411 raise httplib.IncompleteRead(''.join(line))412 if self.chunk_left == 0:413 break414 if amt is None:415 chunk = self._fp._safe_read(self.chunk_left)416 yield chunk417 self._fp._safe_read(2) # Toss the CRLF at the end of the chunk.418 self.chunk_left = None419 elif amt < self.chunk_left:420 value = self._fp._safe_read(amt)421 self.chunk_left = self.chunk_left - amt422 yield value423 elif amt == self.chunk_left:424 value = self._fp._safe_read(amt)425 self._fp._safe_read(2) # Toss the CRLF at the end of the chunk.426 self.chunk_left = None427 yield value428 else: # amt > self.chunk_left429 yield self._fp._safe_read(self.chunk_left)430 self._fp._safe_read(2) # Toss the CRLF at the end of the chunk.431 self.chunk_left = None447 self._update_chunk_length()448 if self.chunk_left == 0:449 break450 chunk = self._handle_chunk(amt)451 yield self._decode(chunk, decode_content=decode_content,452 flush_decoder=True)453454 # Chunk content ends with \r\n: discard it.455 while True:456 line = self._fp.fp.readline()
3 unmodified lines
460 if line == b'\r\n':461 break462463 # We read everything; close the "file".464 if self._original_response:465 self._original_response.close()466 self.release_conn()444