Skip to content
Myr

session work

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

merge kwargs and such

authored by Kenneth Reitz · committed by Kenneth Reitz · parent dc7b4e7 · Browse files · 1 file+50 added−9 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+50 added−9 removed

  • other:+50 added−9 removed

1 file+50 added−9 removed

modified:requests/sessions.py+50 added-9 removed
10 unmodified lines
1112import cookielib1314from . import api15from .config import get_config16from .utils import add_dict_to_cookiejar171819def merge_kwargs(local_kwargs, default_kwargs):20 """Merges kwarg dictionaries.21 """2223 # Bypass if not a dictionary (e.g. timeout)24 if not hasattr(local_kwargs, 'items'):25 return local_kwargs2627 kwargs = default_kwargs.copy()28 kwargs.update(local_kwargs)2930 # Remove keys that are set to None.31 for (k,v) in local_kwargs.items():32 if v is None:33 del kwargs[k]3435 return kwargs36373839class Session(object):40 """A Requests session."""4142 __attrs__ = [43 'headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks',44 'config'45 ]4626 def __init__(self, **kwargs):47 def __init__(self,48 headers=None,49 cookies=None,50 auth=None,51 timeout=None,52 proxies=None,53 hooks=None,54 config=None):5556 # Set up a CookieJar to be used by default29 self.cookies = cookielib.FileCookieJar()30 self.config = kwargs.get('config') or dict()57 # self.cookies = cookielib.FileCookieJar()58 # self.config = kwargs.get('config')59 # self.configs =60 self.headers = headers61 self.cookies = cookies62 self.auth = auth63 self.timeout = timeout64 self.proxies = proxies65 self.hooks = hooks66 self.config = get_config(config)67 # print self.config6869 # Map args from kwargs to instance-local variables33 map(lambda k, v: (k in self.__attrs__) and setattr(self, k, v),34 kwargs.iterkeys(), kwargs.itervalues())70 # map(lambda k, v: (k in self.__attrs__) and setattr(self, k, v),71 # kwargs.iterkeys(), kwargs.itervalues())7273 # Map and wrap requests.api methods74 self._map_api_methods()757677 def get(url, **kwargs):787980 def __repr__(self):81 return '<requests-client at 0x%x>' % (id(self))8283 def __enter__(self):
17 unmodified lines
101 kwargs = dict(inst_attrs.items() + kwargs.items())102103 # If a session request has a cookie_dict, inject the104 # values into the existing CookieJar instead.64 if isinstance(kwargs.get('cookies', None), dict):65 kwargs['cookies'] = add_dict_to_cookiejar(66 inst_attrs['cookies'], kwargs['cookies']67 )105 # if isinstance(kwargs.get('cookies', None), dict):106 # kwargs['cookies'] = add_dict_to_cookiejar(107 # inst_attrs['cookies'], kwargs['cookies']108 # )109110 if kwargs.get('headers', None) and inst_attrs.get('headers', None):111 kwargs['headers'].update(inst_attrs['headers'])112
11 unmodified lines