mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Refs #27753 -- Removed django.utils.encoding.force_text() and smart_text() per deprecation timeline.
This commit is contained in:
parent
88ed1c8d08
commit
810f037b29
@ -1,11 +1,9 @@
|
||||
import codecs
|
||||
import datetime
|
||||
import locale
|
||||
import warnings
|
||||
from decimal import Decimal
|
||||
from urllib.parse import quote
|
||||
|
||||
from django.utils.deprecation import RemovedInDjango40Warning
|
||||
from django.utils.functional import Promise
|
||||
|
||||
|
||||
@ -99,22 +97,6 @@ def force_bytes(s, encoding='utf-8', strings_only=False, errors='strict'):
|
||||
return str(s).encode(encoding, errors)
|
||||
|
||||
|
||||
def smart_text(s, encoding='utf-8', strings_only=False, errors='strict'):
|
||||
warnings.warn(
|
||||
'smart_text() is deprecated in favor of smart_str().',
|
||||
RemovedInDjango40Warning, stacklevel=2,
|
||||
)
|
||||
return smart_str(s, encoding, strings_only, errors)
|
||||
|
||||
|
||||
def force_text(s, encoding='utf-8', strings_only=False, errors='strict'):
|
||||
warnings.warn(
|
||||
'force_text() is deprecated in favor of force_str().',
|
||||
RemovedInDjango40Warning, stacklevel=2,
|
||||
)
|
||||
return force_str(s, encoding, strings_only, errors)
|
||||
|
||||
|
||||
def iri_to_uri(iri):
|
||||
"""
|
||||
Convert an Internationalized Resource Identifier (IRI) portion to a URI
|
||||
|
@ -248,20 +248,6 @@ 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_text(s, encoding='utf-8', strings_only=False, errors='strict')
|
||||
|
||||
.. deprecated:: 3.0
|
||||
|
||||
Alias of :func:`force_str` for backwards compatibility, especially in code
|
||||
that supports Python 2.
|
||||
|
||||
.. function:: force_text(s, encoding='utf-8', strings_only=False, errors='strict')
|
||||
|
||||
.. deprecated:: 3.0
|
||||
|
||||
Alias of :func:`force_str` for backwards compatibility, especially in code
|
||||
that supports Python 2.
|
||||
|
||||
.. function:: iri_to_uri(iri)
|
||||
|
||||
Convert an Internationalized Resource Identifier (IRI) portion to a URI
|
||||
|
@ -249,6 +249,8 @@ to remove usage of these features.
|
||||
* ``django.utils.http.urlquote()``, ``urlquote_plus()``, ``urlunquote()``, and
|
||||
``urlunquote_plus()`` are removed.
|
||||
|
||||
* ``django.utils.encoding.force_text()`` and ``smart_text()`` are removed.
|
||||
|
||||
See :ref:`deprecated-features-3.1` for details on these changes, including how
|
||||
to remove usage of these features.
|
||||
|
||||
|
@ -1,24 +0,0 @@
|
||||
from django.test import SimpleTestCase, ignore_warnings
|
||||
from django.utils.deprecation import RemovedInDjango40Warning
|
||||
from django.utils.encoding import force_text, smart_text
|
||||
from django.utils.functional import SimpleLazyObject
|
||||
from django.utils.translation import gettext_lazy
|
||||
|
||||
|
||||
@ignore_warnings(category=RemovedInDjango40Warning)
|
||||
class TestDeprecatedEncodingUtils(SimpleTestCase):
|
||||
|
||||
def test_force_text(self):
|
||||
s = SimpleLazyObject(lambda: 'x')
|
||||
self.assertIs(type(force_text(s)), str)
|
||||
|
||||
def test_smart_text(self):
|
||||
class Test:
|
||||
def __str__(self):
|
||||
return 'ŠĐĆŽćžšđ'
|
||||
|
||||
lazy_func = gettext_lazy('x')
|
||||
self.assertIs(smart_text(lazy_func), lazy_func)
|
||||
self.assertEqual(smart_text(Test()), '\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111')
|
||||
self.assertEqual(smart_text(1), '1')
|
||||
self.assertEqual(smart_text('foo'), 'foo')
|
Loading…
Reference in New Issue
Block a user