Skip to content

Commit

Permalink
Update urllib3 to a27758625e4169330fcf965652b1093faf5aaaa2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Cordasco committed Jan 10, 2015
1 parent a57eacf commit d2d576b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion requests/packages/urllib3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def add_stderr_logger(level=logging.DEBUG):
del NullHandler


# Set security warning to only go off once by default.
# Set security warning to always go off by default.
import warnings
warnings.simplefilter('always', exceptions.SecurityWarning)

Expand Down
43 changes: 28 additions & 15 deletions requests/packages/urllib3/connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ def _validate_conn(self, conn):
"""
pass

def _prepare_proxy(self, conn):
# Nothing to do for HTTP connections.
pass

def _get_timeout(self, timeout):
""" Helper that always returns a :class:`urllib3.util.Timeout` """
if timeout is _Default:
Expand Down Expand Up @@ -510,11 +514,18 @@ def urlopen(self, method, url, body=None, headers=None, retries=None,

try:
# Request a connection from the queue.
timeout_obj = self._get_timeout(timeout)
conn = self._get_conn(timeout=pool_timeout)

conn.timeout = timeout_obj.connect_timeout

is_new_proxy_conn = self.proxy is not None and not getattr(conn, 'sock', None)
if is_new_proxy_conn:
self._prepare_proxy(conn)

# Make the request on the httplib connection object.
httplib_response = self._make_request(conn, method, url,
timeout=timeout,
timeout=timeout_obj,
body=body, headers=headers)

# If we're going to release the connection in ``finally:``, then
Expand Down Expand Up @@ -673,23 +684,25 @@ def _prepare_conn(self, conn):
assert_fingerprint=self.assert_fingerprint)
conn.ssl_version = self.ssl_version

if self.proxy is not None:
# Python 2.7+
try:
set_tunnel = conn.set_tunnel
except AttributeError: # Platform-specific: Python 2.6
set_tunnel = conn._set_tunnel
return conn

if sys.version_info <= (2, 6, 4) and not self.proxy_headers: # Python 2.6.4 and older
set_tunnel(self.host, self.port)
else:
set_tunnel(self.host, self.port, self.proxy_headers)
def _prepare_proxy(self, conn):
"""
Establish tunnel connection early, because otherwise httplib
would improperly set Host: header to proxy's IP:port.
"""
# Python 2.7+
try:
set_tunnel = conn.set_tunnel
except AttributeError: # Platform-specific: Python 2.6
set_tunnel = conn._set_tunnel

# Establish tunnel connection early, because otherwise httplib
# would improperly set Host: header to proxy's IP:port.
conn.connect()
if sys.version_info <= (2, 6, 4) and not self.proxy_headers: # Python 2.6.4 and older
set_tunnel(self.host, self.port)
else:
set_tunnel(self.host, self.port, self.proxy_headers)

return conn
conn.connect()

def _new_conn(self):
"""
Expand Down
5 changes: 5 additions & 0 deletions requests/packages/urllib3/contrib/pyopenssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ def recv(self, *args, **kwargs):
return b''
else:
raise
except OpenSSL.SSL.ZeroReturnError as e:
if self.connection.get_shutdown() == OpenSSL.SSL.RECEIVED_SHUTDOWN:
return b''
else:
raise
except OpenSSL.SSL.WantReadError:
rd, wd, ed = select.select(
[self.socket], [], [], self.socket.gettimeout())
Expand Down
2 changes: 1 addition & 1 deletion requests/packages/urllib3/util/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def _is_read_error(self, err):
return isinstance(err, (ReadTimeoutError, ProtocolError))

def is_forced_retry(self, method, status_code):
""" Is this method/response retryable? (Based on method/codes whitelists)
""" Is this method/status code retryable? (Based on method/codes whitelists)
"""
if self.method_whitelist and method.upper() not in self.method_whitelist:
return False
Expand Down

0 comments on commit d2d576b

Please sign in to comment.