preserve python2-like dict API for RequestCookieJar
authorKonstantin Podshumok <kpp.live@gmail.com>
Wed, 18 Dec 2013 14:09:24 +0000 (18:09 +0400)
committerKonstantin Podshumok <kpp.live@gmail.com>
Wed, 18 Dec 2013 14:09:24 +0000 (18:09 +0400)
requests/cookies.py
test_requests.py

index 053847ee5576b988503d81d814089b287c997b4d..831c49c6d276fe387cf7264edbc44c44585542b8 100644 (file)
@@ -8,7 +8,7 @@ requests.utils imports from here, so be careful with imports.
 
 import time
 import collections
-from .compat import cookielib, urlparse, urlunparse, Morsel, is_py3
+from .compat import cookielib, urlparse, urlunparse, Morsel
 
 try:
     import threading
@@ -207,10 +207,7 @@ class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
     def keys(self):
         """Dict-like keys() that returns a list of names of cookies from the jar.
         See values() and items()."""
-        if is_py3:
-            return self.iterkeys()
-        else:
-            return list(self.iterkeys())
+        return list(self.iterkeys())
 
     def itervalues(self):
         """Dict-like itervalues() that returns an iterator of values of cookies from the jar.
@@ -221,10 +218,7 @@ class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
     def values(self):
         """Dict-like values() that returns a list of values of cookies from the jar.
         See keys() and items()."""
-        if is_py3:
-            return self.itervalues()
-        else:
-            return list(self.itervalues())
+        return list(self.itervalues())
 
     def iteritems(self):
         """Dict-like iteritems() that returns an iterator of name-value tuples from the jar.
@@ -236,10 +230,7 @@ class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
         """Dict-like items() that returns a list of name-value tuples from the jar.
         See keys() and values(). Allows client-code to call "dict(RequestsCookieJar)
         and get a vanilla python dict of key value pairs."""
-        if is_py3:
-            return self.iteritems()
-        else:
-            return list(self.iteritems())
+        return list(self.iteritems())
 
     def list_domains(self):
         """Utility method to list all the domains in the jar."""
index 7e8a5b2bad695b9bbc0c79030b0957b5cc32b115..eeb186dcc00be03910ca2e157aa561c863f9a26b 100755 (executable)
@@ -593,6 +593,9 @@ class RequestsTestCase(unittest.TestCase):
         assert d2['some_cookie'] == 'some_value'
         assert d3['some_cookie'] == 'some_value'
 
+        keys = jar.keys()
+        assert list(keys) == list(keys)
+
     def test_time_elapsed_blank(self):
         r = requests.get(httpbin('get'))
         td = r.elapsed