Skip to content
Myr

rework session argument

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

Closes #141

authored by Kenneth Reitz · committed by Kenneth Reitz · parent 802bcc9 · Browse files · 1 file+20 added−13 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+20 added−13 removed

  • other:+20 added−13 removed

1 file+20 added−13 removed

modified:requests/sessions.py+20 added-13 removed
111 unmodified lines
112 """113114 def pass_args(func):115 def wrapper_func(*args, **kwargs):116 inst_attrs = dict((k, v) for k, v in self.__dict__.iteritems() if k in self.__attrs__)116118 # Combine instance-local values with kwargs values, with119 # priority to values in kwargs120 kwargs = dict(inst_attrs.items() + kwargs.items())117 # Argument collector.118 _kwargs = {}119122 # If a session request has a cookie_dict, inject the123 # values into the existing CookieJar instead.124 # if isinstance(kwargs.get('cookies', None), dict):125 # kwargs['cookies'] = add_dict_to_cookiejar(126 # inst_attrs['cookies'], kwargs['cookies']127 # )120 # Merge local and session arguments.121 for attr in self.__attrs__:122 default_attr = getattr(self, attr)123 local_attr = kwargs.get(attr)124129 if kwargs.get('headers', None) and inst_attrs.get('headers', None):130 kwargs['headers'].update(inst_attrs['headers'])125 # Merge local and session dictionaries.126 new_attr = merge_kwargs(local_attr, default_attr)127128 # Skip attributes that were set to None.129 if new_attr is not None:130 _kwargs[attr] = new_attr131132 # Make sure we didn't miss anything.133 for (k, v) in kwargs:134 if k not in _kwargs:135 _kwargs[k] = v136137 # TODO: Persist cookies.138132 return func(*args, **kwargs)139 return func(*args, **_kwargs)140 return wrapper_func141142 # Map and decorate each function available in requests.api143 map(lambda fn: setattr(self, fn, pass_args(getattr(api, fn))), api.__all__)
6 unmodified lines