Commit Graph

74 Commits

Author SHA1 Message Date
kennethreitz 5b363d1a57 improve line continuations for flake8 2017-05-29 22:54:23 -04:00
Thomas Grainger fcb272cc36 remove seemingly redundant pyflakes references 2017-04-20 13:23:56 +01:00
Brian Bamsch f002b73026 Move to_native_string to _internal_utils.py to avoid circular dependency 2016-09-26 21:41:01 -07:00
Brian Bamsch 2af059797a Adjust patch to utilize requests utility functions
Use the utility class provided by requests to do native string
transformation rather than recreating the wheel.
2016-09-26 09:14:51 -07:00
Brian Bamsch 01e405c611 Add patch to avoid bytestring/str hodgepodge
When patching Host header into URL, verify that host type matches
urlparse return type before putting it all back together
2016-09-25 22:18:45 -07:00
Ville Skyttä 542fbbc67f Document bunch of return types 2016-08-09 13:32:56 +03:00
kennethreitz fb01456061 Merge pull request #3429 from nateprewitt/docstring_cleanup
Docstring cleanup
2016-07-20 18:38:38 -04:00
Nate Prewitt b7809acb47 making class and function docstrings consistent 2016-07-20 11:43:47 -06:00
Nate Prewitt 2d4a89f5dc adding in pep8 fixes 2016-07-20 10:30:08 -06:00
Nate Prewitt 15a3869006 making module docstrings and coding comments consistent 2016-07-19 14:51:14 -06:00
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