diff options
| author | Joseph Kocherhans <joseph@jkocherhans.com> | 2007-12-19 05:20:55 +0000 |
|---|---|---|
| committer | Joseph Kocherhans <joseph@jkocherhans.com> | 2007-12-19 05:20:55 +0000 |
| commit | f4c7a0dcb66d21987837ba6d4b4f192b15d39816 (patch) | |
| tree | 32201b839f6cc11600466f29c3d99f2155d41917 /django/http | |
| parent | 3f494f18231a369677104d408af775520823228a (diff) | |
newforms-admin: Merged from trunk up to [6952].
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6955 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/http')
| -rw-r--r-- | django/http/__init__.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/django/http/__init__.py b/django/http/__init__.py index 47f9736ce2..69e9d51204 100644 --- a/django/http/__init__.py +++ b/django/http/__init__.py @@ -277,7 +277,20 @@ class HttpResponse(object): for key, value in self._headers.values()]) \ + '\n\n' + self.content + def _convert_to_ascii(self, *values): + "Convert all values to ascii strings" + for value in values: + if isinstance(value, unicode): + try: + yield value.encode('us-ascii') + except UnicodeError, e: + e.reason += ', HTTP response headers must be in US-ASCII format' + raise + else: + yield str(value) + def __setitem__(self, header, value): + header, value = self._convert_to_ascii(header, value) self._headers[header.lower()] = (header, value) def __delitem__(self, header): @@ -331,7 +344,7 @@ class HttpResponse(object): chunk = self._iterator.next() if isinstance(chunk, unicode): chunk = chunk.encode(self._charset) - return chunk + return str(chunk) def close(self): if hasattr(self._container, 'close'): |
