Commit Graph

64 Commits

Author SHA1 Message Date
Casey Davidson d8b36c1718 Override __contains__ method of RequestsCookieJar to catch CookieConflictError. Refs #3028 2016-03-04 15:55:43 -08:00
Cory Benfield 96a068b58e Merge branch 'master' into fix-1859 2015-12-18 09:14:13 +00:00
Jakub Wilk 23d9b077d8 Fix typos 2015-12-01 12:24:56 +01:00
vienno d849d6e907 Replace 'if x' with 'if x is not None' in cookie loop 2015-11-10 13:58:09 +01:00
vienno 89178ebcdc Complete unnesting of if statements in cookie loop 2015-11-10 13:47:40 +01:00
vienno a25a641fb4 unnest deep loop 2015-11-10 12:36:36 +01:00
latyas(懒) dd0f164f8e Update cookies.py 2015-05-15 10:13:06 -05:00
latyas(懒) d3bd3630ee max-age may be not digits 2015-05-15 10:16:35 +08:00
latyas(懒) cda95d3cde morsel['max-age'] may be a str.
Example:

here are Set-Cookie list:
```python
sclst = ['dwac_bcIBMiaagZmkYaaadeYtg11eVR=j9jHdmPjUhgDOhyH9f89X4lQgehEmflVyeA%3D|dw-only|||CNY|false|Asia%2FShanghai|true; Path=/',
 'sid=j9jHdmPjUhgDOhyH9f89X4lQgehEmflVyeA; Path=/',
 'geoLocation=CN; Path=/',
 'dwpersonalization_fae107a9dd0fc32ed99532ec1977f31f=bc8sEiaagZqRsaaadk8XoNTL8h20150506; Expires=Sun, 14-Jun-2015 10:37:07 GMT; Path=/',
 'dwanonymous_fae107a9dd0fc32ed99532ec1977f31f=abjpA8kng31LjPp8ZEERDT4XVg; Version=1; Comment="Demandware anonymous cookie for site Sites-abercrombie_cn-Site"; Max-Age=15552000; Expires=Tue, 10-Nov-2015 10:37:07 GMT; Path=/',
 'myStore=91156; Path=/',
 'AF_PREF=en_CN; Path=/',
 'dwsid=MiHJy3KYZKDcN0lZg4HS1zSpj1VV4s_tFu39ar0KXNpAx9aX8X2LlvZQ9m5fOOknb6QXtmmukHcOjmivYf31hg==; path=/; HttpOnly']
```

```python
    for sc in sclst:
        C = Cookie.SimpleCookie(sc)
        for morsel in C.values():
            cookie = requests.cookies.morsel_to_cookie(morsel)
            cookiejar.set_cookie(cookie)
```
Then, exception occured
```shell
  File "/Library/Python/2.7/site-packages/requests/cookies.py", line 402, in morsel_to_cookie
    expires = time.time() + morsel['max-age']
TypeError: unsupported operand type(s) for +: 'float' and 'str'
```

As Cookie.SimpleCookie is in STL, should `morsel_to_cookie` check the type of `max-age`? On the other hand, if **max-age** can not be converted to float, it's illegal obviously.
2015-05-14 18:44:33 +08:00
Ian Cordasco 36093e69c7 Copy a PreparedRequest's CookieJar reliably
When a PreparedRequests's cookie jar is not a RequestsCookieJar instance, it
will not have a "copy" method. By adding _copy_cookie_jar we can reliably copy
cookie jars so that we have an actual copy instead of the same instance on
different prepared requests.

This also updates the RequestsCookieJar.update logic to create copies of
cookies from the other jar.

Closes #2527
2015-04-05 21:49:52 -05:00
Cory Benfield 101425ebfc Enhance documentation for clarity. 2014-12-24 14:54:49 +00:00
Cory Benfield f4ec3d2309 Clean up cookie docs and display them. 2014-12-24 14:33:14 +00:00
Ian Cordasco 87abd9c609 Use calendar.timegm when calculating cookie expiration
Fixes #1859

Credit: @lukasa
2014-01-12 14:27:45 -06:00
Konstantin Podshumok e6a32d6283 preserve python2-like dict API for RequestCookieJar 2013-12-18 18:09:24 +04:00
Konstantin Podshumok 537def4a4f fix regression with cookiejar.iteritems() 2013-12-18 06:56:53 +04:00
Michael Becker ea4570da57 cookies: Fix bugs found during CI 2013-12-06 09:02:45 -05:00
Michael Becker ef5875cc19 cookies: Take a less cowardly approach
Per discussion with @sigmavirus24, we'll take the less cowardly approach here.
"the RFC defines the Expires header as a string with the format we're assigning to ``time_template`` so checking if it is a string is unnecessary."

Crossing my fingers that this doesn't break anyones existing code...
2013-12-06 09:02:45 -05:00
Michael Becker 6140d08241 cookies: Replace type checks with try/except 2013-12-06 08:56:30 -05:00
daftshady 8eb40c777e remove unnecessary try 2013-11-26 15:28:59 +09:00
daftshady 8b2255d0f8 double try statement 2013-11-26 15:28:59 +09:00
daftshady 5fcaf45c33 update 'merge_cookies' not to create new instance. 2013-11-26 15:28:59 +09:00
daftshady 1adba3c9e9 modified 'merge_cookies' and update tests.
made sessions.py to use that method when merging cookies.
2013-11-26 15:28:59 +09:00
daftshady 30018e604c update 'merge_cookies' 2013-11-26 15:28:59 +09:00
daftshady e40c1637c9 added new method 'merge_cookies' and use it when merging session cookies with param cookies. 2013-11-26 15:28:59 +09:00
nonm cfbbd15de7 Small fix broken cookie parse 2013-11-18 13:32:59 -08:00
kennethreitz a123f8351d Merge pull request #1660 from sigmavirus24/parse-cookies-when-users-set-host-header
Parse cookies when users set custom Host header
2013-11-06 11:19:31 -08:00
Ian Cordasco 6632fb87c0 Fix typo 2013-10-11 20:42:52 -05:00
Ian Cordasco df7aece2c8 Comment our reasonsing for the special cases 2013-10-10 20:43:18 -05:00
Ian Cordasco 0bb8be0e5b Parse cookies when users set custom Host header 2013-10-07 21:43:21 -05:00
daftshady 012f0334ce added param to cookiejar_from_dict instead of creating new method. 2013-09-29 01:08:58 +09:00
daftshady d22eaf96e2 Fixed #1630 2013-09-28 23:44:27 +09:00
Ian Cordasco 98680b64f4 Skip cookie extraction if necessary
If _original_response is never set/is None, then don't try to extract cookies
from the response.
2013-08-16 21:38:20 -05:00
Cory Benfield 6ef3710970 Provide 'host' parameter to MockRequest. 2013-07-30 18:21:37 +01:00
Flavio Curella a8cf5b8502 keep the double quotes, but don't escape them 2013-07-01 15:48:48 -05:00
Flavio Curella cdab4fabf4 unquote double-quotes cookie values 2013-07-01 13:51:40 -05:00
wasw100 767f758aac cookies.morsel_to_cookie morsel['expires'] can't be strtime, and max-age convert to expires problem repair 2013-06-07 00:02:45 +08:00
wasw100 961790f95c cookies.morsel_to_cookie(morsel) raise TypeError repaired.
morsel_to_cookie(mosel) method raise TypeError: create_cookie() got unexpected keyword arguments: ['path_specified', 'domain_specified', 'port_specified', 'domain_initial_dot'].

so we should remove these param from create_cookie(...)
2013-06-06 19:15:09 +08:00
Ian Cordasco 9ce7f0bf5b Attempt a fix for @michaelhelmick 2013-05-20 10:58:03 -04:00
Chase Sterling 3f86e22a07 Make sure session cookies do not overwrite explicit request cookies
Implement RequestsCookieJar.copy
Use RequestsCookieJar.update when merging cookiejars
2013-02-16 00:56:59 -05:00
Chase Sterling f3393fb24c Remove ability to from RequestCookieJar __getitem__, __setitem__ to use cookies as keys 2013-02-14 22:52:31 -05:00
Chase Sterling 87d9d9643c Allow RequestsCookieJar to be updated with cookies from a CookieJar 2013-02-14 01:05:42 -05:00
Ian Cordasco 2e31696156 Test and perfection for cookie handling.
I also fixed up some of the RequestsCookieJar methods so using
jar.update(other_jar) works without a problem. This cleans up some of the code
in sessions and the resolve_redirects method.
2013-02-10 19:36:36 -05:00
Kenneth Reitz 4bad1285b6 nice and cleanup 2012-12-17 05:47:41 -05:00
Kenneth Reitz 4a01272fb3 cleanup 2012-12-17 01:25:55 -05:00
Kenneth Reitz ab27027aa8 cookies 2012-12-15 04:33:44 -05:00
Cory Benfield b76326bf94 MockRequest needs a type property for Py3.3 2012-11-17 13:00:39 +00:00
Radu Voicilas 820dfb0495 Making the code more PEP8 compliant 2012-10-09 00:42:49 +03:00
tokuda109 5ec2c96f02 declare the encoding 2012-10-09 00:42:49 +03:00
yegle 22fdecba52 Update: @property decorator instead of __getattr__ 2012-10-09 00:42:48 +03:00
yegle e656222188 Python 3.3 compatible update
httplib.cookiejar.DefaultCookiePolicy changed its implementation of
set_ok_verifiability.
2012-10-09 00:42:48 +03:00