summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-05-14 21:50:38 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-05-14 21:50:38 +0000
commitcd3d40ec9134a007b376d00a157edc0f275b5648 (patch)
treebb09d9cb24dbd650feed565e106feebbb70d156e /django
parent57ced2560683f7af0c99971dfaaf9c70fca78506 (diff)
unicode: Fixed handling of unicode data passed to test client. Refs #3432.
git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5242 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/test/client.py32
1 files changed, 17 insertions, 15 deletions
diff --git a/django/test/client.py b/django/test/client.py
index c3110f02ec..848cdce9f0 100644
--- a/django/test/client.py
+++ b/django/test/client.py
@@ -13,6 +13,7 @@ from django.dispatch import dispatcher
from django.http import urlencode, SimpleCookie, HttpRequest
from django.test import signals
from django.utils.functional import curry
+from django.utils.encoding import smart_str
BOUNDARY = 'BoUnDaRyStRiNg'
MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY
@@ -61,32 +62,33 @@ def encode_multipart(boundary, data):
as an application/octet-stream; otherwise, str(value) will be sent.
"""
lines = []
+ to_str = lambda s: smart_str(s, settings.DEFAULT_CHARSET)
for (key, value) in data.items():
if isinstance(value, file):
lines.extend([
'--' + boundary,
- 'Content-Disposition: form-data; name="%s"' % key,
+ 'Content-Disposition: form-data; name="%s"' % to_str(key),
'',
'--' + boundary,
- 'Content-Disposition: form-data; name="%s_file"; filename="%s"' % (key, value.name),
+ 'Content-Disposition: form-data; name="%s_file"; filename="%s"' % (to_str(key), to_str(value.name)),
'Content-Type: application/octet-stream',
'',
value.read()
])
- elif hasattr(value, '__iter__'):
+ elif hasattr(value, '__iter__'):
for item in value:
- lines.extend([
- '--' + boundary,
- 'Content-Disposition: form-data; name="%s"' % key,
- '',
- str(item)
+ lines.extend([
+ '--' + boundary,
+ 'Content-Disposition: form-data; name="%s"' % to_str(key),
+ '',
+ to_str(item)
])
else:
lines.extend([
'--' + boundary,
- 'Content-Disposition: form-data; name="%s"' % key,
+ 'Content-Disposition: form-data; name="%s"' % to_str(key),
'',
- str(value)
+ to_str(value)
])
lines.extend([
@@ -118,7 +120,7 @@ class Client:
self.defaults = defaults
self.cookies = SimpleCookie()
self.exc_info = None
-
+
def store_exc_info(self, *args, **kwargs):
"""
Utility method that can be used to store exceptions when they are
@@ -134,7 +136,7 @@ class Client:
return SessionWrapper(cookie.value)
return {}
session = property(_session)
-
+
def request(self, **request):
"""
The master request method. Composes the environment dictionary
@@ -182,7 +184,7 @@ class Client:
# Look for a signalled exception and reraise it
if self.exc_info:
raise self.exc_info[1], None, self.exc_info[2]
-
+
# Update persistent cookie data
if response.cookies:
self.cookies.update(response.cookies)
@@ -246,9 +248,9 @@ class Client:
# Set the session values
Session.objects.save(obj.session_key, request.session._session,
- datetime.datetime.now() + datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE))
+ datetime.datetime.now() + datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE))
return True
else:
return False
- \ No newline at end of file
+