Skip to content
Myr

Connection Adapter Mounting!

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 bc34f33 · Browse files · 1 file+21 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+21 added−2 removed

  • other:+21 added−2 removed

1 file+21 added−2 removed

modified:requests/sessions.py+21 added-2 removed
12 unmodified lines
13from .cookies import cookiejar_from_dict, remove_cookie_by_name14from .models import Request15from .hooks import dispatch_hook, default_hooks16from .utils import header_expand, from_key_val_list, default_headers17from .exceptions import TooManyRedirects17from .exceptions import TooManyRedirects, InvalidSchema1819from .compat import urlparse, urljoin20from .adapters import HTTPAdapter21
154 unmodified lines
176177 # Set up a CookieJar to be used by default178 self.cookies = cookiejar_from_dict({})179180 # Default connection adapters.181 self.adapters = {}182 self.mount('http://', HTTPAdapter())183 self.mount('https://', HTTPAdapter())184185 def __enter__(self):186 return self187188 def __exit__(self, *args):
139 unmodified lines
328 return self.request('DELETE', url, **kwargs)329330 def send(self, request, **kwargs):331 """Send a given PreparedRequest."""327 adapter = HTTPAdapter()332 adapter = self.get_adapter(url=request.url)333 r = adapter.send(request, **kwargs)334 return r335336 def get_adapter(self, url):337 """Returns the appropriate connnection adapter for the given URL."""338 for (prefix, adapter) in self.adapters.items():339340 if url.startswith(prefix):341 return adapter342343 # Nothing matches :-/344 raise InvalidSchema('No connection adapters were found for \'%s\'' % url)345346 def mount(self, prefix, adapter):347 """Registers a connection adapter to a prefix."""348 self.adapters[prefix] = adapter349350 def __getstate__(self):351 return dict((attr, getattr(self, attr, None)) for attr in self.__attrs__)352353 def __setstate__(self, state):
10 unmodified lines