# effectively a deep copy.
return self.copy()
+ def __reduce_ex__(self, v):
+ # We must override dict.__reduce_ex__ to pickle ourselves
+ # correctly.
+ return HTTPHeaders, (), list(self.get_all())
+
+ def __setstate__(self, state):
+ for k, v in state:
+ self.add(k, v)
+
class HTTPServerRequest(object):
"""A single HTTP request.
import copy
import datetime
import logging
+import pickle
import time
class TestUrlConcat(unittest.TestCase):
-
def test_url_concat_no_query_params(self):
url = url_concat(
"https://localhost/path",
self.assertIsNot(headers, h1)
self.assertIsNot(headers.get_list('A'), h1.get_list('A'))
+ def test_pickle_roundtrip(self):
+ headers = HTTPHeaders()
+ headers.add('Set-Cookie', 'a=b')
+ headers.add('Set-Cookie', 'c=d')
+ headers.add('Content-Type', 'text/html')
+ pickled = pickle.dumps(headers)
+ unpickled = pickle.loads(pickled)
+ self.assertEqual(sorted(headers.get_all()), sorted(unpickled.get_all()))
+ self.assertEqual(sorted(headers.items()), sorted(unpickled.items()))
class FormatTimestampTest(unittest.TestCase):