Changeset 8460
- Timestamp:
- 08/21/08 08:55:21 (3 months ago)
- Files:
-
- django/trunk/django/http/__init__.py (modified) (2 diffs)
- django/trunk/tests/regressiontests/httpwrappers/tests.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/http/__init__.py
r8202 r8460 129 129 (DEFAULT_CHARSET by default) to unicode. 130 130 """ 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 131 136 def __init__(self, query_string, mutable=False, encoding=None): 132 137 MultiValueDict.__init__(self) … … 137 142 encoding = settings.DEFAULT_CHARSET 138 143 self.encoding = encoding 139 self._mutable = True140 144 for key, value in parse_qsl((query_string or ''), True): # keep_blank_values=True 141 145 self.appendlist(force_unicode(key, encoding, errors='replace'), 142 146 force_unicode(value, encoding, errors='replace')) 143 147 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) 144 161 145 162 def _assert_mutable(self): django/trunk/tests/regressiontests/httpwrappers/tests.py
r6928 r8460 393 393 394 394 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 402 True 403 404 ###################################### 405 # HttpResponse with Unicode headers # 406 ###################################### 407 408 >>> r = HttpResponse() 409 401 410 If we insert a unicode value it will be converted to an ascii 402 411 string. 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) 406 415 True 407 416 … … 412 421 ... 413 422 UnicodeEncodeError: ..., 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 424 The response also converts unicode keys to strings. 425 426 >>> r[u'test'] = 'testing key' 418 427 >>> l = list(r.items()) 419 428 >>> l.sort() … … 427 436 ... 428 437 UnicodeEncodeError: ..., HTTP response headers must be in US-ASCII format 429 438 430 439 """ 431 440
