Ticket #10184: querydict-pickle.diff

File querydict-pickle.diff, 2.1 KB (added by Alex Gaynor, 16 years ago)
  • django/http/__init__.py

    diff --git a/django/http/__init__.py b/django/http/__init__.py
    index 60b6d15..033a0c1 100644
    a b class QueryDict(MultiValueDict):  
    190190            dict.__setitem__(result, copy.deepcopy(key, memo), copy.deepcopy(value, memo))
    191191        return result
    192192
     193    def __getstate__(self):
     194        obj_dict = super(QueryDict, self).__getstate__()
     195        obj_dict['_mutable'] = self._mutable
     196        return obj_dict
     197
     198    def __setstate__(self, obj_dict):
     199        data = obj_dict.pop('_data', [])
     200        for k, v in data.items():
     201            self.setlist(k, v)
     202        self.__dict__.update(obj_dict)
     203       
    193204    def setlist(self, key, list_):
    194205        self._assert_mutable()
    195206        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..d88e7b0 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..49b104b 100644
    a b u'\ufffd'  
    400400>>> q1 = pickle.loads(pickle.dumps(q, 2))
    401401>>> q == q1
    402402True
     403>>> q = QueryDict('a=b&c=d&a=1')
     404>>> q1 = pickle.loads(pickle.dumps(q, 2))
     405>>> q == q1
     406True
    403407
    404408######################################
    405409# HttpResponse with Unicode headers  #
Back to Top