summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/http/__init__.py2
-rw-r--r--django/utils/datastructures.py13
-rw-r--r--tests/regressiontests/httpwrappers/tests.py8
3 files changed, 21 insertions, 2 deletions
diff --git a/django/http/__init__.py b/django/http/__init__.py
index 60b6d15795..812a0fdfa1 100644
--- a/django/http/__init__.py
+++ b/django/http/__init__.py
@@ -189,7 +189,7 @@ class QueryDict(MultiValueDict):
for key, value in dict.items(self):
dict.__setitem__(result, copy.deepcopy(key, memo), copy.deepcopy(value, memo))
return result
-
+
def setlist(self, key, list_):
self._assert_mutable()
key = str_to_unicode(key, self.encoding)
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index 5837c3d236..d0cd9085dd 100644
--- a/django/utils/datastructures.py
+++ b/django/utils/datastructures.py
@@ -222,7 +222,18 @@ class MultiValueDict(dict):
dict.__setitem__(result, copy.deepcopy(key, memo),
copy.deepcopy(value, memo))
return result
-
+
+ def __getstate__(self):
+ obj_dict = self.__dict__.copy()
+ obj_dict['_data'] = dict([(k, self.getlist(k)) for k in self])
+ return obj_dict
+
+ def __setstate__(self, obj_dict):
+ data = obj_dict.pop('_data', {})
+ for k, v in data.items():
+ self.setlist(k, v)
+ self.__dict__.update(obj_dict)
+
def get(self, key, default=None):
"""
Returns the last data value for the passed key. If key doesn't exist
diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py
index 844b356366..15b872821c 100644
--- a/tests/regressiontests/httpwrappers/tests.py
+++ b/tests/regressiontests/httpwrappers/tests.py
@@ -396,10 +396,18 @@ u'\ufffd'
# Pickling a QueryDict #
########################
>>> import pickle
+>>> q = QueryDict('')
+>>> q1 = pickle.loads(pickle.dumps(q, 2))
+>>> q == q1
+True
>>> q = QueryDict('a=b&c=d')
>>> q1 = pickle.loads(pickle.dumps(q, 2))
>>> q == q1
True
+>>> q = QueryDict('a=b&c=d&a=1')
+>>> q1 = pickle.loads(pickle.dumps(q, 2))
+>>> q == q1
+True
######################################
# HttpResponse with Unicode headers #