Refs #27753 -- Removed django.utils.text.unescape_entities() per deprecation timeline.

This commit is contained in:
Mariusz Felisiak 2021-01-07 08:09:04 +01:00
parent 5e33ec80d1
commit 157ab32f34
3 changed files with 3 additions and 40 deletions

View File

@ -1,11 +1,9 @@
import html.entities import html.entities
import re import re
import unicodedata import unicodedata
import warnings
from gzip import GzipFile from gzip import GzipFile
from io import BytesIO from io import BytesIO
from django.utils.deprecation import RemovedInDjango40Warning
from django.utils.functional import SimpleLazyObject, keep_lazy_text, lazy from django.utils.functional import SimpleLazyObject, keep_lazy_text, lazy
from django.utils.regex_helper import _lazy_re_compile from django.utils.regex_helper import _lazy_re_compile
from django.utils.translation import gettext as _, gettext_lazy, pgettext from django.utils.translation import gettext as _, gettext_lazy, pgettext
@ -359,16 +357,6 @@ def _replace_entity(match):
_entity_re = _lazy_re_compile(r"&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));") _entity_re = _lazy_re_compile(r"&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));")
@keep_lazy_text
def unescape_entities(text):
warnings.warn(
'django.utils.text.unescape_entities() is deprecated in favor of '
'html.unescape().',
RemovedInDjango40Warning, stacklevel=2,
)
return _entity_re.sub(_replace_entity, str(text))
@keep_lazy_text @keep_lazy_text
def unescape_string_literal(s): def unescape_string_literal(s):
r""" r"""

View File

@ -260,6 +260,8 @@ to remove usage of these features.
* ``alias=None`` is required in the signature of * ``alias=None`` is required in the signature of
``django.db.models.Expression.get_group_by_cols()`` subclasses. ``django.db.models.Expression.get_group_by_cols()`` subclasses.
* ``django.utils.text.unescape_entities()`` is removed.
See :ref:`deprecated-features-3.1` for details on these changes, including how See :ref:`deprecated-features-3.1` for details on these changes, including how
to remove usage of these features. to remove usage of these features.

View File

@ -1,9 +1,8 @@
import json import json
import sys import sys
from django.test import SimpleTestCase, ignore_warnings from django.test import SimpleTestCase
from django.utils import text from django.utils import text
from django.utils.deprecation import RemovedInDjango40Warning
from django.utils.functional import lazystr from django.utils.functional import lazystr
from django.utils.text import format_lazy from django.utils.text import format_lazy
from django.utils.translation import gettext_lazy, override from django.utils.translation import gettext_lazy, override
@ -213,32 +212,6 @@ class TestUtilsText(SimpleTestCase):
with self.subTest('intern'): with self.subTest('intern'):
self.assertEqual(sys.intern(text.slugify('a')), 'a') self.assertEqual(sys.intern(text.slugify('a')), 'a')
@ignore_warnings(category=RemovedInDjango40Warning)
def test_unescape_entities(self):
items = [
('', ''),
('foo', 'foo'),
('&', '&'),
('&am;', '&am;'),
('&', '&'),
('&#xk;', '&#xk;'),
('&', '&'),
('foo & bar', 'foo & bar'),
('foo & bar', 'foo & bar'),
]
for value, output in items:
with self.subTest(value=value):
self.assertEqual(text.unescape_entities(value), output)
self.assertEqual(text.unescape_entities(lazystr(value)), output)
def test_unescape_entities_deprecated(self):
msg = (
'django.utils.text.unescape_entities() is deprecated in favor of '
'html.unescape().'
)
with self.assertWarnsMessage(RemovedInDjango40Warning, msg):
text.unescape_entities('foo')
def test_unescape_string_literal(self): def test_unescape_string_literal(self):
items = [ items = [
('"abc"', 'abc'), ('"abc"', 'abc'),