summaryrefslogtreecommitdiff
path: root/django/utils/encoding.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/utils/encoding.py')
-rw-r--r--django/utils/encoding.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/django/utils/encoding.py b/django/utils/encoding.py
index ad4473df6a..ee67df30ea 100644
--- a/django/utils/encoding.py
+++ b/django/utils/encoding.py
@@ -38,6 +38,7 @@ def python_2_unicode_compatible(klass):
klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
return klass
+
def smart_text(s, encoding='utf-8', strings_only=False, errors='strict'):
"""
Returns a text object representing 's' -- unicode on Python 2 and str on
@@ -50,6 +51,7 @@ def smart_text(s, encoding='utf-8', strings_only=False, errors='strict'):
return s
return force_text(s, encoding, strings_only, errors)
+
def is_protected_type(obj):
"""Determine if the object instance is of a protected type.
@@ -59,6 +61,7 @@ def is_protected_type(obj):
return isinstance(obj, six.integer_types + (type(None), float, Decimal,
datetime.datetime, datetime.date, datetime.time))
+
def force_text(s, encoding='utf-8', strings_only=False, errors='strict'):
"""
Similar to smart_text, except that lazy instances are resolved to
@@ -100,6 +103,7 @@ def force_text(s, encoding='utf-8', strings_only=False, errors='strict'):
errors) for arg in s])
return s
+
def smart_bytes(s, encoding='utf-8', strings_only=False, errors='strict'):
"""
Returns a bytestring version of 's', encoded as specified in 'encoding'.
@@ -168,6 +172,7 @@ force_str.__doc__ = """
Apply force_text in Python 3 and force_bytes in Python 2.
"""
+
def iri_to_uri(iri):
"""
Convert an Internationalized Resource Identifier (IRI) portion to a URI
@@ -195,6 +200,7 @@ def iri_to_uri(iri):
return iri
return quote(force_bytes(iri), safe=b"/#%[]=:;$&()+,!?*@'~")
+
def filepath_to_uri(path):
"""Convert a file system path to a URI portion that is suitable for
inclusion in a URL.
@@ -214,6 +220,7 @@ def filepath_to_uri(path):
# some flexibility for hardcoding separators.
return quote(force_bytes(path).replace(b"\\", b"/"), safe=b"/~!*()'")
+
def get_system_encoding():
"""
The encoding of the default system locale but falls back to the given