session => sessions
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 2fa0215 · Browse files · 2 files·+47 added−44 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+47 added−44 removed
- other:+47 added−44 removed
Provenance
- Commit
f319006- Tree
0a7f0cb- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
2fa0215
2 files changed+47 added−44 removed
deleted:requests/session.py-44 removed
1-# -*- coding: utf-8 -*-2-3-"""4-requests.session5-~~~~~~~~~~~~~~~6-7-This module provides a Session object to manage and persist settings across8-requests (cookies, auth, proxies).9-10-"""11-12-import requests.api13-import cookielib14-15-class Session(object):16- __attrs__ = ['headers', 'cookies', 'auth', 'timeout', 'proxies']17-18- def __init__(self, **kwargs):19- # Set up a CookieJar to be used by default20- self.cookies = cookielib.FileCookieJar()21- # Map args from kwargs to instance-local variables22- map(lambda k, v: (k in self.__attrs__) and setattr(self, k, v),23- kwargs.iterkeys(), kwargs.itervalues())24- # Map and wrap requests.api methods25- self._map_api_methods()26- 27- def _map_api_methods(self):28- """ Reads each available method from requests.api and decorates29- them with a wrapper that inserts any instance-local attributes30- (from __attrs__) that have been set, combining them with **kwargs """31- def pass_args(func):32- def wrapper_func(*args, **kwargs):33- inst_attrs = dict((k, v) for k, v in self.__dict__.iteritems() 34- if k in self.__attrs__)35- # Combine instance-local values with kwargs values, with 36- # priority to values in kwargs37- kwargs = dict(inst_attrs.items() + kwargs.items())38- return func(*args, **kwargs)39- return wrapper_func40- # Map and decorate each function available in requests.api41- map(lambda fn: setattr(self, fn, pass_args(getattr(requests.api, fn))),42- requests.api.__all__) 43-44-added:requests/sessions.py+47 added
1+# -*- coding: utf-8 -*-2+3+"""4+requests.session5+~~~~~~~~~~~~~~~6+7+This module provides a Session object to manage and persist settings across8+requests (cookies, auth, proxies).9+10+"""11+12+import requests.api13+import cookielib14+15+class Session(object):16+ __attrs__ = ['headers', 'cookies', 'auth', 'timeout', 'proxies']17+18+ def __init__(self, **kwargs):19+ # Set up a CookieJar to be used by default20+ self.cookies = cookielib.FileCookieJar()21+ # Map args from kwargs to instance-local variables22+ map(lambda k, v: (k in self.__attrs__) and setattr(self, k, v),23+ kwargs.iterkeys(), kwargs.itervalues())24+ # Map and wrap requests.api methods25+ self._map_api_methods()26+27+ def __repr__(self):28+ return '<requests-client at %s>' % (id(self))29+30+ def _map_api_methods(self):31+ """ Reads each available method from requests.api and decorates32+ them with a wrapper that inserts any instance-local attributes33+ (from __attrs__) that have been set, combining them with **kwargs """34+ def pass_args(func):35+ def wrapper_func(*args, **kwargs):36+ inst_attrs = dict((k, v) for k, v in self.__dict__.iteritems()37+ if k in self.__attrs__)38+ # Combine instance-local values with kwargs values, with39+ # priority to values in kwargs40+ kwargs = dict(inst_attrs.items() + kwargs.items())41+ return func(*args, **kwargs)42+ return wrapper_func43+ # Map and decorate each function available in requests.api44+ map(lambda fn: setattr(self, fn, pass_args(getattr(requests.api, fn))),45+ requests.api.__all__)46+47+