From: Kenneth Reitz Date: Sat, 1 Oct 2011 10:04:18 +0000 (-0400) Subject: urllib3 update X-Git-Tag: v0.8.0~94^2~30 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c9f5614417fc2b997e2e5223d8bdacf07b9e13be;p=services%2Fpython-requests.git urllib3 update --- diff --git a/requests/packages/urllib3/__init__.py b/requests/packages/urllib3/__init__.py index 19a6239..5c4b5d1 100644 --- a/requests/packages/urllib3/__init__.py +++ b/requests/packages/urllib3/__init__.py @@ -1,3 +1,9 @@ +# urllib3/__init__.py +# Copyright 2008-2011 Andrey Petrov and contributors (see CONTRIBUTORS.txt) +# +# This module is part of urllib3 and is released under +# the MIT License: http://www.opensource.org/licenses/mit-license.php + """ urllib3 - Thread-safe connection pooling and re-using. """ diff --git a/requests/packages/urllib3/_collections.py b/requests/packages/urllib3/_collections.py index 0e1c8e6..2b0de0e 100644 --- a/requests/packages/urllib3/_collections.py +++ b/requests/packages/urllib3/_collections.py @@ -1,3 +1,9 @@ +# urllib3/_collections.py +# Copyright 2008-2011 Andrey Petrov and contributors (see CONTRIBUTORS.txt) +# +# This module is part of urllib3 and is released under +# the MIT License: http://www.opensource.org/licenses/mit-license.php + from collections import MutableMapping, deque diff --git a/requests/packages/urllib3/connectionpool.py b/requests/packages/urllib3/connectionpool.py index add6fbc..92ce154 100644 --- a/requests/packages/urllib3/connectionpool.py +++ b/requests/packages/urllib3/connectionpool.py @@ -1,3 +1,9 @@ +# urllib3/connectionpool.py +# Copyright 2008-2011 Andrey Petrov and contributors (see CONTRIBUTORS.txt) +# +# This module is part of urllib3 and is released under +# the MIT License: http://www.opensource.org/licenses/mit-license.php + import logging import socket @@ -191,10 +197,12 @@ class HTTPConnectionPool(ConnectionPool): if timeout is _Default: timeout = self.timeout + conn.request(method, url, **httplib_request_kw) conn.sock.settimeout(timeout) httplib_response = conn.getresponse() + log.debug("\"%s %s %s\" %s %s" % (method, url, conn._http_vsn_str, # pylint: disable-msg=W0212 @@ -276,14 +284,17 @@ class HTTPConnectionPool(ConnectionPool): raise HostChangedError("Connection pool with host '%s' tried to " "open a foreign host: %s" % (host, url)) - # Request a connection from the queue - conn = self._get_conn(timeout=pool_timeout) + conn = None try: + # Request a connection from the queue + # (Could raise SocketError: Bad file descriptor) + conn = self._get_conn(timeout=pool_timeout) # Make the request on the httplib connection object httplib_response = self._make_request(conn, method, url, timeout=timeout, body=body, headers=headers) + # print '!' # Import httplib's response into our own wrapper object response = HTTPResponse.from_httplib(httplib_response, @@ -291,8 +302,14 @@ class HTTPConnectionPool(ConnectionPool): connection=conn, **response_kw) - # The connection will be put back into the pool when - # response.release_conn() is called (implicitly by response.read()) + if release_conn: + # The connection will be released manually in the ``finally:`` + response.connection = None + + # else: + # The connection will be put back into the pool when + # ``response.release_conn()`` is called (implicitly by + # ``response.read()``) except (SocketTimeout, Empty), e: # Timed out either by socket or queue @@ -308,10 +325,9 @@ class HTTPConnectionPool(ConnectionPool): conn = None finally: - if release_conn: + if conn and release_conn: # Put the connection back to be reused - response.release_conn() # Equivalent to self._put_conn(conn) but - # tracks release state. + self._put_conn(conn) if not conn: log.warn("Retrying (%d attempts remain) after connection " @@ -399,7 +415,7 @@ class HTTPSConnectionPool(HTTPConnectionPool): strict=False, timeout=None, maxsize=1, block=False, headers=None, key_file=None, cert_file=None, - cert_reqs='CERT_NONE', ca_certs=None): + cert_reqs=ssl.CERT_REQUIRED, ca_certs=None): super(HTTPSConnectionPool, self).__init__(host, port, strict, timeout, maxsize, @@ -413,6 +429,7 @@ class HTTPSConnectionPool(HTTPConnectionPool): """ Return a fresh HTTPSConnection. """ + self.num_connections += 1 log.info("Starting new HTTPS connection (%d): %s" % (self.num_connections, self.host)) diff --git a/requests/packages/urllib3/contrib/ntlmpool.py b/requests/packages/urllib3/contrib/ntlmpool.py index a4642fa..c5f010e 100644 --- a/requests/packages/urllib3/contrib/ntlmpool.py +++ b/requests/packages/urllib3/contrib/ntlmpool.py @@ -1,3 +1,9 @@ +# urllib3/contrib/ntlmpool.py +# Copyright 2008-2011 Andrey Petrov and contributors (see CONTRIBUTORS.txt) +# +# This module is part of urllib3 and is released under +# the MIT License: http://www.opensource.org/licenses/mit-license.php + """ NTLM authenticating pool, contributed by erikcederstran diff --git a/requests/packages/urllib3/exceptions.py b/requests/packages/urllib3/exceptions.py index 45b0e82..69f459b 100644 --- a/requests/packages/urllib3/exceptions.py +++ b/requests/packages/urllib3/exceptions.py @@ -1,3 +1,9 @@ +# urllib3/exceptions.py +# Copyright 2008-2011 Andrey Petrov and contributors (see CONTRIBUTORS.txt) +# +# This module is part of urllib3 and is released under +# the MIT License: http://www.opensource.org/licenses/mit-license.php + ## Exceptions class HTTPError(Exception): diff --git a/requests/packages/urllib3/filepost.py b/requests/packages/urllib3/filepost.py index 67d2d0d..8e65b5c 100644 --- a/requests/packages/urllib3/filepost.py +++ b/requests/packages/urllib3/filepost.py @@ -1,3 +1,9 @@ +# urllib3/filepost.py +# Copyright 2008-2011 Andrey Petrov and contributors (see CONTRIBUTORS.txt) +# +# This module is part of urllib3 and is released under +# the MIT License: http://www.opensource.org/licenses/mit-license.php + import codecs import mimetools import mimetypes diff --git a/requests/packages/urllib3/poolmanager.py b/requests/packages/urllib3/poolmanager.py index 1863696..d5b7613 100644 --- a/requests/packages/urllib3/poolmanager.py +++ b/requests/packages/urllib3/poolmanager.py @@ -1,3 +1,9 @@ +# urllib3/poolmanager.py +# Copyright 2008-2011 Andrey Petrov and contributors (see CONTRIBUTORS.txt) +# +# This module is part of urllib3 and is released under +# the MIT License: http://www.opensource.org/licenses/mit-license.php + from ._collections import RecentlyUsedContainer from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, get_host @@ -40,6 +46,7 @@ class PoolManager(object): """ pool_key = (scheme, host, port) + # If the scheme, host, or port doesn't match existing open connections, # open a new ConnectionPool. pool = self.pools.get(pool_key) @@ -64,7 +71,7 @@ class PoolManager(object): port = port or port_by_scheme.get(scheme, 80) - return self.connection_from_host(host, port=port, scheme=scheme) + return self.connection_from_host(host, port=port, scheme=scheme) def urlopen(self, method, url, **kw): "Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute." diff --git a/requests/packages/urllib3/response.py b/requests/packages/urllib3/response.py index 8c847ce..2bbc06a 100644 --- a/requests/packages/urllib3/response.py +++ b/requests/packages/urllib3/response.py @@ -1,3 +1,9 @@ +# urllib3/response.py +# Copyright 2008-2011 Andrey Petrov and contributors (see CONTRIBUTORS.txt) +# +# This module is part of urllib3 and is released under +# the MIT License: http://www.opensource.org/licenses/mit-license.php + import gzip import logging import zlib