mirror of
https://github.com/django/django.git
synced 2025-10-25 22:56:12 +00:00
Refs #23919 -- Removed six.PY2/PY3 usage
Thanks Tim Graham for the review.
This commit is contained in:
@@ -2,13 +2,11 @@ import codecs
|
||||
import datetime
|
||||
import locale
|
||||
from decimal import Decimal
|
||||
from urllib.parse import unquote_to_bytes
|
||||
|
||||
from django.utils import six
|
||||
from django.utils.functional import Promise
|
||||
from django.utils.six.moves.urllib.parse import quote, unquote
|
||||
|
||||
if six.PY3:
|
||||
from urllib.parse import unquote_to_bytes
|
||||
from django.utils.six.moves.urllib.parse import quote
|
||||
|
||||
|
||||
class DjangoUnicodeDecodeError(UnicodeDecodeError):
|
||||
@@ -66,15 +64,10 @@ def force_text(s, encoding='utf-8', strings_only=False, errors='strict'):
|
||||
return s
|
||||
try:
|
||||
if not issubclass(type(s), six.string_types):
|
||||
if six.PY3:
|
||||
if isinstance(s, bytes):
|
||||
s = six.text_type(s, encoding, errors)
|
||||
else:
|
||||
s = six.text_type(s)
|
||||
elif hasattr(s, '__unicode__'):
|
||||
s = six.text_type(s)
|
||||
if isinstance(s, bytes):
|
||||
s = six.text_type(s, encoding, errors)
|
||||
else:
|
||||
s = six.text_type(bytes(s), encoding, errors)
|
||||
s = six.text_type(s)
|
||||
else:
|
||||
# Note: We use .decode() here, instead of six.text_type(s, encoding,
|
||||
# errors), so that if s is a SafeBytes, it ends up being a
|
||||
@@ -127,10 +120,7 @@ def force_bytes(s, encoding='utf-8', strings_only=False, errors='strict'):
|
||||
return six.text_type(s).encode(encoding, errors)
|
||||
if not isinstance(s, six.string_types):
|
||||
try:
|
||||
if six.PY3:
|
||||
return six.text_type(s).encode(encoding)
|
||||
else:
|
||||
return bytes(s)
|
||||
return six.text_type(s).encode(encoding)
|
||||
except UnicodeEncodeError:
|
||||
if isinstance(s, Exception):
|
||||
# An Exception subclass containing non-ASCII data that doesn't
|
||||
@@ -143,15 +133,8 @@ def force_bytes(s, encoding='utf-8', strings_only=False, errors='strict'):
|
||||
return s.encode(encoding, errors)
|
||||
|
||||
|
||||
if six.PY3:
|
||||
smart_str = smart_text
|
||||
force_str = force_text
|
||||
else:
|
||||
smart_str = smart_bytes
|
||||
force_str = force_bytes
|
||||
# backwards compatibility for Python 2
|
||||
smart_unicode = smart_text
|
||||
force_unicode = force_text
|
||||
smart_str = smart_text
|
||||
force_str = force_text
|
||||
|
||||
smart_str.__doc__ = """
|
||||
Apply smart_text in Python 3 and smart_bytes in Python 2.
|
||||
@@ -207,7 +190,7 @@ def uri_to_iri(uri):
|
||||
if uri is None:
|
||||
return uri
|
||||
uri = force_bytes(uri)
|
||||
iri = unquote_to_bytes(uri) if six.PY3 else unquote(uri)
|
||||
iri = unquote_to_bytes(uri)
|
||||
return repercent_broken_unicode(iri).decode('utf-8')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user