Skip to content
Myr

Merge pull request #632 from amalakar/develop

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

Issue #505: Changed the store_cookie configuration to be part of the conig dict, instead of being a new argument

authored by Kenneth Reitz · committed by Kenneth Reitz · parents de1637c, 4a30979 · Browse files · 5 files+11 added−17 removed
This commit

State

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

Diff stats

5 files+11 added−17 removed

  • tests:+6 added−4 removed
  • other:+5 added−13 removed

5 files+11 added−17 removed

modified:requests/api.py+1 added-2 removed
23 unmodified lines
24 :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.25 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.26 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.27 :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.28 :param store_cookies: (optional) if ``False``, the received cookies as part of the HTTP response would be ignored.28 :param files: (optional) Dictionary of 'name': file-like-objects (or {'name': ('filename', fileobj)}) for multipart encoding upload.29 :param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.30 :param timeout: (optional) Float describing the timeout of the request.31 :param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.32 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.33 :param return_response: (optional) If False, an un-sent Request object will returned.34 :param session: (optional) A :class:`Session` object to be used for the request.36 :param config: (optional) A configuration dictionary.35 :param config: (optional) A configuration dictionary. See ``request.defaults`` for allowed keys and their default values.36 :param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided.37 :param prefetch: (optional) if ``True``, the response content will be immediately downloaded.38 :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.39 """
80 unmodified lines
modified:requests/defaults.py+2 added
18 unmodified lines
19:pool_maxsize: The maximium size of an HTTP connection pool.20:pool_connections: The number of active HTTP connection pools to use.21:encode_uri: If true, URIs will automatically be percent-encoded.22:trust_env: If true, the surrouding environment will be trusted (environ, netrc).23:param store_cookies: If false, the received cookies as part of the HTTP response would be ignored.2425"""2627SCHEMAS = ['http', 'https']
19 unmodified lines
47defaults['strict_mode'] = False48defaults['keep_alive'] = True49defaults['encode_uri'] = True50defaults['trust_env'] = True51defaults['store_cookies'] = True5253
modified:requests/models.py+1 added-5 removed
57 unmodified lines
58 data=dict(),59 params=dict(),60 auth=None,61 cookies=None,62 store_cookies=True,62 timeout=None,63 redirect=False,64 allow_redirects=False,65 proxies=None,
42 unmodified lines
108109 # Dictionary mapping protocol to the URL of the proxy (e.g. {'http': 'foo.bar:3128'})110 self.proxies = dict(proxies or [])111113 #param store_cookies: (optional) if ``False``, the received cookies as part of the HTTP response would be ignored.114 self.store_cookies = store_cookies115112 # If no proxies are given, allow configuration by environment variables113 # HTTP_PROXY and HTTPS_PROXY.114 if not self.proxies and self.config.get('trust_env'):115 self.proxies = get_environ_proxies()
80 unmodified lines
196 # Set encoding.197 response.encoding = get_encoding_from_headers(response.headers)198199 # Add new cookies from the server. Don't if configured not to204 if self.store_cookies:200 if self.config.get('store_cookies'):201 extract_cookies_to_jar(self.cookies, self, resp)202203 # Save cookies in Response.204 response.cookies = self.cookies
627 unmodified lines
modified:requests/sessions.py+1 added-6 removed
58 unmodified lines
5960 def __init__(self,61 headers=None,62 cookies=None,63 store_cookies=True,63 auth=None,64 timeout=None,65 proxies=None,66 hooks=None,
12 unmodified lines
79 self.config = config or {}80 self.prefetch = prefetch81 self.verify = verify82 self.cert = cert84 self.store_cookies = store_cookies8384 for (k, v) in list(defaults.items()):85 self.config.setdefault(k, deepcopy(v))86
24 unmodified lines
111 params=None,112 data=None,113 headers=None,114 cookies=None,117 store_cookies=True,115 files=None,116 auth=None,117 timeout=None,118 allow_redirects=True,
13 unmodified lines
132 :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.133 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.134 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.135 :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.139 :param store_cookies: (optional) if ``False``, the received cookies as part of the HTTP response would be ignored.136 :param files: (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.137 :param auth: (optional) Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth.138 :param timeout: (optional) Float describing the timeout of the request.139 :param allow_redirects: (optional) Boolean. Set to True by default.140 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.141 :param return_response: (optional) If False, an un-sent Request object will returned.146 :param config: (optional) A configuration dictionary.142 :param config: (optional) A configuration dictionary. See ``request.defaults`` for allowed keys and their default values.143 :param prefetch: (optional) if ``True``, the response content will be immediately downloaded.144 :param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided.145 :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.146 """
23 unmodified lines
170 data=data,171 params=params,172 headers=headers,173 cookies=cookies,178 store_cookies=store_cookies,174 files=files,175 auth=auth,176 hooks=hooks,177 timeout=timeout,
147 unmodified lines
modified:tests/test_cookies.py+6 added-4 removed
104 unmodified lines
105106 def test_disabled_cookie_persistence(self):107 """Test that cookies are not persisted when configured accordingly."""108109 config = {'store_cookies' : False}110111 # Check the case when no cookie is passed as part of the request and the one in response is ignored110 cookies = requests.get(httpbin('cookies', 'set', 'key', 'value'), store_cookies = False).cookies111 self.assertEqual(cookies.get("key"), None)112 cookies = requests.get(httpbin('cookies', 'set', 'key', 'value'), config = config).cookies113 self.assertTrue(cookies.get("key") is None)114115 # Test that the cookies passed while making the request still gets used and is available in response object.116 # only the ones received from server is not saved115 cookies_2 = requests.get(httpbin('cookies', 'set', 'key', 'value'), store_cookies = False,\117 cookies_2 = requests.get(httpbin('cookies', 'set', 'key', 'value'), config = config,\118 cookies = {"key_2" : "value_2"}).cookies119 self.assertEqual(len(cookies_2), 1)120 self.assertEqual(cookies_2.get("key_2"), "value_2")121122 # Use the session and make sure that the received cookie is not used in subsequent calls123 s = requests.session()122 s.get(httpbin('cookies', 'set', 'key', 'value'), store_cookies = False)124 s.get(httpbin('cookies', 'set', 'key', 'value'), config = config)125 r = s.get(httpbin('cookies'))126 self.assertEqual(json.loads(r.text)['cookies'], {})127128 def test_jar_utility_functions(self):
135 unmodified lines