Skip to content
Myr

fix regression with cookiejar.iteritems()

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

authored by Konstantin Podshumok · committed by Konstantin Podshumok · parent 1832e33 · Browse files · 3 files+53 added−11 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+53 added−11 removed

  • other:+53 added−11 removed

3 files+53 added−11 removed

modified:requests/cookies.py+29 added-11 removed
6 unmodified lines
7"""89import time10import collections11from .compat import cookielib, urlparse, urlunparse, Morsel11from .compat import cookielib, urlparse, urlunparse, Morsel, is_py31213try:14 import threading15 # grr, pyflakes: this fixes "redefinition of unused 'threading'"
181 unmodified lines
197 c = create_cookie(name, value, **kwargs)198 self.set_cookie(c)199 return c200201 def iterkeys(self):202 """Dict-like iterkeys() that returns an iterator of names of cookies from the jar.203 See itervalues() and iteritems()."""204 for cookie in iter(self):205 yield cookie.name206207 def keys(self):208 """Dict-like keys() that returns a list of names of cookies from the jar.209 See values() and items()."""204 keys = []210 if is_py3:211 return self.iterkeys()212 else:213 return list(self.iterkeys())214215 def itervalues(self):216 """Dict-like itervalues() that returns an iterator of values of cookies from the jar.217 See iterkeys() and iteritems()."""218 for cookie in iter(self):206 keys.append(cookie.name)207 return keys219 yield cookie.value220221 def values(self):222 """Dict-like values() that returns a list of values of cookies from the jar.223 See keys() and items()."""212 values = []224 if is_py3:225 return self.itervalues()226 else:227 return list(self.itervalues())228229 def iteritems(self):230 """Dict-like iteritems() that returns an iterator of name-value tuples from the jar.231 See iterkeys() and itervalues()."""232 for cookie in iter(self):214 values.append(cookie.value)215 return values233 yield cookie.name, cookie.value234235 def items(self):236 """Dict-like items() that returns a list of name-value tuples from the jar.237 See keys() and values(). Allows client-code to call "dict(RequestsCookieJar)238 and get a vanilla python dict of key value pairs."""221 items = []222 for cookie in iter(self):223 items.append((cookie.name, cookie.value))224 return items239 if is_py3:240 return self.iteritems()241 else:242 return list(self.iteritems())243244 def list_domains(self):245 """Utility method to list all the domains in the jar."""246 domains = []
217 unmodified lines
modified:AUTHORS.rst+1 added
143 unmodified lines
144- Jayson Vantuyl <jayson@aggressive.ly> @kagato145- Pengfei.X <pengphy@gmail.com>146- Kamil Madac <kamil.madac@gmail.com>147- Michael Becker <mike@beckerfuffle.com> @beckerfuffle148- Константин Подшумок @podshumok
modified:test_requests.py+23 added
568 unmodified lines
569 assert cookie.secure == secure570 assert cookie.domain == domain571 assert cookie._rest['HttpOnly'] == rest['HttpOnly']572573 def test_cookie_as_dict(self):574 key = 'some_cookie'575 value = 'some_value'576577 key1 = 'some_cookie1'578 value1 = 'some_value1'579580 jar = requests.cookies.RequestsCookieJar()581 jar.set(key, value)582 jar.set(key1, value1)583584 d1 = dict(jar)585 d2 = dict(jar.iteritems())586 d3 = dict(jar.items())587588 assert len(d1) == 2589 assert len(d2) == 2590 assert len(d3) == 2591592 assert d1['some_cookie'] == 'some_value'593 assert d2['some_cookie'] == 'some_value'594 assert d3['some_cookie'] == 'some_value'595596 def test_time_elapsed_blank(self):597 r = requests.get(httpbin('get'))598 td = r.elapsed599 total_seconds = ((td.microseconds + (td.seconds + td.days * 24 * 3600)
492 unmodified lines