Ticket #13572: querydict-copy-encoding-fix-and-tests.patch

File querydict-copy-encoding-fix-and-tests.patch, 1.8 KB (added by adammck, 15 years ago)
  • django/http/__init__.py

     
    177177        super(QueryDict, self).__delitem__(key)
    178178
    179179    def __copy__(self):
    180         result = self.__class__('', mutable=True)
     180        result = self.__class__('', mutable=True, encoding=self.encoding)
    181181        for key, value in dict.items(self):
    182182            dict.__setitem__(result, key, value)
    183183        return result
    184184
    185185    def __deepcopy__(self, memo):
    186186        import django.utils.copycompat as copy
    187         result = self.__class__('', mutable=True)
     187        result = self.__class__('', mutable=True, encoding=self.encoding)
    188188        memo[id(self)] = result
    189189        for key, value in dict.items(self):
    190190            dict.__setitem__(result, copy.deepcopy(key, memo), copy.deepcopy(value, memo))
  • tests/regressiontests/httpwrappers/tests.py

     
    392392[u'bar', u'\ufffd']
    393393
    394394
     395#######################################
     396# QueryDict with non-default encoding #
     397#######################################
     398
     399>>> q = QueryDict('sbb=one', encoding='rot_13')
     400>>> q.encoding
     401'rot_13'
     402
     403>>> q.items()
     404[(u'foo', u'bar')]
     405
     406>>> q.urlencode()
     407'sbb=one'
     408
     409>>> q = q.copy()
     410>>> q.encoding
     411'rot_13'
     412
     413>>> q.items()
     414[(u'foo', u'bar')]
     415
     416>>> q.urlencode()
     417'sbb=one'
     418
     419>>> from copy import copy
     420>>> copy(q).encoding
     421'rot_13'
     422
     423>>> from copy import deepcopy
     424>>> deepcopy(q).encoding
     425'rot_13'
     426
     427
     428
    395429########################
    396430# Pickling a QueryDict #
    397431########################
Back to Top