Refs #27648 -- Removed support for (iLmsu) regex groups in url() patterns.

Per deprecation timeline.
This commit is contained in:
Tim Graham 2017-09-02 21:16:09 -04:00
parent 5bcca2a056
commit ba42456c2e
4 changed files with 2 additions and 54 deletions

View File

@ -5,10 +5,6 @@ Used internally by Django and not intended for external use.
This is not, and is not intended to be, a complete reg-exp decompiler. It This is not, and is not intended to be, a complete reg-exp decompiler. It
should be good enough for a large class of URLS, however. should be good enough for a large class of URLS, however.
""" """
import warnings
from django.utils.deprecation import RemovedInDjango21Warning
# Mapping of an escape character to a representative of that class. So, e.g., # Mapping of an escape character to a representative of that class. So, e.g.,
# "\w" is replaced by "x" in a reverse URL. A value of None means to ignore # "\w" is replaced by "x" in a reverse URL. A value of None means to ignore
# this sequence. Any missing key is mapped to itself. # this sequence. Any missing key is mapped to itself.
@ -121,12 +117,6 @@ def normalize(pattern):
# All of these are ignorable. Walk to the end of the # All of these are ignorable. Walk to the end of the
# group. # group.
walk_to_end(ch, pattern_iter) walk_to_end(ch, pattern_iter)
elif ch in 'iLmsu#':
warnings.warn(
'Using (?%s) in url() patterns is deprecated.' % ch,
RemovedInDjango21Warning
)
walk_to_end(ch, pattern_iter)
elif ch == ':': elif ch == ':':
# Non-capturing group # Non-capturing group
non_capturing_groups.append(len(result)) non_capturing_groups.append(len(result))

View File

@ -256,3 +256,5 @@ how to remove usage of these features.
``django.utils.cache.patch_response_headers()`` no longer set ETags. ``django.utils.cache.patch_response_headers()`` no longer set ETags.
* The ``Model._meta.has_auto_field`` attribute is removed. * The ``Model._meta.has_auto_field`` attribute is removed.
* Support for regular expression groups with ``iLmsu#`` in ``url()`` is removed.

View File

@ -1,33 +0,0 @@
import warnings
from django.conf.urls import url
from django.test import SimpleTestCase, override_settings
from django.urls import reverse
from .views import empty_view
urlpatterns = [
url(r'^(?i)CaseInsensitive/(\w+)', empty_view, name="insensitive"),
url(r'^(?i)test/2/?$', empty_view, name="test2"),
]
@override_settings(ROOT_URLCONF='urlpatterns_reverse.test_deprecated')
class URLPatternReverse(SimpleTestCase):
def test_urlpattern_reverse(self):
test_data = (
('insensitive', '/CaseInsensitive/fred', ['fred'], {}),
('test2', '/test/2', [], {}),
)
with warnings.catch_warnings(record=True) as warns:
warnings.simplefilter('always')
warnings.filterwarnings(
'ignore', 'Flags not at the start',
DeprecationWarning, module='django.urls.resolvers'
)
for i, (name, expected, args, kwargs) in enumerate(test_data):
got = reverse(name, args=args, kwargs=kwargs)
self.assertEqual(got, expected)
msg = str(warns[i].message)
self.assertEqual(msg, 'Using (?i) in url() patterns is deprecated.')

View File

@ -1,5 +1,4 @@
import unittest import unittest
import warnings
from django.utils import regex_helper from django.utils import regex_helper
@ -23,16 +22,6 @@ class NormalizeTests(unittest.TestCase):
result = regex_helper.normalize(pattern) result = regex_helper.normalize(pattern)
self.assertEqual(result, expected) self.assertEqual(result, expected)
def test_group_ignored(self):
pattern = r"(?i)(?L)(?m)(?s)(?u)(?#)"
expected = [('', [])]
with warnings.catch_warnings(record=True) as warns:
warnings.simplefilter('always')
result = regex_helper.normalize(pattern)
self.assertEqual(result, expected)
for i, char in enumerate('iLmsu#'):
self.assertEqual(str(warns[i].message), 'Using (?%s) in url() patterns is deprecated.' % char)
def test_group_noncapturing(self): def test_group_noncapturing(self):
pattern = r"(?:non-capturing)" pattern = r"(?:non-capturing)"
expected = [('non-capturing', [])] expected = [('non-capturing', [])]