Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[soc2009/http-wsgi-improvements] Added the codec attribute/property t…

…o 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
  • Loading branch information...
commit bf66b536a2e5c1307b3e47d737012fd4829faf01 1 parent c53880e
Christopher Cahoon authored July 11, 2009
9  django/http/__init__.py
@@ -373,6 +373,15 @@ def _configure_body_encoding(self):
373 373
         if not self._codec:
374 374
             self._codec = UnsupportedCharset
375 375
 
  376
+    def _get_codec(self):
  377
+        return self._codec
  378
+
  379
+    def _set_codec(self, value):
  380
+        if hasattr(value, "name"):
  381
+            self._codec = value
  382
+
  383
+    codec = property(_get_codec, _set_codec)
  384
+
376 385
     def _get_status_code(self):
377 386
         self._configure_body_encoding()
378 387
         if self._codec is UnsupportedCharset:
15  docs/ref/request-response.txt
@@ -471,10 +471,19 @@ Attributes
471 471
     A normal Python string representing the content, encoded from a Unicode
472 472
     object if necessary.
473 473
 
  474
+.. attribute :: HttpResponse.codec
  475
+
  476
+    A class that contains the attribute ``name``, which contains an alias or
  477
+    name of a codec (from the module ``codecs``) that will be used to encode
  478
+    the response content. This value is set automatically in response to a
  479
+    ``request`` argument that contains an Accept-Charset header or content_type
  480
+    argument that contains a charset value. The priority for setting the codec/
  481
+    charset is specified in HttpResponse.charsets.
  482
+
474 483
 Methods
475 484
 -------
476 485
 
477  
-.. method:: HttpResponse.__init__(content='', mimetype=None, status=200, content_type=DEFAULT_CONTENT_TYPE)
  486
+.. method:: HttpResponse.__init__(content='', mimetype=None, status=200, content_type=DEFAULT_CONTENT_TYPE, request=None)
478 487
 
479 488
     Instantiates an ``HttpResponse`` object with the given page content (a
480 489
     string) and MIME type. The ``DEFAULT_CONTENT_TYPE`` is ``'text/html'``.
@@ -495,6 +504,10 @@ Methods
495 504
     Otherwise, ``content_type`` is used. If neither is given, the
496 505
     ``DEFAULT_CONTENT_TYPE`` setting is used.
497 506
 
  507
+    ``request`` is the request that triggered this response. It can be used in
  508
+    the event that a view cares about dealing with request headers, in
  509
+    particular the Accept-Charset header.
  510
+
498 511
 .. method:: HttpResponse.__setitem__(header, value)
499 512
 
500 513
     Sets the given header name to the given value. Both ``header`` and

0 notes on commit bf66b53

Please sign in to comment.
Something went wrong with that request. Please try again.