Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[soc2009/http-wsgi-improvements] Clean up charset-related code in Htt…

…pResponse. Refs #10190.

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/http-wsgi-improvements@11448 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c2d80a5acbfdbab14586d3970f88439fea7ccb04 1 parent d76879d
@ccahoon ccahoon authored
Showing with 13 additions and 10 deletions.
  1. +13 −10 django/http/__init__.py
View
23 django/http/__init__.py
@@ -277,15 +277,9 @@ class HttpResponse(object):
def __init__(self, content='', mimetype=None, status=None,
content_type=None, request=None):
from django.conf import settings
- accept_charset = None
- self._charset = settings.DEFAULT_CHARSET
if mimetype:
content_type = mimetype # Mimetype arg is an alias for content-type
- if request:
- accept_charset = request.META.get("ACCEPT_CHARSET")
- if accept_charset or content_type:
- encoding = get_response_encoding(content_type, accept_charset)
- (self._charset, self._codec) = encoding
+ self.determine_charset(content_type, request)
if not content_type:
content_type = "%s; charset=%s" % (settings.DEFAULT_CONTENT_TYPE,
self._charset)
@@ -294,8 +288,7 @@ def __init__(self, content='', mimetype=None, status=None,
if hasattr(content, 'close'):
content.close()
self.cookies = SimpleCookie()
- if status:
- self.status_code = status
+ self.status_code = status
# _headers is a mapping of the lower-case name to the original case of
# the header (required for working with legacy systems) and the header
# value.
@@ -306,6 +299,15 @@ def __str__(self):
return '\n'.join(['%s: %s' % (k, v) for k, v in self._headers.values()]) \
+ "\n\n" + self.content
+ def determine_charset(self, content_type, request):
+ self._charset = settings.DEFAULT_CHARSET
+ accept_charset = None
+ if request:
+ accept_charset = request.META.get("ACCEPT_CHARSET")
+ if accept_charset or content_type:
+ encoding = get_response_encoding(content_type, accept_charset)
+ (self._charset, self._codec) = encoding
+
def _convert_to_ascii(self, *values):
"""Converts all values to ascii strings."""
for value in values:
@@ -390,7 +392,8 @@ def _get_status_code(self):
return self._status_code
def _set_status_code(self, value):
- self._status_code = value
+ if value:
+ self._status_code = value
status_code = property(_get_status_code, _set_status_code)
Please sign in to comment.
Something went wrong with that request. Please try again.