summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Cahoon <chris.cahoon@gmail.com>2009-07-11 02:00:34 +0000
committerChris Cahoon <chris.cahoon@gmail.com>2009-07-11 02:00:34 +0000
commitbf66b536a2e5c1307b3e47d737012fd4829faf01 (patch)
treede3a6c9d961f95de98be1256fad79a0bd553a735
parentc53880e2c1c040f3ef68b393c47d152a4f719579 (diff)
[soc2009/http-wsgi-improvements] Added the codec attribute/property to HttpResponse, and added docs for recent work with charsets/codecs.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/http-wsgi-improvements@11214 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/http/__init__.py9
-rw-r--r--docs/ref/request-response.txt15
2 files changed, 23 insertions, 1 deletions
diff --git a/django/http/__init__.py b/django/http/__init__.py
index 78ab957543..049f9420e5 100644
--- a/django/http/__init__.py
+++ b/django/http/__init__.py
@@ -373,6 +373,15 @@ class HttpResponse(object):
if not self._codec:
self._codec = UnsupportedCharset
+ def _get_codec(self):
+ return self._codec
+
+ def _set_codec(self, value):
+ if hasattr(value, "name"):
+ self._codec = value
+
+ codec = property(_get_codec, _set_codec)
+
def _get_status_code(self):
self._configure_body_encoding()
if self._codec is UnsupportedCharset:
diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt
index bae79520ac..881d278a55 100644
--- a/docs/ref/request-response.txt
+++ b/docs/ref/request-response.txt
@@ -471,10 +471,19 @@ Attributes
A normal Python string representing the content, encoded from a Unicode
object if necessary.
+.. attribute :: HttpResponse.codec
+
+ A class that contains the attribute ``name``, which contains an alias or
+ name of a codec (from the module ``codecs``) that will be used to encode
+ the response content. This value is set automatically in response to a
+ ``request`` argument that contains an Accept-Charset header or content_type
+ argument that contains a charset value. The priority for setting the codec/
+ charset is specified in HttpResponse.charsets.
+
Methods
-------
-.. method:: HttpResponse.__init__(content='', mimetype=None, status=200, content_type=DEFAULT_CONTENT_TYPE)
+.. method:: HttpResponse.__init__(content='', mimetype=None, status=200, content_type=DEFAULT_CONTENT_TYPE, request=None)
Instantiates an ``HttpResponse`` object with the given page content (a
string) and MIME type. The ``DEFAULT_CONTENT_TYPE`` is ``'text/html'``.
@@ -495,6 +504,10 @@ Methods
Otherwise, ``content_type`` is used. If neither is given, the
``DEFAULT_CONTENT_TYPE`` setting is used.
+ ``request`` is the request that triggered this response. It can be used in
+ the event that a view cares about dealing with request headers, in
+ particular the Accept-Charset header.
+
.. method:: HttpResponse.__setitem__(header, value)
Sets the given header name to the given value. Both ``header`` and