From: Kenneth Reitz Date: Mon, 26 Sep 2011 01:46:07 +0000 (-0400) Subject: urllib3 update X-Git-Tag: v0.8.0~94^2~51 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f52c0032a325b593f6e9fc0485ad6bd0ce871f12;p=services%2Fpython-requests.git urllib3 update --- diff --git a/requests/packages/urllib3/connectionpool.py b/requests/packages/urllib3/connectionpool.py index 2077026..95e3dd4 100644 --- a/requests/packages/urllib3/connectionpool.py +++ b/requests/packages/urllib3/connectionpool.py @@ -29,6 +29,8 @@ from .exceptions import ( log = logging.getLogger(__name__) +_Default = object() + ## Connection objects (extension of httplib) @@ -178,15 +180,19 @@ class HTTPConnectionPool(ConnectionPool): log.warning("HttpConnectionPool is full, discarding connection: %s" % self.host) - def _make_request(self, conn, method, url, **httplib_request_kw): + def _make_request(self, conn, method, url, timeout=_Default, + **httplib_request_kw): """ Perform a request on a given httplib connection object taken from our pool. """ self.num_requests += 1 + if timeout is _Default: + timeout = self.timeout + conn.request(method, url, **httplib_request_kw) - conn.sock.settimeout(self.timeout) + conn.sock.settimeout(timeout) httplib_response = conn.getresponse() log.debug("\"%s %s %s\" %s %s" % @@ -202,8 +208,8 @@ class HTTPConnectionPool(ConnectionPool): get_host(url) == (self.scheme, self.host, self.port)) def urlopen(self, method, url, body=None, headers=None, retries=3, - redirect=True, assert_same_host=True, pool_timeout=None, - release_conn=None, **response_kw): + redirect=True, assert_same_host=True, timeout=_Default, + pool_timeout=None, release_conn=None, **response_kw): """ Get a connection from the pool and perform an HTTP request. @@ -233,6 +239,9 @@ class HTTPConnectionPool(ConnectionPool): consistent else will raise HostChangedError. When False, you can use the pool on an HTTP proxy and request foreign hosts. + timeout + If specified, overrides the default timeout for this one request. + pool_timeout If set and the pool is set to block=True, then this method will block for ``pool_timeout`` seconds and raise EmptyPoolError if no @@ -273,6 +282,7 @@ class HTTPConnectionPool(ConnectionPool): try: # Make the request on the httplib connection object httplib_response = self._make_request(conn, method, url, + timeout=timeout, body=body, headers=headers) # Import httplib's response into our own wrapper object response = HTTPResponse.from_httplib(httplib_response, diff --git a/requests/packages/urllib3/poolmanager.py b/requests/packages/urllib3/poolmanager.py index d451f68..1863696 100644 --- a/requests/packages/urllib3/poolmanager.py +++ b/requests/packages/urllib3/poolmanager.py @@ -34,18 +34,14 @@ class PoolManager(object): self.pools = RecentlyUsedContainer(num_pools) self.recently_used_pools = [] - def connection_from_url(self, url): + def connection_from_host(self, host, port=80, scheme='http'): """ - Similar to connectionpool.connection_from_url but doesn't pass any - additional keywords to the ConnectionPool constructor. Additional - keywords are taken from the PoolManager constructor. + Get a ConnectionPool based on the host, port, and scheme. """ - scheme, host, port = get_host(url) + pool_key = (scheme, host, port) # If the scheme, host, or port doesn't match existing open connections, # open a new ConnectionPool. - pool_key = (scheme, host, port or port_by_scheme.get(scheme, 80)) - pool = self.pools.get(pool_key) if pool: return pool @@ -58,7 +54,19 @@ class PoolManager(object): return pool + def connection_from_url(self, url): + """ + Similar to connectionpool.connection_from_url but doesn't pass any + additional keywords to the ConnectionPool constructor. Additional + keywords are taken from the PoolManager constructor. + """ + scheme, host, port = get_host(url) + + port = port or port_by_scheme.get(scheme, 80) + + return self.connection_from_host(host, port=port, scheme=scheme) + def urlopen(self, method, url, **kw): - "Same as HTTP(S)ConnectionPool.urlopen" + "Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute." conn = self.connection_from_url(url) return conn.urlopen(method, url, **kw) diff --git a/requests/packages/urllib3/response.py b/requests/packages/urllib3/response.py index 14b3068..8c847ce 100644 --- a/requests/packages/urllib3/response.py +++ b/requests/packages/urllib3/response.py @@ -83,6 +83,7 @@ class HTTPResponse(object): return self._pool._put_conn(self._connection) + self._connection = None @property def data(self):