Ticket #10184: querydict-pickle.3.diff

File querydict-pickle.3.diff, 2.0 KB (added by Alex, 6 years ago)
  • django/http/__init__.py

    diff --git a/django/http/__init__.py b/django/http/__init__.py
    index 60b6d15..812a0fd 100644
    a b class QueryDict(MultiValueDict): 
    189189        for key, value in dict.items(self):
    190190            dict.__setitem__(result, copy.deepcopy(key, memo), copy.deepcopy(value, memo))
    191191        return result
    192 
     192   
    193193    def setlist(self, key, list_):
    194194        self._assert_mutable()
    195195        key = str_to_unicode(key, self.encoding)
  • django/utils/datastructures.py

    diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
    index 5837c3d..d0cd908 100644
    a b class MultiValueDict(dict): 
    222222            dict.__setitem__(result, copy.deepcopy(key, memo),
    223223                             copy.deepcopy(value, memo))
    224224        return result
    225 
     225   
     226    def __getstate__(self):
     227        obj_dict = self.__dict__.copy()
     228        obj_dict['_data'] = dict([(k, self.getlist(k)) for k in self])
     229        return obj_dict
     230   
     231    def __setstate__(self, obj_dict):
     232        data = obj_dict.pop('_data', {})
     233        for k, v in data.items():
     234            self.setlist(k, v)
     235        self.__dict__.update(obj_dict)
     236       
    226237    def get(self, key, default=None):
    227238        """
    228239        Returns the last data value for the passed key. If key doesn't exist
  • tests/regressiontests/httpwrappers/tests.py

    diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py
    index 844b356..15b8728 100644
    a b u'\ufffd' 
    396396# Pickling a QueryDict #
    397397########################
    398398>>> import pickle
     399>>> q = QueryDict('')
     400>>> q1 = pickle.loads(pickle.dumps(q, 2))
     401>>> q == q1
     402True
    399403>>> q = QueryDict('a=b&c=d')
    400404>>> q1 = pickle.loads(pickle.dumps(q, 2))
    401405>>> q == q1
    402406True
     407>>> q = QueryDict('a=b&c=d&a=1')
     408>>> q1 = pickle.loads(pickle.dumps(q, 2))
     409>>> q == q1
     410True
    403411
    404412######################################
    405413# HttpResponse with Unicode headers  #
Back to Top