summaryrefslogtreecommitdiff
path: root/django/utils/encoding.py
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2017-01-26 10:08:08 +0100
committerTim Graham <timograham@gmail.com>2019-02-06 14:12:06 -0500
commit3bb6a4390c0a57da991fcb1c0642b9b3fccff751 (patch)
treef958fe5cf95e3a5285e3bb595da4f7cf27567d58 /django/utils/encoding.py
parent24b82cd201e21060fbc02117dc16d1702877a1f3 (diff)
downloaddjango-3bb6a4390c0a57da991fcb1c0642b9b3fccff751.tar.gz
Refs #27753 -- Favored force/smart_str() over force/smart_text().
Diffstat (limited to 'django/utils/encoding.py')
-rw-r--r--django/utils/encoding.py24
1 files changed, 7 insertions, 17 deletions
diff --git a/django/utils/encoding.py b/django/utils/encoding.py
index bb5aefcf7a..42adb45b8e 100644
--- a/django/utils/encoding.py
+++ b/django/utils/encoding.py
@@ -16,7 +16,7 @@ class DjangoUnicodeDecodeError(UnicodeDecodeError):
return '%s. You passed in %r (%s)' % (super().__str__(), self.obj, type(self.obj))
-def smart_text(s, encoding='utf-8', strings_only=False, errors='strict'):
+def smart_str(s, encoding='utf-8', strings_only=False, errors='strict'):
"""
Return a string representing 's'. Treat bytestrings using the 'encoding'
codec.
@@ -26,7 +26,7 @@ def smart_text(s, encoding='utf-8', strings_only=False, errors='strict'):
if isinstance(s, Promise):
# The input is the result of a gettext_lazy() call.
return s
- return force_text(s, encoding, strings_only, errors)
+ return force_str(s, encoding, strings_only, errors)
_PROTECTED_TYPES = (
@@ -38,14 +38,14 @@ def is_protected_type(obj):
"""Determine if the object instance is of a protected type.
Objects of protected types are preserved as-is when passed to
- force_text(strings_only=True).
+ force_str(strings_only=True).
"""
return isinstance(obj, _PROTECTED_TYPES)
-def force_text(s, encoding='utf-8', strings_only=False, errors='strict'):
+def force_str(s, encoding='utf-8', strings_only=False, errors='strict'):
"""
- Similar to smart_text, except that lazy instances are resolved to
+ Similar to smart_str(), except that lazy instances are resolved to
strings, rather than kept as lazy objects.
If strings_only is True, don't convert (some) non-string-like objects.
@@ -97,18 +97,8 @@ def force_bytes(s, encoding='utf-8', strings_only=False, errors='strict'):
return str(s).encode(encoding, errors)
-smart_str = smart_text
-force_str = force_text
-
-smart_str.__doc__ = """
-Apply smart_text in Python 3 and smart_bytes in Python 2.
-
-This is suitable for writing to sys.stdout (for instance).
-"""
-
-force_str.__doc__ = """
-Apply force_text in Python 3 and force_bytes in Python 2.
-"""
+smart_text = smart_str
+force_text = force_str
def iri_to_uri(iri):