mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
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
This commit is contained in:
parent
57ced25606
commit
cd3d40ec91
@ -13,6 +13,7 @@ from django.dispatch import dispatcher
|
|||||||
from django.http import urlencode, SimpleCookie, HttpRequest
|
from django.http import urlencode, SimpleCookie, HttpRequest
|
||||||
from django.test import signals
|
from django.test import signals
|
||||||
from django.utils.functional import curry
|
from django.utils.functional import curry
|
||||||
|
from django.utils.encoding import smart_str
|
||||||
|
|
||||||
BOUNDARY = 'BoUnDaRyStRiNg'
|
BOUNDARY = 'BoUnDaRyStRiNg'
|
||||||
MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY
|
MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY
|
||||||
@ -61,14 +62,15 @@ def encode_multipart(boundary, data):
|
|||||||
as an application/octet-stream; otherwise, str(value) will be sent.
|
as an application/octet-stream; otherwise, str(value) will be sent.
|
||||||
"""
|
"""
|
||||||
lines = []
|
lines = []
|
||||||
|
to_str = lambda s: smart_str(s, settings.DEFAULT_CHARSET)
|
||||||
for (key, value) in data.items():
|
for (key, value) in data.items():
|
||||||
if isinstance(value, file):
|
if isinstance(value, file):
|
||||||
lines.extend([
|
lines.extend([
|
||||||
'--' + boundary,
|
'--' + boundary,
|
||||||
'Content-Disposition: form-data; name="%s"' % key,
|
'Content-Disposition: form-data; name="%s"' % to_str(key),
|
||||||
'',
|
'',
|
||||||
'--' + boundary,
|
'--' + 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',
|
'Content-Type: application/octet-stream',
|
||||||
'',
|
'',
|
||||||
value.read()
|
value.read()
|
||||||
@ -77,16 +79,16 @@ def encode_multipart(boundary, data):
|
|||||||
for item in value:
|
for item in value:
|
||||||
lines.extend([
|
lines.extend([
|
||||||
'--' + boundary,
|
'--' + boundary,
|
||||||
'Content-Disposition: form-data; name="%s"' % key,
|
'Content-Disposition: form-data; name="%s"' % to_str(key),
|
||||||
'',
|
'',
|
||||||
str(item)
|
to_str(item)
|
||||||
])
|
])
|
||||||
else:
|
else:
|
||||||
lines.extend([
|
lines.extend([
|
||||||
'--' + boundary,
|
'--' + boundary,
|
||||||
'Content-Disposition: form-data; name="%s"' % key,
|
'Content-Disposition: form-data; name="%s"' % to_str(key),
|
||||||
'',
|
'',
|
||||||
str(value)
|
to_str(value)
|
||||||
])
|
])
|
||||||
|
|
||||||
lines.extend([
|
lines.extend([
|
||||||
|
Loading…
x
Reference in New Issue
Block a user