Skip to content
Myr

memory location repr for requests-client

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 853383a · Browse files · 1 file+6 added−1 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+6 added−1 removed

  • other:+6 added−1 removed

1 file+6 added−1 removed

modified:requests/sessions.py+6 added-1 removed
14 unmodified lines
15class Session(object):16 __attrs__ = ['headers', 'cookies', 'auth', 'timeout', 'proxies']1718 def __init__(self, **kwargs):1920 # Set up a CookieJar to be used by default21 self.cookies = cookielib.FileCookieJar()2223 # Map args from kwargs to instance-local variables24 map(lambda k, v: (k in self.__attrs__) and setattr(self, k, v),25 kwargs.iterkeys(), kwargs.itervalues())2627 # Map and wrap requests.api methods28 self._map_api_methods()2930 def __repr__(self):28 return '<requests-client at %s>' % (id(self))31 return '<requests-client at 0x%x>' % (id(self))3233 def _map_api_methods(self):34 """Reads each available method from requests.api and decorates35 them with a wrapper, which inserts any instance-local attributes36 (from __attrs__) that have been set, combining them with **kwargs.37 """3839 def pass_args(func):40 def wrapper_func(*args, **kwargs):41 inst_attrs = dict((k, v) for k, v in self.__dict__.iteritems()42 if k in self.__attrs__)
1 unmodified line
44 # priority to values in kwargs45 kwargs = dict(inst_attrs.items() + kwargs.items())46 return func(*args, **kwargs)47 return wrapper_func4849 # Map and decorate each function available in requests.api50 map(lambda fn: setattr(self, fn, pass_args(getattr(requests.api, fn))),51 requests.api.__all__)52
1 unmodified line