mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Replaced many smart_bytes by force_bytes
In all those occurrences, we didn't care about preserving the lazy status of the strings, but we really wanted to obtain a real bytestring.
This commit is contained in:
@@ -21,7 +21,7 @@ from django.http import SimpleCookie, HttpRequest, QueryDict
|
||||
from django.template import TemplateDoesNotExist
|
||||
from django.test import signals
|
||||
from django.utils.functional import curry
|
||||
from django.utils.encoding import smart_bytes
|
||||
from django.utils.encoding import force_bytes
|
||||
from django.utils.http import urlencode
|
||||
from django.utils.importlib import import_module
|
||||
from django.utils.itercompat import is_iterable
|
||||
@@ -110,7 +110,7 @@ def encode_multipart(boundary, data):
|
||||
as an application/octet-stream; otherwise, str(value) will be sent.
|
||||
"""
|
||||
lines = []
|
||||
to_bytes = lambda s: smart_bytes(s, settings.DEFAULT_CHARSET)
|
||||
to_bytes = lambda s: force_bytes(s, settings.DEFAULT_CHARSET)
|
||||
|
||||
# Not by any means perfect, but good enough for our purposes.
|
||||
is_file = lambda thing: hasattr(thing, "read") and callable(thing.read)
|
||||
@@ -147,7 +147,7 @@ def encode_multipart(boundary, data):
|
||||
return b'\r\n'.join(lines)
|
||||
|
||||
def encode_file(boundary, key, file):
|
||||
to_bytes = lambda s: smart_bytes(s, settings.DEFAULT_CHARSET)
|
||||
to_bytes = lambda s: force_bytes(s, settings.DEFAULT_CHARSET)
|
||||
content_type = mimetypes.guess_type(file.name)[0]
|
||||
if content_type is None:
|
||||
content_type = 'application/octet-stream'
|
||||
@@ -222,7 +222,7 @@ class RequestFactory(object):
|
||||
charset = match.group(1)
|
||||
else:
|
||||
charset = settings.DEFAULT_CHARSET
|
||||
return smart_bytes(data, encoding=charset)
|
||||
return force_bytes(data, encoding=charset)
|
||||
|
||||
def _get_path(self, parsed):
|
||||
# If there are parameters, add them
|
||||
@@ -293,7 +293,7 @@ class RequestFactory(object):
|
||||
def generic(self, method, path,
|
||||
data='', content_type='application/octet-stream', **extra):
|
||||
parsed = urlparse(path)
|
||||
data = smart_bytes(data, settings.DEFAULT_CHARSET)
|
||||
data = force_bytes(data, settings.DEFAULT_CHARSET)
|
||||
r = {
|
||||
'PATH_INFO': self._get_path(parsed),
|
||||
'QUERY_STRING': parsed[4],
|
||||
|
||||
@@ -41,7 +41,7 @@ from django.test.utils import (get_warnings_state, restore_warnings_state,
|
||||
override_settings)
|
||||
from django.test.utils import ContextList
|
||||
from django.utils import unittest as ut2
|
||||
from django.utils.encoding import smart_bytes, force_text
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils import six
|
||||
from django.utils.unittest.util import safe_repr
|
||||
from django.views.static import serve
|
||||
|
||||
Reference in New Issue
Block a user