Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.0.X] Fixed #10184: QueryDicts with multiple values can now be safe…

…ly pickled. Thanks, Alex Gaynor.

Backport of [10240] from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10279 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 606c5a7e7e731166164f17243aec32a498e02422 1 parent 76fd191
Jacob Kaplan-Moss jacobian authored
2  django/http/__init__.py
View
@@ -189,7 +189,7 @@ def __deepcopy__(self, memo):
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)
13 django/utils/datastructures.py
View
@@ -222,7 +222,18 @@ def __deepcopy__(self, memo=None):
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
8 tests/regressiontests/httpwrappers/tests.py
View
@@ -396,10 +396,18 @@
# 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 #
Please sign in to comment.
Something went wrong with that request. Please try again.