1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Refs #27753 -- Favored force/smart_str() over force/smart_text().

This commit is contained in:
Aymeric Augustin
2017-01-26 10:08:08 +01:00
committed by Tim Graham
parent 24b82cd201
commit 3bb6a4390c
21 changed files with 84 additions and 101 deletions

View File

@@ -191,7 +191,7 @@ The functions defined in this module share the following properties:
.. module:: django.utils.encoding
:synopsis: A series of helper functions to manage character encoding.
.. function:: smart_text(s, encoding='utf-8', strings_only=False, errors='strict')
.. function:: smart_str(s, encoding='utf-8', strings_only=False, errors='strict')
Returns a ``str`` object representing arbitrary object ``s``. Treats
bytestrings using the ``encoding`` codec.
@@ -204,11 +204,11 @@ The functions defined in this module share the following properties:
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)``.
.. function:: force_text(s, encoding='utf-8', strings_only=False, errors='strict')
.. function:: 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
@@ -230,22 +230,15 @@ The functions defined in this module share the following properties:
If ``strings_only`` is ``True``, don't convert (some) non-string-like
objects.
.. function:: smart_str(s, encoding='utf-8', strings_only=False, errors='strict')
.. function:: smart_text(s, encoding='utf-8', strings_only=False, errors='strict')
Alias of :func:`smart_text`. This function returns a ``str`` or a lazy
string.
Alias of :func:`force_str` for backwards compatibility, especially in code
that supports Python 2.
For instance, this is suitable for writing to :data:`sys.stdout`.
.. function:: force_text(s, encoding='utf-8', strings_only=False, errors='strict')
Alias of :func:`smart_bytes` on Python 2 (in older versions of Django that
support it).
.. function:: force_str(s, encoding='utf-8', strings_only=False, errors='strict')
Alias of :func:`force_text`. This function always returns a ``str``.
Alias of :func:`force_bytes` on Python 2 (in older versions of Django that
support it).
Alias of :func:`force_str` for backwards compatibility, especially in code
that supports Python 2.
.. function:: iri_to_uri(iri)
@@ -622,7 +615,7 @@ escaping HTML.
interpolation, some of the formatting options provided by ``str.format()``
(e.g. number formatting) will not work, since all arguments are passed
through :func:`conditional_escape` which (ultimately) calls
:func:`~django.utils.encoding.force_text` on the values.
:func:`~django.utils.encoding.force_str` on the values.
.. function:: format_html_join(sep, format_string, args_generator)