Fixed #10184: QueryDicts with multiple values can now be safely pickled. Thanks, Alex Gaynor.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10240 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
62353e8fe7
commit
9ae873fcd8
|
@ -223,6 +223,17 @@ class MultiValueDict(dict):
|
||||||
copy.deepcopy(value, memo))
|
copy.deepcopy(value, memo))
|
||||||
return result
|
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):
|
def get(self, key, default=None):
|
||||||
"""
|
"""
|
||||||
Returns the last data value for the passed key. If key doesn't exist
|
Returns the last data value for the passed key. If key doesn't exist
|
||||||
|
|
|
@ -396,10 +396,18 @@ u'\ufffd'
|
||||||
# Pickling a QueryDict #
|
# Pickling a QueryDict #
|
||||||
########################
|
########################
|
||||||
>>> import pickle
|
>>> import pickle
|
||||||
|
>>> q = QueryDict('')
|
||||||
|
>>> q1 = pickle.loads(pickle.dumps(q, 2))
|
||||||
|
>>> q == q1
|
||||||
|
True
|
||||||
>>> q = QueryDict('a=b&c=d')
|
>>> q = QueryDict('a=b&c=d')
|
||||||
>>> q1 = pickle.loads(pickle.dumps(q, 2))
|
>>> q1 = pickle.loads(pickle.dumps(q, 2))
|
||||||
>>> q == q1
|
>>> q == q1
|
||||||
True
|
True
|
||||||
|
>>> q = QueryDict('a=b&c=d&a=1')
|
||||||
|
>>> q1 = pickle.loads(pickle.dumps(q, 2))
|
||||||
|
>>> q == q1
|
||||||
|
True
|
||||||
|
|
||||||
######################################
|
######################################
|
||||||
# HttpResponse with Unicode headers #
|
# HttpResponse with Unicode headers #
|
||||||
|
|
Loading…
Reference in New Issue