# default implementation returns dict(self), not the subclass
return HTTPHeaders(self)
+ # Use our overridden copy method for the copy.copy module.
+ __copy__ = copy
+
+ def __deepcopy__(self, memo_dict):
+ # Our values are immutable strings, so our standard copy is
+ # effectively a deep copy.
+ return self.copy()
+
class HTTPServerRequest(object):
"""A single HTTP request.
from tornado.test.util import unittest
from tornado.util import u
+import copy
import datetime
import logging
import time
('Lf', 'lf'),
])
+ def test_copy(self):
+ all_pairs = [('A', '1'), ('A', '2'), ('B', 'c')]
+ h1 = HTTPHeaders()
+ for k, v in all_pairs:
+ h1.add(k, v)
+ h2 = h1.copy()
+ h3 = copy.copy(h1)
+ h4 = copy.deepcopy(h1)
+ for headers in [h1, h2, h3, h4]:
+ # All the copies are identical, no matter how they were
+ # constructed.
+ self.assertEqual(list(sorted(headers.get_all())), all_pairs)
+ for headers in [h2, h3, h4]:
+ # Neither the dict or its member lists are reused.
+ self.assertIsNot(headers, h1)
+ self.assertIsNot(headers.get_list('A'), h1.get_list('A'))
+
+
class FormatTimestampTest(unittest.TestCase):
# Make sure that all the input types are supported.