summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-05-25 09:48:02 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-05-25 09:48:02 +0000
commit7ba850af3ba4ac7dbe3d67a2360079bce0bf0eb3 (patch)
tree9060bd793b288b686e0894d8dd33061027991da9 /django
parent29d2094b29ccbc09f49772ca7dd773aca5114a9b (diff)
unicode: Added a more convenient way to set/change the encoding on a request
instance. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5342 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/core/handlers/modpython.py4
-rw-r--r--django/core/handlers/wsgi.py6
-rw-r--r--django/http/__init__.py19
3 files changed, 24 insertions, 5 deletions
diff --git a/django/core/handlers/modpython.py b/django/core/handlers/modpython.py
index 6370cab47c..cbb65bba5f 100644
--- a/django/core/handlers/modpython.py
+++ b/django/core/handlers/modpython.py
@@ -49,7 +49,7 @@ class ModPythonRequest(http.HttpRequest):
if 'content-type' in self._req.headers_in and self._req.headers_in['content-type'].startswith('multipart'):
self._post, self._files = http.parse_file_upload(self._req.headers_in, self.raw_post_data)
else:
- self._post, self._files = http.QueryDict(self.raw_post_data), datastructures.MultiValueDict()
+ self._post, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict()
def _get_request(self):
if not hasattr(self, '_request'):
@@ -58,7 +58,7 @@ class ModPythonRequest(http.HttpRequest):
def _get_get(self):
if not hasattr(self, '_get'):
- self._get = http.QueryDict(self._req.args)
+ self._get = http.QueryDict(self._req.args, encoding=self._encoding)
return self._get
def _set_get(self, get):
diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py
index 4320b69627..04c39834d1 100644
--- a/django/core/handlers/wsgi.py
+++ b/django/core/handlers/wsgi.py
@@ -113,9 +113,9 @@ class WSGIRequest(http.HttpRequest):
header_dict['Content-Type'] = self.environ.get('CONTENT_TYPE', '')
self._post, self._files = http.parse_file_upload(header_dict, self.raw_post_data)
else:
- self._post, self._files = http.QueryDict(self.raw_post_data), datastructures.MultiValueDict()
+ self._post, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict()
else:
- self._post, self._files = http.QueryDict(''), datastructures.MultiValueDict()
+ self._post, self._files = http.QueryDict('', encoding=self._encoding), datastructures.MultiValueDict()
def _get_request(self):
if not hasattr(self, '_request'):
@@ -125,7 +125,7 @@ class WSGIRequest(http.HttpRequest):
def _get_get(self):
if not hasattr(self, '_get'):
# The WSGI spec says 'QUERY_STRING' may be absent.
- self._get = http.QueryDict(self.environ.get('QUERY_STRING', ''))
+ self._get = http.QueryDict(self.environ.get('QUERY_STRING', ''), encoding=self._encoding)
return self._get
def _set_get(self, get):
diff --git a/django/http/__init__.py b/django/http/__init__.py
index 5bc0e4ca54..481c604ba8 100644
--- a/django/http/__init__.py
+++ b/django/http/__init__.py
@@ -18,6 +18,10 @@ class Http404(Exception):
class HttpRequest(object):
"A basic HTTP request"
+
+ # The encoding used in GET/POST dicts. None means use default setting.
+ _encoding = None
+
def __init__(self):
self.GET, self.POST, self.COOKIES, self.META, self.FILES = {}, {}, {}, {}, {}
self.path = ''
@@ -43,6 +47,21 @@ class HttpRequest(object):
def is_secure(self):
return os.environ.get("HTTPS") == "on"
+ def _set_encoding(self, val):
+ """
+ Sets the encoding used for GET/POST accesses.
+ """
+ self._encoding = val
+ if hasattr(self, '_get'):
+ self.GET.encoding = val
+ if hasattr(self, '_post'):
+ self.POST.encoding = val
+
+ def _get_encoding(self):
+ return self._encoding
+
+ encoding = property(_get_encoding, _set_encoding)
+
def parse_file_upload(header_dict, post_data):
"Returns a tuple of (POST MultiValueDict, FILES MultiValueDict)"
import email, email.Message