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
Provenance
- Commit
92355ad- Tree
3fc17eb- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
42ee255
1 file changed+15 added−33 removed
modified:requests/sessions.py+15 added-33 removed
10 unmodified lines11 12 from .compat import cookielib13 from .cookies import cookiejar_from_dict, remove_cookie_by_name14 from .models import Request15-from .hooks import dispatch_hook, HOOKS15+from .hooks import dispatch_hook, default_hooks16 from .utils import header_expand, from_key_val_list, default_headers17 from .exceptions import TooManyRedirects18 19 from .compat import urlparse, urljoin39 unmodified lines59 60 return kwargs61 62 63-class SessionMixin(object):63+class SessionRedirectMixin(object):64 65 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 lines126 i += 1127 yield resp128 129 130-class Session(SessionMixin):130+class Session(SessionRedirectMixin):131 """A Requests session."""132 133 __attrs__ = [134 'headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks',135 'params', 'verify', 'cert', 'prefetch']136 137- 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):138 139 #: 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()143 144 #: Authentication tuple or object to attach to145 #: :class:`Request <Request>`.156- self.auth = auth146+ self.auth = None147 158- #: Float describing the timeout of the each :class:`Request <Request>`.159- self.timeout = timeout160-148 #: 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 = {}152 153 #: Event-handling hooks.167- self.hooks = from_key_val_list(hooks or {})154+ self.hooks = default_hooks()155 156 #: 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 = {}160 161 #: Prefetch response content.175- self.prefetch = prefetch162+ self.prefetch = True163 164 #: SSL Verification.178- self.verify = verify165+ self.verify = True166 167 #: SSL certificate.181- self.cert = cert168+ self.cert = None169 170 #: Maximum number of redirects to follow.171 self.max_redirects = DEFAULT_REDIRECT_LIMIT172 173 #: Should we trust the environment174 self.trust_env = True175 189- self.default_headers = default_headers()190-176 # 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({})178 179 def __enter__(self):180 return self181 29 unmodified lines211 req.auth = auth212 req.cookies = cookies213 # TODO: move to attached214 # req.allow_redirects = allow_redirects233- req.proxies = proxies215+ # req.proxies = proxies216 req.hooks = hooks217 218 prep = req.prepare()219 220 # TODO: prepare cookies.221 240- resp = self.send(prep, prefetch, timeout, verify, cert)222+ resp = self.send(prep, prefetch=prefetch, timeout=timeout, verify=verify, cert=cert)223 224 # Redirect resolving generator.225 gen = self.resolve_redirects(resp, req, prefetch, timeout, verify, cert)226 106 unmodified lines