urllib3 update
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parent dfe0e93 · Browse files · 3 files·+31 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+31 added−12 removed
- other:+31 added−12 removed
Provenance
- Commit
f52c003- Tree
160a597- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
dfe0e93
3 files changed+31 added−12 removed
modified:requests/packages/urllib3/connectionpool.py+14 added-4 removed
27 unmodified lines28 29 30 log = logging.getLogger(__name__)31 32+_Default = object()33 34+35 ## Connection objects (extension of httplib)36 37 class VerifiedHTTPSConnection(HTTPSConnection):38 """140 unmodified lines179 # This should never happen if self.block == True180 log.warning("HttpConnectionPool is full, discarding connection: %s"181 % self.host)182 181- def _make_request(self, conn, method, url, **httplib_request_kw):183+ def _make_request(self, conn, method, url, timeout=_Default,184+ **httplib_request_kw):185 """186 Perform a request on a given httplib connection object taken from our187 pool.188 """189 self.num_requests += 1190 191+ if timeout is _Default:192+ timeout = self.timeout193+194 conn.request(method, url, **httplib_request_kw)189- conn.sock.settimeout(self.timeout)195+ conn.sock.settimeout(timeout)196 httplib_response = conn.getresponse()197 198 log.debug("\"%s %s %s\" %s %s" %199 (method, url,7 unmodified lines207 return (url.startswith('/') or208 get_host(url) == (self.scheme, self.host, self.port))209 210 def urlopen(self, method, url, body=None, headers=None, retries=3,205- redirect=True, assert_same_host=True, pool_timeout=None,206- release_conn=None, **response_kw):211+ redirect=True, assert_same_host=True, timeout=_Default,212+ pool_timeout=None, release_conn=None, **response_kw):213 """214 Get a connection from the pool and perform an HTTP request.215 216 method21 unmodified lines238 If True, will make sure that the host of the pool requests is239 consistent else will raise HostChangedError. When False, you can240 use the pool on an HTTP proxy and request foreign hosts.241 242+ timeout243+ If specified, overrides the default timeout for this one request.244+245 pool_timeout246 If set and the pool is set to block=True, then this method will247 block for ``pool_timeout`` seconds and raise EmptyPoolError if no248 connection is available within the time period.32 unmodified lines281 282 try:283 # Make the request on the httplib connection object284 httplib_response = self._make_request(conn, method, url,285+ timeout=timeout,286 body=body, headers=headers)287 # Import httplib's response into our own wrapper object288 response = HTTPResponse.from_httplib(httplib_response,289 pool=self,223 unmodified linesmodified:requests/packages/urllib3/poolmanager.py+16 added-8 removed
32 unmodified lines33 34 self.pools = RecentlyUsedContainer(num_pools)35 self.recently_used_pools = []36 37- def connection_from_url(self, url):37+ def connection_from_host(self, host, port=80, scheme='http'):38 """39- Similar to connectionpool.connection_from_url but doesn't pass any40- additional keywords to the ConnectionPool constructor. Additional41- keywords are taken from the PoolManager constructor.39+ Get a ConnectionPool based on the host, port, and scheme.40 """43- scheme, host, port = get_host(url)41+ pool_key = (scheme, host, port)42 43 # If the scheme, host, or port doesn't match existing open connections,44 # open a new ConnectionPool.47- pool_key = (scheme, host, port or port_by_scheme.get(scheme, 80))48-45 pool = self.pools.get(pool_key)46 if pool:47 return pool48 4 unmodified lines53 self.pools[pool_key] = pool54 55 return pool56 57+ def connection_from_url(self, url):58+ """59+ Similar to connectionpool.connection_from_url but doesn't pass any60+ additional keywords to the ConnectionPool constructor. Additional61+ keywords are taken from the PoolManager constructor.62+ """63+ scheme, host, port = get_host(url)64+65+ port = port or port_by_scheme.get(scheme, 80)66+67+ return self.connection_from_host(host, port=port, scheme=scheme)68+69 def urlopen(self, method, url, **kw):62- "Same as HTTP(S)ConnectionPool.urlopen"70+ "Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute."71 conn = self.connection_from_url(url)72 return conn.urlopen(method, url, **kw)modified:requests/packages/urllib3/response.py+1 added
81 unmodified lines82 if not self._pool or not self._connection:83 return84 85 self._pool._put_conn(self._connection)86+ self._connection = None87 88 @property89 def data(self):90 # For backwords-compat with earlier urllib3 0.4 and earlier.84 unmodified lines