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
Provenance
- Commit
0cf0bde- Tree
3d4f583- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
dc7b4e7
1 file changed+50 added−9 removed
modified:requests/sessions.py+50 added-9 removed
10 unmodified lines11 12 import cookielib13 14 from . import api15+from .config import get_config16 from .utils import add_dict_to_cookiejar17 18 19+def merge_kwargs(local_kwargs, default_kwargs):20+ """Merges kwarg dictionaries.21+ """22+23+ # Bypass if not a dictionary (e.g. timeout)24+ if not hasattr(local_kwargs, 'items'):25+ return local_kwargs26+27+ kwargs = default_kwargs.copy()28+ kwargs.update(local_kwargs)29+30+ # Remove keys that are set to None.31+ for (k,v) in local_kwargs.items():32+ if v is None:33+ del kwargs[k]34+35+ return kwargs36+37+38+39 class Session(object):40 """A Requests session."""41 42 __attrs__ = [43 'headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks',44 'config'45 ]46 26- 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):55 56 # 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.config68 69 # 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())72 73 # Map and wrap requests.api methods74 self._map_api_methods()75 76+77+ def get(url, **kwargs):78+79+80 def __repr__(self):81 return '<requests-client at 0x%x>' % (id(self))82 83 def __enter__(self):17 unmodified lines101 kwargs = dict(inst_attrs.items() + kwargs.items())102 103 # 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+ # )109 110 if kwargs.get('headers', None) and inst_attrs.get('headers', None):111 kwargs['headers'].update(inst_attrs['headers'])112 11 unmodified lines