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 33df9d1 · Browse files · 2 files·+25 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+25 added−6 removed
- other:+25 added−6 removed
Provenance
- Commit
55cea74- Tree
43b1685- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
33df9d1
2 files changed+25 added−6 removed
modified:requests/packages/urllib3/connectionpool.py+24 added-5 removed
201 unmodified lines202 get_host(url) == (self.scheme, self.host, self.port))203 204 def urlopen(self, method, url, body=None, headers=None, retries=3,205 redirect=True, assert_same_host=True, pool_timeout=None,206- **response_kw):206+ release_conn=None, **response_kw):207 """208 Get a connection from the pool and perform an HTTP request.209 210 method26 unmodified lines237 If set and the pool is set to block=True, then this method will238 block for ``pool_timeout`` seconds and raise EmptyPoolError if no239 connection is available within the time period.240 241+ release_conn242+ If False, then the urlopen call will not release the connection243+ back into the pool once a response is received. This is useful if244+ you're not preloading the response's content immediately. You will245+ need to call ``r.release_conn()`` on the response ``r`` to return246+ the connection back into the pool. If None, it takes the value of247+ ``response_kw.get('preload_content', True)``.248+249 Additional parameters are passed to250 ``HTTPResponse.from_httplib(r, **response_kw)``251 """252 if headers is None:1 unmodified line254 255 if retries < 0:256 raise MaxRetryError("Max retries exceeded for url: %s" % url)257 258+ if release_conn is None:259+ release_conn = response_kw.get('preload_content', True)260+261 # Check host262 if assert_same_host and not self.is_same_host(url):263 host = "%s://%s" % (self.scheme, self.host)264 if self.port:1 unmodified line266 267 raise HostChangedError("Connection pool with host '%s' tried to "268 "open a foreign host: %s" % (host, url))269 259- try:260- # Request a connection from the queue261- conn = self._get_conn(timeout=pool_timeout)270+ # Request a connection from the queue271+ conn = self._get_conn(timeout=pool_timeout)272 273+ try:274 # Make the request on the httplib connection object275 httplib_response = self._make_request(conn, method, url,276 body=body, headers=headers)266-277 # Import httplib's response into our own wrapper object278 response = HTTPResponse.from_httplib(httplib_response,279 pool=self,280 connection=conn,11 unmodified lines292 # SSL certificate error293 raise SSLError(e)294 295 except (HTTPException, SocketError), e:296+ # Connection broken, discard. It will be replaced next _get_conn().297+ conn = None298+299+ finally:300+ if release_conn:301+ # Put the connection back to be reused302+ self._put_conn(conn)303+304+ if not conn:305 log.warn("Retrying (%d attempts remain) after connection "306 "broken by '%r': %s" % (retries, e, url))307 return self.urlopen(method, url, body, headers, retries - 1,308 redirect, assert_same_host) # Try again194 unmodified linesmodified:requests/packages/urllib3/response.py+1 added-1 removed
54 unmodified lines55 'deflate': decode_deflate,56 }57 58 def __init__(self, body='', headers=None, status=0, version=0, reason=None,59- strict=0, preload_content=False, decode_content=True,59+ strict=0, preload_content=True, decode_content=True,60 original_response=None, pool=None, connection=None):61 self.headers = headers or {}62 self.status = status63 self.version = version110 unmodified lines