Skip to content
Myr

cleanup

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 42ee255 · Browse files · 1 file+15 added−33 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+15 added−33 removed

  • other:+15 added−33 removed

1 file+15 added−33 removed

modified:requests/sessions.py+15 added-33 removed
10 unmodified lines
1112from .compat import cookielib13from .cookies import cookiejar_from_dict, remove_cookie_by_name14from .models import Request15from .hooks import dispatch_hook, HOOKS15from .hooks import dispatch_hook, default_hooks16from .utils import header_expand, from_key_val_list, default_headers17from .exceptions import TooManyRedirects1819from .compat import urlparse, urljoin
39 unmodified lines
5960 return kwargs616263class SessionMixin(object):63class SessionRedirectMixin(object):6465 def resolve_redirects(self, resp, req, prefetch=True, timeout=None, verify=True, cert=None):66 """Receives a Response. Returns a generator of Responses."""67
58 unmodified lines
126 i += 1127 yield resp128129130class Session(SessionMixin):130class Session(SessionRedirectMixin):131 """A Requests session."""132133 __attrs__ = [134 'headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks',135 'params', 'verify', 'cert', 'prefetch']136137 def __init__(self,138 headers=None,139 cookies=None,140 auth=None,141 timeout=None,142 proxies=None,143 hooks=None,144 params=None,145 prefetch=True,146 verify=True,147 cert=None):137 def __init__(self):138139 #: A case-insensitive dictionary of headers to be sent on each140 #: :class:`Request <Request>` sent from this141 #: :class:`Session <Session>`.152 self.headers = from_key_val_list(headers or [])142 self.headers = default_headers()143144 #: Authentication tuple or object to attach to145 #: :class:`Request <Request>`.156 self.auth = auth146 self.auth = None147158 #: Float describing the timeout of the each :class:`Request <Request>`.159 self.timeout = timeout160148 #: Dictionary mapping protocol to the URL of the proxy (e.g.149 #: {'http': 'foo.bar:3128'}) to be used on each150 #: :class:`Request <Request>`.164 self.proxies = from_key_val_list(proxies or [])151 self.proxies = {}152153 #: Event-handling hooks.167 self.hooks = from_key_val_list(hooks or {})154 self.hooks = default_hooks()155156 #: Dictionary of querystring data to attach to each157 #: :class:`Request <Request>`. The dictionary values may be lists for158 #: representing multivalued query parameters.172 self.params = from_key_val_list(params or [])159 self.params = {}160161 #: Prefetch response content.175 self.prefetch = prefetch162 self.prefetch = True163164 #: SSL Verification.178 self.verify = verify165 self.verify = True166167 #: SSL certificate.181 self.cert = cert168 self.cert = None169170 #: Maximum number of redirects to follow.171 self.max_redirects = DEFAULT_REDIRECT_LIMIT172173 #: Should we trust the environment174 self.trust_env = True175189 self.default_headers = default_headers()190176 # Set up a CookieJar to be used by default192 if isinstance(cookies, cookielib.CookieJar):193 self.cookies = cookies194 else:195 self.cookies = cookiejar_from_dict(cookies)177 self.cookies = cookiejar_from_dict({})178179 def __enter__(self):180 return self181
29 unmodified lines
211 req.auth = auth212 req.cookies = cookies213 # TODO: move to attached214 # req.allow_redirects = allow_redirects233 req.proxies = proxies215 # req.proxies = proxies216 req.hooks = hooks217218 prep = req.prepare()219220 # TODO: prepare cookies.221240 resp = self.send(prep, prefetch, timeout, verify, cert)222 resp = self.send(prep, prefetch=prefetch, timeout=timeout, verify=verify, cert=cert)223224 # Redirect resolving generator.225 gen = self.resolve_redirects(resp, req, prefetch, timeout, verify, cert)226
106 unmodified lines