Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
51cde873
Kaydet (Commit)
51cde873
authored
Ara 27, 2016
tarafından
Tim Graham
Kaydeden (comit)
GitHub
Ara 27, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #27648 -- Deprecated (iLmsu) regex groups in url() patterns.
üst
544b2ef2
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
60 additions
and
9 deletions
+60
-9
regex_helper.py
django/utils/regex_helper.py
+11
-4
deprecation.txt
docs/internals/deprecation.txt
+3
-0
1.11.txt
docs/releases/1.11.txt
+7
-0
test_deprecated.py
tests/urlpatterns_reverse/test_deprecated.py
+33
-0
tests.py
tests/urlpatterns_reverse/tests.py
+0
-2
urls.py
tests/urlpatterns_reverse/urls.py
+0
-2
test_regex_helper.py
tests/utils_tests/test_regex_helper.py
+6
-1
No files found.
django/utils/regex_helper.py
Dosyayı görüntüle @
51cde873
...
...
@@ -7,7 +7,10 @@ should be good enough for a large class of URLS, however.
"""
from
__future__
import
unicode_literals
import
warnings
from
django.utils
import
six
from
django.utils.deprecation
import
RemovedInDjango21Warning
from
django.utils.six.moves
import
zip
# Mapping of an escape character to a representative of that class. So, e.g.,
...
...
@@ -59,9 +62,7 @@ def normalize(pattern):
(3) Select the first (essentially an arbitrary) element from any character
class. Select an arbitrary character for any unordered class (e.g. '.'
or '\w') in the pattern.
(4) Ignore comments, look-ahead and look-behind assertions, and any of the
reg-exp flags that won't change what we construct ("iLmsu"). "(?x)" is
an error, however.
(4) Ignore look-ahead and look-behind assertions.
(5) Raise an error on any disjunctive ('|') constructs.
Django's URLs for forward resolving are either all positional arguments or
...
...
@@ -128,10 +129,16 @@ def normalize(pattern):
walk_to_end
(
ch
,
pattern_iter
)
else
:
ch
,
escaped
=
next
(
pattern_iter
)
if
ch
in
"iLmsu#!=<"
:
if
ch
in
'!=<'
:
# All of these are ignorable. Walk to the end of the
# group.
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
==
':'
:
# Non-capturing group
non_capturing_groups
.
append
(
len
(
result
))
...
...
docs/internals/deprecation.txt
Dosyayı görüntüle @
51cde873
...
...
@@ -48,6 +48,9 @@ details on these changes.
* The ``Model._meta.has_auto_field`` attribute will be removed.
* Support for regular expression groups with ``iLmsu#`` in ``url()`` will be
removed.
.. _deprecation-removed-in-2.0:
2.0
...
...
docs/releases/1.11.txt
Dosyayı görüntüle @
51cde873
...
...
@@ -747,3 +747,10 @@ Miscellaneous
* ``Model._meta.has_auto_field`` is deprecated in favor of checking if
``Model._meta.auto_field is not None``.
* Using regular expression groups with ``iLmsu#`` in ``url()`` is deprecated.
The only group that's useful is ``(?i)`` for case-insensitive URLs, however,
case-insensitive URLs aren't a good practice because they create multiple
entries for search engines, for example. An alternative solution could be to
create a :data:`~django.conf.urls.handler404` that looks for uppercase
characters in the URL and redirects to a lowercase equivalent.
tests/urlpatterns_reverse/test_deprecated.py
0 → 100644
Dosyayı görüntüle @
51cde873
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.'
)
tests/urlpatterns_reverse/tests.py
Dosyayı görüntüle @
51cde873
...
...
@@ -198,9 +198,7 @@ test_data = (
(
'repeats'
,
'/repeats/a/'
,
[],
{}),
(
'repeats2'
,
'/repeats/aa/'
,
[],
{}),
(
'repeats3'
,
'/repeats/aa/'
,
[],
{}),
(
'insensitive'
,
'/CaseInsensitive/fred'
,
[
'fred'
],
{}),
(
'test'
,
'/test/1'
,
[],
{}),
(
'test2'
,
'/test/2'
,
[],
{}),
(
'inner-nothing'
,
'/outer/42/'
,
[],
{
'outer'
:
'42'
}),
(
'inner-nothing'
,
'/outer/42/'
,
[
'42'
],
{}),
(
'inner-nothing'
,
NoReverseMatch
,
[
'foo'
],
{}),
...
...
tests/urlpatterns_reverse/urls.py
Dosyayı görüntüle @
51cde873
...
...
@@ -49,9 +49,7 @@ urlpatterns = [
url
(
r'^repeats/a{1,2}/$'
,
empty_view
,
name
=
"repeats"
),
url
(
r'^repeats/a{2,4}/$'
,
empty_view
,
name
=
"repeats2"
),
url
(
r'^repeats/a{2}/$'
,
empty_view
,
name
=
"repeats3"
),
url
(
r'^(?i)CaseInsensitive/(\w+)'
,
empty_view
,
name
=
"insensitive"
),
url
(
r'^test/1/?'
,
empty_view
,
name
=
"test"
),
url
(
r'^(?i)test/2/?$'
,
empty_view
,
name
=
"test2"
),
url
(
r'^outer/(?P<outer>[0-9]+)/'
,
include
(
'urlpatterns_reverse.included_urls'
)),
url
(
r'^outer-no-kwargs/([0-9]+)/'
,
include
(
'urlpatterns_reverse.included_no_kwargs_urls'
)),
url
(
''
,
include
(
'urlpatterns_reverse.extra_urls'
)),
...
...
tests/utils_tests/test_regex_helper.py
Dosyayı görüntüle @
51cde873
from
__future__
import
unicode_literals
import
unittest
import
warnings
from
django.utils
import
regex_helper
...
...
@@ -27,8 +28,12 @@ class NormalizeTests(unittest.TestCase):
def
test_group_ignored
(
self
):
pattern
=
r"(?i)(?L)(?m)(?s)(?u)(?#)"
expected
=
[(
''
,
[])]
result
=
regex_helper
.
normalize
(
pattern
)
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
):
pattern
=
r"(?:non-capturing)"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment