Ticket #8765: 8765.2.diff
File 8765.2.diff, 3.0 KB (added by , 15 years ago) |
---|
-
tests/regressiontests/httpwrappers/tests.py
### Eclipse Workspace Patch 1.0 #P Django trunk
429 429 ... 430 430 UnicodeEncodeError: ..., HTTP response headers must be in US-ASCII format 431 431 432 An error is raised when a unicode object with non-ascii is set as the initial 433 mimetype or content_type. 434 435 >>> HttpResponse(mimetype=u't\xebst value') # doctest:+ELLIPSIS 436 Traceback (most recent call last): 437 ... 438 UnicodeEncodeError: ..., HTTP response headers must be in US-ASCII format 439 >>> HttpResponse(content_type=u't\xebst value') # doctest:+ELLIPSIS 440 Traceback (most recent call last): 441 ... 442 UnicodeEncodeError: ..., HTTP response headers must be in US-ASCII format 443 432 444 The response also converts unicode keys to strings. 433 445 434 446 >>> r[u'test'] = 'testing key' -
django/http/__init__.py
272 272 status_code = 200 273 273 274 274 def __init__(self, content='', mimetype=None, status=None, 275 content_type=None): 276 from django.conf import settings 275 content_type=None): 276 # _headers is a mapping of the lower-case name to the original case of 277 # the header (required for working with legacy systems) and the header 278 # value. Both the name of the header and its value are ASCII strings. 279 self._headers = {} 277 280 self._charset = settings.DEFAULT_CHARSET 278 if mimetype: 279 content_type = mimetype # For backwards compatibility 280 if not content_type: 281 content_type = "%s; charset=%s" % (settings.DEFAULT_CONTENT_TYPE, 282 settings.DEFAULT_CHARSET) 281 self.cookies = SimpleCookie() 282 283 283 if not isinstance(content, basestring) and hasattr(content, '__iter__'): 284 284 self._container = content 285 285 self._is_string = False 286 286 else: 287 287 self._container = [content] 288 288 self._is_string = True 289 self.cookies = SimpleCookie() 289 290 if mimetype: 291 content_type = mimetype # For backwards compatibility 292 if not content_type: 293 content_type = "%s; charset=%s" % (settings.DEFAULT_CONTENT_TYPE, 294 self._charset) 295 self['Content-Type'] = content_type 296 290 297 if status: 291 298 self.status_code = status 292 299 293 # _headers is a mapping of the lower-case name to the original case of294 # the header (required for working with legacy systems) and the header295 # value.296 self._headers = {'content-type': ('Content-Type', content_type)}297 298 300 def __str__(self): 299 301 """Full HTTP message, including headers.""" 300 302 return '\n'.join(['%s: %s' % (key, value)