Django

Code

Changeset 8460

Show
Ignore:
Timestamp:
08/21/08 08:55:21 (3 months ago)
Author:
mtredinnick
Message:

Fixed #7233 -- Ensured that QueryDict? classes are always unpicklable. This
problem only arose on some systems, since it depends upon the order in which
the attributes are pickled. Makes reliable testing kind of tricky.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/http/__init__.py

    r8202 r8460  
    129129    (DEFAULT_CHARSET by default) to unicode. 
    130130    """ 
     131    # These are both reset in __init__, but is specified here at the class 
     132    # level so that unpickling will have valid values 
     133    _mutable = True 
     134    _encoding = None 
     135 
    131136    def __init__(self, query_string, mutable=False, encoding=None): 
    132137        MultiValueDict.__init__(self) 
     
    137142            encoding = settings.DEFAULT_CHARSET 
    138143        self.encoding = encoding 
    139         self._mutable = True 
    140144        for key, value in parse_qsl((query_string or ''), True): # keep_blank_values=True 
    141145            self.appendlist(force_unicode(key, encoding, errors='replace'), 
    142146                            force_unicode(value, encoding, errors='replace')) 
    143147        self._mutable = mutable 
     148 
     149    def _get_encoding(self): 
     150        if self._encoding is None: 
     151            # *Important*: do not import settings at the module level because 
     152            # of the note in core.handlers.modpython. 
     153            from django.conf import settings 
     154            self._encoding = settings.DEFAULT_CHARSET 
     155        return self._encoding 
     156 
     157    def _set_encoding(self, value): 
     158        self._encoding = value 
     159 
     160    encoding = property(_get_encoding, _set_encoding) 
    144161 
    145162    def _assert_mutable(self): 
  • django/trunk/tests/regressiontests/httpwrappers/tests.py

    r6928 r8460  
    393393 
    394394 
    395 ######################################  
    396 # HttpResponse with Unicode headers  #  
    397 ######################################  
    398   
    399 >>> r = HttpResponse()  
    400   
     395######################## 
     396# Pickling a QueryDict # 
     397######################## 
     398>>> import pickle 
     399>>> q = QueryDict('a=b&c=d') 
     400>>> q1 = pickle.loads(pickle.dumps(q)) 
     401>>> q == q1 
     402True 
     403 
     404###################################### 
     405# HttpResponse with Unicode headers  # 
     406###################################### 
     407 
     408>>> r = HttpResponse() 
     409 
    401410If we insert a unicode value it will be converted to an ascii 
    402411string. This makes sure we comply with the HTTP specifications. 
    403   
    404 >>> r['value'] = u'test value'  
    405 >>> isinstance(r['value'], str)  
     412 
     413>>> r['value'] = u'test value' 
     414>>> isinstance(r['value'], str) 
    406415True 
    407416 
     
    412421... 
    413422UnicodeEncodeError: ..., HTTP response headers must be in US-ASCII format 
    414   
    415 The response also converts unicode keys to strings.  
    416   
    417 >>> r[u'test'] = 'testing key'  
     423 
     424The response also converts unicode keys to strings. 
     425 
     426>>> r[u'test'] = 'testing key' 
    418427>>> l = list(r.items()) 
    419428>>> l.sort() 
     
    427436... 
    428437UnicodeEncodeError: ..., HTTP response headers must be in US-ASCII format 
    429   
     438 
    430439""" 
    431440