Skip to content
Myr

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

3 files+39 added−27 removed

modified:requests/config.py+17 added-19 removed
6 unmodified lines
7This module provides the Requests settings feature set.89settings parameters:1011TODO: Verify!!!12TODO: 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?1821Used globally2219"""2021def merge_configs(config, default_config=None):22 """Merge two given configurations."""2326class Settings(object):24 # Use the module-level defaults, if none is given.25 if default_config is None:26 default_config = config.copy()2728 def __init__(self, **kwargs):29 super(Settings, self).__init__()28 d = default_config.copy()29 d.update(config)3031 def __getattribute__(self, key):32 return object.__getattribute__(self, key)31 return d3233# Module-level defaults.34config = dict()3535settings = Settings()36config['base_headers'] = {'User-Agent': 'python-requests.org'}37config['accept_gzip'] = True38config['proxies'] = {}39config['verbose'] = None40config['timeout'] = None41config['max_redirects'] = 3042config['decode_unicode'] = True4337settings.base_headers = {'User-Agent': 'python-requests.org'}38settings.accept_gzip = True39settings.proxies = None40settings.verbose = None41settings.timeout = None42settings.max_redirects = 3043settings.decode_unicode = True4445#: Use socket.setdefaulttimeout() as fallback?46settings.timeout_fallback = True
modified:requests/models.py+14 added-2 removed
158 unmodified lines
159 # Opt-in to redirects for non- idempotent methods.160 (self.allow_redirects))161 ):162163 # print r.headers['location']164 # print dir(r.raw._original_response.fp)165 # print '--'166167 # We already redirected. Don't keep it alive.168 # r.raw.close()169170 # Woah, this is getting crazy.
27 unmodified lines
198 method = self.method199200 # 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,211212 # Flag as part of a redirect loop.213 redirect=True214 )
67 unmodified lines
282 # self.cookiejar.extract_cookies(resp, req)283284 # 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 lines
modified:requests/sessions.py+8 added-6 removed
16 unmodified lines
1718class Session(object):19 """A Requests session."""2021 __attrs__ = ['headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks']21 __attrs__ = [22 'headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks',23 'config'24 ]2526 def __init__(self, **kwargs):2728 # Set up a CookieJar to be used by default29 self.cookies = cookielib.FileCookieJar()30 self.config = kwargs.get('config') or dict()3132 # 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 lines
42 def __enter__(self):43 return self4445 def __exit__(self, *args):42 # print args46 pass4748 def _map_api_methods(self):49 """Reads each available method from requests.api and decorates
2 unmodified lines
52 """5354 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__)5758 # Combine instance-local values with kwargs values, with59 # priority to values in kwargs60 kwargs = dict(inst_attrs.items() + kwargs.items())61
10 unmodified lines
72 return func(*args, **kwargs)73 return wrapper_func7475 # 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__)777879def session(**kwargs):80 """Returns a :class:`Session` for context-managment."""
2 unmodified lines