From 125619c7836c69bf12e50f0177921954a43213a9 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Mon, 23 Jan 2012 01:01:42 -0500 Subject: [PATCH] urllib3 update --- requests/packages/urllib3/connectionpool.py | 24 +++++++++++++++------ requests/packages/urllib3/contrib/ntlmpool.py | 2 +- requests/packages/urllib3/packages/__init__.py | 2 +- requests/packages/urllib3/packages/six.py | 30 +++++++++++++------------- requests/packages/urllib3/request.py | 2 +- requests/packages/urllib3/response.py | 9 ++++++-- 6 files changed, 43 insertions(+), 26 deletions(-) diff --git a/requests/packages/urllib3/connectionpool.py b/requests/packages/urllib3/connectionpool.py index b9c912f..ea77c8f 100644 --- a/requests/packages/urllib3/connectionpool.py +++ b/requests/packages/urllib3/connectionpool.py @@ -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): diff --git a/requests/packages/urllib3/contrib/ntlmpool.py b/requests/packages/urllib3/contrib/ntlmpool.py index 443cb8f..bb41fd1 100644 --- a/requests/packages/urllib3/contrib/ntlmpool.py +++ b/requests/packages/urllib3/contrib/ntlmpool.py @@ -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 diff --git a/requests/packages/urllib3/packages/__init__.py b/requests/packages/urllib3/packages/__init__.py index ec2d3b4..37e8351 100644 --- a/requests/packages/urllib3/packages/__init__.py +++ b/requests/packages/urllib3/packages/__init__.py @@ -1,4 +1,4 @@ - +from __future__ import absolute_import from . import ssl_match_hostname diff --git a/requests/packages/urllib3/packages/six.py b/requests/packages/urllib3/packages/six.py index 2cd0458..a64f6fb 100644 --- a/requests/packages/urllib3/packages/six.py +++ b/requests/packages/urllib3/packages/six.py @@ -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 = " " diff --git a/requests/packages/urllib3/request.py b/requests/packages/urllib3/request.py index d2efdd6..5ea26a0 100644 --- a/requests/packages/urllib3/request.py +++ b/requests/packages/urllib3/request.py @@ -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 diff --git a/requests/packages/urllib3/response.py b/requests/packages/urllib3/response.py index df95aad..e023970 100644 --- a/requests/packages/urllib3/response.py +++ b/requests/packages/urllib3/response.py @@ -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 -- 2.7.4