urllib3 update
authorKenneth Reitz <me@kennethreitz.com>
Mon, 23 Jan 2012 06:01:42 +0000 (01:01 -0500)
committerKenneth Reitz <me@kennethreitz.com>
Mon, 23 Jan 2012 06:01:42 +0000 (01:01 -0500)
requests/packages/urllib3/connectionpool.py
requests/packages/urllib3/contrib/ntlmpool.py
requests/packages/urllib3/packages/__init__.py
requests/packages/urllib3/packages/six.py
requests/packages/urllib3/request.py
requests/packages/urllib3/response.py

index b9c912f8294d071d24d19b80508409f259c6b859..ea77c8f4a3344875064a19de10bbf677161af118 100644 (file)
@@ -7,21 +7,29 @@
 import logging
 import socket
 
-from select import poll, POLLIN
+from httplib import (HTTPConnection, HTTPSConnection, HTTPException,
+                     HTTP_PORT, HTTPS_PORT)
+
+from Queue import Queue, Empty, Full
 from socket import error as SocketError, timeout as SocketTimeout
 
+try:
+    from select import poll, POLLIN
+except ImportError: # Doesn't exist on OSX and other platforms
+    from select import select
+    poll = False
 
 try:   # Python 3
     from http.client import HTTPConnection, HTTPSConnection, HTTPException
     from http.client import HTTP_PORT, HTTPS_PORT
 except ImportError:
-    from http.client import HTTPConnection, HTTPSConnection, HTTPException
-    from http.client import HTTP_PORT, HTTPS_PORT
+    from httplib import HTTPConnection, HTTPSConnection, HTTPException
+    from httplib import HTTP_PORT, HTTPS_PORT
 
 try:   # Python 3
     from queue import Queue, Empty, Full
 except ImportError:
-    from queue import Queue, Empty, Full
+    from Queue import Queue, Empty, Full
 
 try:   # Compiled with SSL?
     import ssl
@@ -31,6 +39,7 @@ except ImportError:
     BaseSSLError = None
 
 
+from .packages.ssl_match_hostname import match_hostname, CertificateError
 from .request import RequestMethods
 from .response import HTTPResponse
 from .exceptions import (SSLError,
@@ -160,7 +169,7 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
         self.headers = headers or {}
 
         # Fill the queue up so that doing get() on it will block properly
-        for _ in range(maxsize):
+        for _ in xrange(maxsize):
             self.pool.put(None)
 
         # These are mostly for testing and debugging purposes.
@@ -587,7 +596,10 @@ def is_connection_dropped(conn):
     :param conn:
         ``HTTPConnection`` object.
     """
-    # poll-based replacement to select([conn.sock], [], [], 0.0)[0]:
+    if not poll:
+        return select([conn.sock], [], [], 0.0)[0]
+
+    # This version is better on platforms that support it.
     p = poll()
     p.register(conn.sock, POLLIN)
     for (fno, ev) in p.poll(0.0):
index 443cb8f6f25db0c4fb272d22ac56e6220f875052..bb41fd10e74426959edd20280023bb411d0f1fbd 100644 (file)
@@ -13,7 +13,7 @@ Issue #10, see: http://code.google.com/p/urllib3/issues/detail?id=10
 try:
     from http.client import HTTPSConnection
 except ImportError:
-    from http.client import HTTPSConnection
+    from httplib import HTTPSConnection
 from logging import getLogger
 from ntlm import ntlm
 
index ec2d3b4afecf96e3d282de988598109e1f4353df..37e8351577681ea1ea7a116a7d719adb4de5025d 100644 (file)
@@ -1,4 +1,4 @@
-
+from __future__ import absolute_import
 
 from . import ssl_match_hostname
 
index 2cd0458379a061d52d512be21dc87cc2f975b35f..a64f6fb8b71866e141d1d72074e50b5895b54227 100644 (file)
@@ -39,10 +39,10 @@ if PY3:
 
     MAXSIZE = sys.maxsize
 else:
-    string_types = str,
-    integer_types = (int, int)
-    class_types = (type, type)
-    text_type = str
+    string_types = basestring,
+    integer_types = (int, long)
+    class_types = (type, types.ClassType)
+    text_type = unicode
     binary_type = str
 
     # It's possible to have sizeof(long) != sizeof(Py_ssize_t).
@@ -230,11 +230,11 @@ if PY3:
         return any("__call__" in klass.__dict__ for klass in type(obj).__mro__)
 else:
     def get_unbound_function(unbound):
-        return unbound.__func__
+        return unbound.im_func
 
 
     def advance_iterator(it):
-        return next(it)
+        return it.next()
 
     callable = callable
 _add_doc(get_unbound_function,
@@ -278,10 +278,10 @@ else:
     def b(s):
         return s
     def u(s):
-        return str(s, "unicode_escape")
+        return unicode(s, "unicode_escape")
     int2byte = chr
-    import io
-    StringIO = BytesIO = io.StringIO
+    import StringIO
+    StringIO = BytesIO = StringIO.StringIO
 _add_doc(b, """Byte literal""")
 _add_doc(u, """Text literal""")
 
@@ -325,19 +325,19 @@ else:
         if fp is None:
             return
         def write(data):
-            if not isinstance(data, str):
+            if not isinstance(data, basestring):
                 data = str(data)
             fp.write(data)
         want_unicode = False
         sep = kwargs.pop("sep", None)
         if sep is not None:
-            if isinstance(sep, str):
+            if isinstance(sep, unicode):
                 want_unicode = True
             elif not isinstance(sep, str):
                 raise TypeError("sep must be None or a string")
         end = kwargs.pop("end", None)
         if end is not None:
-            if isinstance(end, str):
+            if isinstance(end, unicode):
                 want_unicode = True
             elif not isinstance(end, str):
                 raise TypeError("end must be None or a string")
@@ -345,12 +345,12 @@ else:
             raise TypeError("invalid keyword arguments to print()")
         if not want_unicode:
             for arg in args:
-                if isinstance(arg, str):
+                if isinstance(arg, unicode):
                     want_unicode = True
                     break
         if want_unicode:
-            newline = str("\n")
-            space = str(" ")
+            newline = unicode("\n")
+            space = unicode(" ")
         else:
             newline = "\n"
             space = " "
index d2efdd6cdaec169fdc62b57bb7ed4aa8ed737a0a..5ea26a0f046b736fa66beebde8eaeb77351e4cac 100644 (file)
@@ -7,7 +7,7 @@
 try:
     from urllib.parse import urlencode
 except ImportError:
-    from urllib.parse import urlencode
+    from urllib import urlencode
 
 from .filepost import encode_multipart_formdata
 
index df95aad405496ff61de83ee1a84139a7f0eeba24..e0239703618605367ed2fc4b78b84a2848a7e2e2 100644 (file)
@@ -10,10 +10,15 @@ import zlib
 
 from io import BytesIO
 
-
 from .exceptions import HTTPError
 
 
+try:
+    basestring = basestring
+except NameError: # Python 3
+    basestring = (str, bytes)
+
+
 log = logging.getLogger(__name__)
 
 
@@ -67,7 +72,7 @@ class HTTPResponse(object):
         self.strict = strict
 
         self._decode_content = decode_content
-        self._body = body if body and isinstance(body, str) else None
+        self._body = body if body and isinstance(body, basestring) else None
         self._fp = None
         self._original_response = original_response