urllib3 update
authorKenneth Reitz <me@kennethreitz.com>
Sat, 1 Oct 2011 10:04:18 +0000 (06:04 -0400)
committerKenneth Reitz <me@kennethreitz.com>
Sat, 1 Oct 2011 10:04:22 +0000 (06:04 -0400)
requests/packages/urllib3/__init__.py
requests/packages/urllib3/_collections.py
requests/packages/urllib3/connectionpool.py
requests/packages/urllib3/contrib/ntlmpool.py
requests/packages/urllib3/exceptions.py
requests/packages/urllib3/filepost.py
requests/packages/urllib3/poolmanager.py
requests/packages/urllib3/response.py

index 19a6239178b93f6ff12546e00b0d0512d44c8fcc..5c4b5d17e8f567d5b92014c933653ab9c1ee5f94 100644 (file)
@@ -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.
 """
index 0e1c8e693da2e0fe522e2a545e2337c211360f9e..2b0de0e8be01ef10553d29bed369fa9d00a0732e 100644 (file)
@@ -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
 
 
index add6fbc72f659d607c586a5c256e1685a652f71b..92ce15403ab12a6b6882660ae83df753ae6e03e3 100644 (file)
@@ -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))
index a4642face856a989e8f9e73a8c8ec15cafdc0452..c5f010e190b009df0d0abc9b5cf521c26a6f94db 100644 (file)
@@ -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
 
index 45b0e822088856cadc9546f68c240f9bdd5b856e..69f459bdc9ab6827ce1e81d0fb19b6428ab188b0 100644 (file)
@@ -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):
index 67d2d0d8beb5436856efef08ae178939cd214767..8e65b5c2f507607a1df9bbabeb0e709a69ae8a53 100644 (file)
@@ -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
index 1863696700f1f69b14b34bc410df679bbd650ec0..d5b7613c4df13cd6ad8c95e9c04490d3196b4b13 100644 (file)
@@ -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."
index 8c847ce117a7a0e12634846dd7e77bd462fa0f3c..2bbc06ab9fdb164f4d93ba66ddde94d1eeea301b 100644 (file)
@@ -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