summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-11-02 20:35:47 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-11-02 20:35:47 (GMT)
commit186c5f07e65c95b23087abe33670efa95eca497b (patch)
tree56c7ea8f19517c4fca043b5bb936370a3ac23f46
parent009352aefd6f744b018df5a6c0cb077e7f667b5b (diff)
downloadcpython-186c5f07e65c95b23087abe33670efa95eca497b.zip
cpython-186c5f07e65c95b23087abe33670efa95eca497b.tar.gz
cpython-186c5f07e65c95b23087abe33670efa95eca497b.tar.bz2
Issue #22775: Fixed unpickling of Cookie.SimpleCookie with protocol 2.
Patch by Tim Graham.
-rw-r--r--Lib/Cookie.py8
-rw-r--r--Lib/test/test_cookie.py13
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
4 files changed, 23 insertions, 2 deletions
diff --git a/Lib/Cookie.py b/Lib/Cookie.py
index d674437..0b15531 100644
--- a/Lib/Cookie.py
+++ b/Lib/Cookie.py
@@ -591,8 +591,12 @@ class BaseCookie(dict):
def __setitem__(self, key, value):
"""Dictionary style assignment."""
- rval, cval = self.value_encode(value)
- self.__set(key, rval, cval)
+ if isinstance(value, Morsel):
+ # allow assignment of constructed Morsels (e.g. for pickling)
+ dict.__setitem__(self, key, value)
+ else:
+ rval, cval = self.value_encode(value)
+ self.__set(key, rval, cval)
# end __setitem__
def output(self, attrs=None, header="Set-Cookie:", sep="\015\012"):
diff --git a/Lib/test/test_cookie.py b/Lib/test/test_cookie.py
index 41ba60f..36cd52e 100644
--- a/Lib/test/test_cookie.py
+++ b/Lib/test/test_cookie.py
@@ -3,6 +3,7 @@
from test.test_support import run_unittest, run_doctest, check_warnings
import unittest
import Cookie
+import pickle
class CookieTests(unittest.TestCase):
@@ -141,6 +142,18 @@ class CookieTests(unittest.TestCase):
self.assertEqual(dict(C), {})
self.assertEqual(C.output(), '')
+ def test_pickle(self):
+ rawdata = 'Customer="WILE_E_COYOTE"; Path=/acme; Version=1'
+ expected_output = 'Set-Cookie: %s' % rawdata
+
+ C = Cookie.SimpleCookie()
+ C.load(rawdata)
+ self.assertEqual(C.output(), expected_output)
+
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ C1 = pickle.loads(pickle.dumps(C, protocol=proto))
+ self.assertEqual(C1.output(), expected_output)
+
def test_main():
run_unittest(CookieTests)
diff --git a/Misc/ACKS b/Misc/ACKS
index b1d6d3f..d44240f 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -484,6 +484,7 @@ Chris Gonnerman
Shelley Gooch
David Goodger
Hans de Graaff
+Tim Graham
Nathaniel Gray
Eddy De Greef
Grant Griffin
diff --git a/Misc/NEWS b/Misc/NEWS
index 1da8970..57c752c 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -37,6 +37,9 @@ Core and Builtins
Library
-------
+- Issue #22775: Fixed unpickling of Cookie.SimpleCookie with protocol 2.
+ Patch by Tim Graham.
+
- Issue #22776: Brought excluded code into the scope of a try block in
SysLogHandler.emit().