POOL PARTY!!!!!!!!!!!!!!!
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 e2af50b · Browse files · 4 files·+16 added−5 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+16 added−5 removed
- other:+16 added−5 removed
Provenance
- Commit
ae4e85f- Tree
c7db796- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
e2af50b
4 files changed+16 added−5 removed
modified:requests/_config.py+1 added
45 unmodified lines46 defaults['timeout'] = None47 defaults['max_redirects'] = 3048 defaults['decode_unicode'] = True49 defaults['keepalive'] = True50+defaults['max_connections'] = 1051 52 modified:requests/api.py+3 added-3 removed
22 unmodified lines23 24 def request(method, url,25 params=None, data=None, headers=None, cookies=None, files=None, auth=None,26 timeout=None, allow_redirects=False, proxies=None, hooks=None,27- config=None, _connection=None):27+ config=None, _pools=None):28 29 """Constructs and sends a :class:`Request <Request>`.30 Returns :class:`Response <Response>` object.31 7 unmodified lines39 :param auth: (optional) AuthObject to enable Basic HTTP Auth.40 :param timeout: (optional) Float describing the timeout of the request.41 :param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.42 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.43- :param _connection: (optional) An HTTP Connection to re-use.43+ :param _pools: (optional) An HTTP PoolManager to use.44 """45 46 method = str(method).upper()47 config = get_config(config)31 unmodified lines79 # Pre-request hook.80 r = dispatch_hook('pre_request', hooks, r)81 82 # Send the HTTP Request.83- r.send(connection=_connection)83+ r.send(pools=_pools)84 85 # Post-request hook.86 r = dispatch_hook('post_request', hooks, r)87 73 unmodified linesmodified:requests/models.py+3 added-2 removed
225 unmodified lines226 self.response.request = self227 228 229 230- def send(self, connection=None, anyway=False):230+ def send(self, pools=None, anyway=False):231 """Sends the shit."""232 233 # Safety check.234 self._checks()18 unmodified lines253 if (anyway) or (not self.sent):254 255 try:256 # Create a new HTTP connection, since one wasn't passed in.257- if not connection:257+ if not pools:258 connection = urllib3.connection_from_url(url, timeout=self.timeout)259 260 # One-off request. Delay fetching the content until needed.261 do_block = False262 else:263+ connection = pools.connection_from_url(url, timeout=self.timeout)264 # Part of a connection pool, so no fancy stuff. Sorry!265 do_block = True266 267 # Create the connection.166 unmodified linesmodified:requests/sessions.py+9 added
12 unmodified lines13 14 from . import api15 from ._config import get_config16 from .utils import add_dict_to_cookiejar17+from .packages.urllib3.poolmanager import PoolManager18 19 20 def merge_kwargs(local_kwarg, default_kwarg):21 """Merges kwarg dictionaries.42 unmodified lines64 self.proxies = proxies65 self.hooks = hooks66 self.config = get_config(config)67 68+ self.__pool = PoolManager(69+ num_pools=self.config.get('max_connections')70+ )71+72 # Map and wrap requests.api methods.73 self._map_api_methods()74 75 def __repr__(self):33 unmodified lines109 for (k, v) in kwargs.items():110 if k not in _kwargs:111 _kwargs[k] = v112 113+ # Add in PoolManager, if neccesary.114+ if self.config.get('keepalive'):115+ _kwargs['_pool'] = self.__pool116+117 # TODO: Persist cookies.118 119 return func(*args, **_kwargs)120 return wrapper_func9 unmodified lines