Fixed a silly function flow bug in [10711].

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10712 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss 2009-05-08 11:31:36 +00:00
parent 155ab07a5d
commit 38a6c48878
1 changed files with 5 additions and 4 deletions

View File

@ -304,16 +304,17 @@ class HttpResponse(object):
def _convert_to_ascii(self, *values):
"""Converts all values to ascii strings."""
for value in values:
if '\n' in value or '\r' in value:
raise BadHeaderError("Header values can't contain newlines (got %r)" % (value))
if isinstance(value, unicode):
try:
yield value.encode('us-ascii')
value = value.encode('us-ascii')
except UnicodeError, e:
e.reason += ', HTTP response headers must be in US-ASCII format'
raise
else:
yield str(value)
value = str(value)
if '\n' in value or '\r' in value:
raise BadHeaderError("Header values can't contain newlines (got %r)" % (value))
yield value
def __setitem__(self, header, value):
header, value = self._convert_to_ascii(header, value)