Don't add params to redirect / new configuration
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 9488af5 · Browse files · 3 files·+39 added−27 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+39 added−27 removed
- other:+39 added−27 removed
Provenance
- Commit
dc7b4e7- Tree
987a8fc- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
9488af5
3 files changed+39 added−27 removed
modified:requests/config.py+17 added-19 removed
6 unmodified lines7 This module provides the Requests settings feature set.8 9 settings parameters:10 11-TODO: Verify!!!12-TODO: Make sure format is acceptabl/cool11 - :base_headers: - Sets default User-Agent to `python-requests.org`12 - :accept_gzip: - Whether or not to accept gzip-compressed data13 - :proxies: - http proxies?14 - :verbose: - display verbose information?15 - :timeout: - timeout time until request terminates16 - :max_redirects: - maximum number of allowed redirects?17 - :decode_unicode: - whether or not to accept unicode?18 21-Used globally22-19 """20 21+def merge_configs(config, default_config=None):22+ """Merge two given configurations."""23 26-class Settings(object):24+ # Use the module-level defaults, if none is given.25+ if default_config is None:26+ default_config = config.copy()27 28- def __init__(self, **kwargs):29- super(Settings, self).__init__()28+ d = default_config.copy()29+ d.update(config)30 31- def __getattribute__(self, key):32- return object.__getattribute__(self, key)31+ return d32 33+# Module-level defaults.34+config = dict()35 35-settings = Settings()36+config['base_headers'] = {'User-Agent': 'python-requests.org'}37+config['accept_gzip'] = True38+config['proxies'] = {}39+config['verbose'] = None40+config['timeout'] = None41+config['max_redirects'] = 3042+config['decode_unicode'] = True43 37-settings.base_headers = {'User-Agent': 'python-requests.org'}38-settings.accept_gzip = True39-settings.proxies = None40-settings.verbose = None41-settings.timeout = None42-settings.max_redirects = 3043-settings.decode_unicode = True44 45-#: Use socket.setdefaulttimeout() as fallback?46-settings.timeout_fallback = Truemodified:requests/models.py+14 added-2 removed
158 unmodified lines159 # Opt-in to redirects for non- idempotent methods.160 (self.allow_redirects))161 ):162 163+ # print r.headers['location']164+ # print dir(r.raw._original_response.fp)165+ # print '--'166+167 # We already redirected. Don't keep it alive.168 # r.raw.close()169 170 # Woah, this is getting crazy.27 unmodified lines198 method = self.method199 200 # Create the new Request.201 request = Request(198- url, self.headers, self.files, method,199- self.data, self.params, self.auth, self.cookies,202+ url=url,203+ headers=self.headers,204+ files=self.files,205+ method=method,206+ data=self.data,207+ # params=self.params,208+ params=None,209+ auth=self.auth,210+ cookies=self.cookies,211 212 # Flag as part of a redirect loop.213 redirect=True214 )67 unmodified lines282 # self.cookiejar.extract_cookies(resp, req)283 284 # except (urllib2.HTTPError, urllib2.URLError), why:285 except Exception, why:286+ print why.__dict__287 # if hasattr(why, 'reason'):288 # if isinstance(why.reason, socket.timeout):289 # why = Timeout(why)290 143 unmodified linesmodified:requests/sessions.py+8 added-6 removed
16 unmodified lines17 18 class Session(object):19 """A Requests session."""20 21- __attrs__ = ['headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks']21+ __attrs__ = [22+ 'headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks',23+ 'config'24+ ]25 26 def __init__(self, **kwargs):27 28 # Set up a CookieJar to be used by default29 self.cookies = cookielib.FileCookieJar()30+ self.config = kwargs.get('config') or dict()31 32 # 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())7 unmodified lines42 def __enter__(self):43 return self44 45 def __exit__(self, *args):42- # print args46 pass47 48 def _map_api_methods(self):49 """Reads each available method from requests.api and decorates2 unmodified lines52 """53 54 def pass_args(func):55 def wrapper_func(*args, **kwargs):53- inst_attrs = dict((k, v) for k, v in self.__dict__.iteritems()54- if k in self.__attrs__)56+ inst_attrs = dict((k, v) for k, v in self.__dict__.iteritems() if k in self.__attrs__)57+58 # Combine instance-local values with kwargs values, with59 # priority to values in kwargs60 kwargs = dict(inst_attrs.items() + kwargs.items())61 10 unmodified lines72 return func(*args, **kwargs)73 return wrapper_func74 75 # Map and decorate each function available in requests.api73- map(lambda fn: setattr(self, fn, pass_args(getattr(api, fn))),74- api.__all__)76+ map(lambda fn: setattr(self, fn, pass_args(getattr(api, fn))), api.__all__)77 78 79 def session(**kwargs):80 """Returns a :class:`Session` for context-managment."""2 unmodified lines