diff --git a/docs/intro/overview.txt b/docs/intro/overview.txt index 42d80f66cd2..685666f8cbf 100644 --- a/docs/intro/overview.txt +++ b/docs/intro/overview.txt @@ -187,9 +187,9 @@ example above:: from django.conf.urls import url urlpatterns = [ - url(r'^articles/(\d{4})/$', 'news.views.year_archive'), - url(r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'), - url(r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'), + url(r'^articles/([0-9]{4})/$', 'news.views.year_archive'), + url(r'^articles/([0-9]{4})/([0-9]{2})/$', 'news.views.month_archive'), + url(r'^articles/([0-9]{4})/([0-9]{2})/([0-9]+)/$', 'news.views.article_detail'), ] The code above maps URLs, as simple `regular expressions`_, to the location of diff --git a/docs/intro/tutorial03.txt b/docs/intro/tutorial03.txt index 3d4f65a720d..1d25a58711c 100644 --- a/docs/intro/tutorial03.txt +++ b/docs/intro/tutorial03.txt @@ -215,11 +215,11 @@ Wire these new views into the ``polls.urls`` module by adding the following # ex: /polls/ url(r'^$', views.index, name='index'), # ex: /polls/5/ - url(r'^(?P\d+)/$', views.detail, name='detail'), + url(r'^(?P[0-9]+)/$', views.detail, name='detail'), # ex: /polls/5/results/ - url(r'^(?P\d+)/results/$', views.results, name='results'), + url(r'^(?P[0-9]+)/results/$', views.results, name='results'), # ex: /polls/5/vote/ - url(r'^(?P\d+)/vote/$', views.vote, name='vote'), + url(r'^(?P[0-9]+)/vote/$', views.vote, name='vote'), ] Take a look in your browser, at "/polls/34/". It'll run the ``detail()`` @@ -251,15 +251,15 @@ Here's what happens if a user goes to "/polls/34/" in this system: * Then, Django will strip off the matching text (``"polls/"``) and send the remaining text -- ``"34/"`` -- to the 'polls.urls' URLconf for - further processing which matches ``r'^(?P\d+)/$'`` resulting in a + further processing which matches ``r'^(?P[0-9]+)/$'`` resulting in a call to the ``detail()`` view like so:: detail(request=, question_id='34') -The ``question_id='34'`` part comes from ``(?P\d+)``. Using parentheses +The ``question_id='34'`` part comes from ``(?P[0-9]+)``. Using parentheses around a pattern "captures" the text matched by that pattern and sends it as an argument to the view function; ``?P`` defines the name that will -be used to identify the matched pattern; and ``\d+`` is a regular expression to +be used to identify the matched pattern; and ``[0-9]+`` is a regular expression to match a sequence of digits (i.e., a number). Because the URL patterns are regular expressions, there really is no limit on @@ -554,7 +554,7 @@ defined below:: ... # the 'name' value as called by the {% url %} template tag - url(r'^(?P\d+)/$', views.detail, name='detail'), + url(r'^(?P[0-9]+)/$', views.detail, name='detail'), ... If you want to change the URL of the polls detail view to something else, @@ -563,7 +563,7 @@ template (or templates) you would change it in ``polls/urls.py``:: ... # added the word 'specifics' - url(r'^specifics/(?P\d+)/$', views.detail, name='detail'), + url(r'^specifics/(?P[0-9]+)/$', views.detail, name='detail'), ... Namespacing URL names diff --git a/docs/intro/tutorial04.txt b/docs/intro/tutorial04.txt index 63d12d1a688..5b46dc0bb86 100644 --- a/docs/intro/tutorial04.txt +++ b/docs/intro/tutorial04.txt @@ -61,7 +61,7 @@ created a URLconf for the polls application that includes this line: .. snippet:: :filename: polls/urls.py - url(r'^(?P\d+)/vote/$', views.vote, name='vote'), + url(r'^(?P[0-9]+)/vote/$', views.vote, name='vote'), We also created a dummy implementation of the ``vote()`` function. Let's create a real version. Add the following to ``polls/views.py``: @@ -228,9 +228,9 @@ First, open the ``polls/urls.py`` URLconf and change it like so: urlpatterns = [ url(r'^$', views.IndexView.as_view(), name='index'), - url(r'^(?P\d+)/$', views.DetailView.as_view(), name='detail'), - url(r'^(?P\d+)/results/$', views.ResultsView.as_view(), name='results'), - url(r'^(?P\d+)/vote/$', views.vote, name='vote'), + url(r'^(?P[0-9]+)/$', views.DetailView.as_view(), name='detail'), + url(r'^(?P[0-9]+)/results/$', views.ResultsView.as_view(), name='results'), + url(r'^(?P[0-9]+)/vote/$', views.vote, name='vote'), ] Amend views diff --git a/docs/ref/class-based-views/base.txt b/docs/ref/class-based-views/base.txt index e8f5271e979..0e43f5b4b3c 100644 --- a/docs/ref/class-based-views/base.txt +++ b/docs/ref/class-based-views/base.txt @@ -198,8 +198,8 @@ RedirectView from article.views import ArticleCounterRedirectView, ArticleDetail urlpatterns = [ - url(r'^counter/(?P\d+)/$', ArticleCounterRedirectView.as_view(), name='article-counter'), - url(r'^details/(?P\d+)/$', ArticleDetail.as_view(), name='article-detail'), + url(r'^counter/(?P[0-9]+)/$', ArticleCounterRedirectView.as_view(), name='article-counter'), + url(r'^details/(?P[0-9]+)/$', ArticleDetail.as_view(), name='article-detail'), url(r'^go-to-django/$', RedirectView.as_view(url='http://djangoproject.com'), name='go-to-django'), ] diff --git a/docs/ref/class-based-views/generic-date-based.txt b/docs/ref/class-based-views/generic-date-based.txt index 9d6d447052a..ecaeddfeccb 100644 --- a/docs/ref/class-based-views/generic-date-based.txt +++ b/docs/ref/class-based-views/generic-date-based.txt @@ -171,7 +171,7 @@ YearArchiveView from myapp.views import ArticleYearArchiveView urlpatterns = [ - url(r'^(?P\d{4})/$', + url(r'^(?P[0-9]{4})/$', ArticleYearArchiveView.as_view(), name="article_year_archive"), ] @@ -267,11 +267,11 @@ MonthArchiveView urlpatterns = [ # Example: /2012/aug/ - url(r'^(?P\d{4})/(?P[-\w]+)/$', + url(r'^(?P[0-9]{4})/(?P[-\w]+)/$', ArticleMonthArchiveView.as_view(), name="archive_month"), # Example: /2012/08/ - url(r'^(?P\d{4})/(?P\d+)/$', + url(r'^(?P[0-9]{4})/(?P[0-9]+)/$', ArticleMonthArchiveView.as_view(month_format='%m'), name="archive_month_numeric"), ] @@ -361,7 +361,7 @@ WeekArchiveView urlpatterns = [ # Example: /2012/week/23/ - url(r'^(?P\d{4})/week/(?P\d+)/$', + url(r'^(?P[0-9]{4})/week/(?P[0-9]+)/$', ArticleWeekArchiveView.as_view(), name="archive_week"), ] @@ -475,7 +475,7 @@ DayArchiveView urlpatterns = [ # Example: /2012/nov/10/ - url(r'^(?P\d{4})/(?P[-\w]+)/(?P\d+)/$', + url(r'^(?P[0-9]{4})/(?P[-\w]+)/(?P[0-9]+)/$', ArticleDayArchiveView.as_view(), name="archive_day"), ] @@ -597,7 +597,7 @@ DateDetailView from django.views.generic.dates import DateDetailView urlpatterns = [ - url(r'^(?P\d+)/(?P[-\w]+)/(?P\d+)/(?P\d+)/$', + url(r'^(?P[0-9]+)/(?P[-\w]+)/(?P[0-9]+)/(?P[0-9]+)/$', DateDetailView.as_view(model=Article, date_field="pub_date"), name="archive_date_detail"), ] diff --git a/docs/ref/contrib/syndication.txt b/docs/ref/contrib/syndication.txt index b2ebf40e615..3310edd3431 100644 --- a/docs/ref/contrib/syndication.txt +++ b/docs/ref/contrib/syndication.txt @@ -217,7 +217,7 @@ The police beat feeds could be accessible via URLs like this: These can be matched with a :doc:`URLconf ` line such as:: - (r'^beats/(?P\d+)/rss/$', BeatFeed()), + (r'^beats/(?P[0-9]+)/rss/$', BeatFeed()), Like a view, the arguments in the URL are passed to the ``get_object()`` method along with the request object. diff --git a/docs/ref/forms/fields.txt b/docs/ref/forms/fields.txt index 10547a1664c..ec9ea3a85e5 100644 --- a/docs/ref/forms/fields.txt +++ b/docs/ref/forms/fields.txt @@ -930,10 +930,10 @@ Slightly complex built-in ``Field`` classes # Or define a different message for each field. fields = ( CharField(error_messages={'incomplete': 'Enter a country code.'}, - validators=[RegexValidator(r'^\d+$', 'Enter a valid country code.')]), + validators=[RegexValidator(r'^[0-9]+$', 'Enter a valid country code.')]), CharField(error_messages={'incomplete': 'Enter a phone number.'}, - validators=[RegexValidator(r'^\d+$', 'Enter a valid phone number.')]), - CharField(validators=[RegexValidator(r'^\d+$', 'Enter a valid extension.')], + validators=[RegexValidator(r'^[0-9]+$', 'Enter a valid phone number.')]), + CharField(validators=[RegexValidator(r'^[0-9]+$', 'Enter a valid extension.')], required=False), ) super(PhoneField, self).__init__( diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt index 2a93996d8d7..9bc7b841c7a 100644 --- a/docs/ref/models/instances.txt +++ b/docs/ref/models/instances.txt @@ -642,7 +642,7 @@ template tag and a high-level wrapper for the An example should make it clear how to use ``permalink()``. Suppose your URLconf contains a line such as:: - (r'^people/(\d+)/$', 'people.views.details'), + (r'^people/([0-9]+)/$', 'people.views.details'), ...your model could have a :meth:`~django.db.models.Model.get_absolute_url` method that looked like this:: @@ -655,7 +655,7 @@ method that looked like this:: Similarly, if you had a URLconf entry that looked like:: - (r'/archive/(?P\d{4})/(?P\d{2})/(?P\d{2})/$', archive_view) + (r'/archive/(?P[0-9]{4})/(?P[0-9]{2})/(?P[0-9]{2})/$', archive_view) ...you could reference this using ``permalink()`` as follows:: @@ -684,7 +684,7 @@ pattern tuple by a call to the ``url`` function):: from django.conf.urls import url - url(r'^people/(\d+)/$', 'blog_views.generic_detail', name='people_view'), + url(r'^people/([0-9]+)/$', 'blog_views.generic_detail', name='people_view'), ...and then using that name to perform the reverse URL resolution instead of the view name:: diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt index 6e9c703938d..a78fd495482 100644 --- a/docs/ref/templates/builtins.txt +++ b/docs/ref/templates/builtins.txt @@ -1000,7 +1000,7 @@ takes a client ID (here, ``client()`` is a method inside the views file .. code-block:: python - ('^client/(\d+)/$', 'app_views.client') + ('^client/([0-9]+)/$', 'app_views.client') If this app's URLconf is included into the project's URLconf under a path such as this: diff --git a/docs/ref/urls.txt b/docs/ref/urls.txt index 47ef488afc0..be09777b409 100644 --- a/docs/ref/urls.txt +++ b/docs/ref/urls.txt @@ -23,9 +23,9 @@ URLconf from the :doc:`Django overview `:: from django.conf.urls import patterns, url urlpatterns = patterns('', - url(r'^articles/(\d{4})/$', 'news.views.year_archive'), - url(r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'), - url(r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'), + url(r'^articles/([0-9]{4})/$', 'news.views.year_archive'), + url(r'^articles/([0-9]{4})/([0-9]{2})/$', 'news.views.month_archive'), + url(r'^articles/([0-9]{4})/([0-9]{2})/([0-9]+)/$', 'news.views.article_detail'), ) In this example, each view has a common prefix -- ``'news.views'``. @@ -38,9 +38,9 @@ With this in mind, the above example can be written more concisely as:: from django.conf.urls import patterns, url urlpatterns = patterns('news.views', - url(r'^articles/(\d{4})/$', 'year_archive'), - url(r'^articles/(\d{4})/(\d{2})/$', 'month_archive'), - url(r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'article_detail'), + url(r'^articles/([0-9]{4})/$', 'year_archive'), + url(r'^articles/([0-9]{4})/([0-9]{2})/$', 'month_archive'), + url(r'^articles/([0-9]{4})/([0-9]{2})/([0-9]+)/$', 'article_detail'), ) Note that you don't put a trailing dot (``"."``) in the prefix. Django puts diff --git a/docs/topics/cache.txt b/docs/topics/cache.txt index feeaf37a47f..a5f9b3451cb 100644 --- a/docs/topics/cache.txt +++ b/docs/topics/cache.txt @@ -533,7 +533,7 @@ multiple URLs point at the same view, each URL will be cached separately. Continuing the ``my_view`` example, if your URLconf looks like this:: urlpatterns = [ - url(r'^foo/(\d{1,2})/$', my_view), + url(r'^foo/([0-9]{1,2})/$', my_view), ] then requests to ``/foo/1/`` and ``/foo/23/`` will be cached separately, as @@ -579,7 +579,7 @@ Doing so is easy: simply wrap the view function with ``cache_page`` when you refer to it in the URLconf. Here's the old URLconf from earlier:: urlpatterns = [ - url(r'^foo/(\d{1,2})/$', my_view), + url(r'^foo/([0-9]{1,2})/$', my_view), ] Here's the same thing, with ``my_view`` wrapped in ``cache_page``:: @@ -587,7 +587,7 @@ Here's the same thing, with ``my_view`` wrapped in ``cache_page``:: from django.views.decorators.cache import cache_page urlpatterns = [ - url(r'^foo/(\d{1,2})/$', cache_page(60 * 15)(my_view)), + url(r'^foo/([0-9]{1,2})/$', cache_page(60 * 15)(my_view)), ] .. templatetag:: cache diff --git a/docs/topics/class-based-views/generic-display.txt b/docs/topics/class-based-views/generic-display.txt index 98d2b79d325..54b75ce5571 100644 --- a/docs/topics/class-based-views/generic-display.txt +++ b/docs/topics/class-based-views/generic-display.txt @@ -401,7 +401,7 @@ custom view:: urlpatterns = [ #... - url(r'^authors/(?P\d+)/$', AuthorDetailView.as_view(), name='author-detail'), + url(r'^authors/(?P[0-9]+)/$', AuthorDetailView.as_view(), name='author-detail'), ] Then we'd write our new view -- ``get_object`` is the method that retrieves the diff --git a/docs/topics/class-based-views/generic-editing.txt b/docs/topics/class-based-views/generic-editing.txt index 2587c9426d4..74d19d53b1d 100644 --- a/docs/topics/class-based-views/generic-editing.txt +++ b/docs/topics/class-based-views/generic-editing.txt @@ -147,8 +147,8 @@ Finally, we hook these new views into the URLconf:: urlpatterns = [ # ... url(r'author/add/$', AuthorCreate.as_view(), name='author_add'), - url(r'author/(?P\d+)/$', AuthorUpdate.as_view(), name='author_update'), - url(r'author/(?P\d+)/delete/$', AuthorDelete.as_view(), name='author_delete'), + url(r'author/(?P[0-9]+)/$', AuthorUpdate.as_view(), name='author_update'), + url(r'author/(?P[0-9]+)/delete/$', AuthorDelete.as_view(), name='author_delete'), ] .. note:: diff --git a/docs/topics/class-based-views/mixins.txt b/docs/topics/class-based-views/mixins.txt index 00729f36f9d..40ba6150887 100644 --- a/docs/topics/class-based-views/mixins.txt +++ b/docs/topics/class-based-views/mixins.txt @@ -261,7 +261,7 @@ We can hook this into our URLs easily enough:: urlpatterns = [ #... - url(r'^author/(?P\d+)/interest/$', RecordInterest.as_view(), name='author-interest'), + url(r'^author/(?P[0-9]+)/interest/$', RecordInterest.as_view(), name='author-interest'), ] Note the ``pk`` named group, which diff --git a/docs/topics/http/urls.txt b/docs/topics/http/urls.txt index 05525cc7156..92ec4bb0e9d 100644 --- a/docs/topics/http/urls.txt +++ b/docs/topics/http/urls.txt @@ -76,9 +76,9 @@ Here's a sample URLconf:: urlpatterns = [ url(r'^articles/2003/$', 'news.views.special_case_2003'), - url(r'^articles/(\d{4})/$', 'news.views.year_archive'), - url(r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'), - url(r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'), + url(r'^articles/([0-9]{4})/$', 'news.views.year_archive'), + url(r'^articles/([0-9]{4})/([0-9]{2})/$', 'news.views.month_archive'), + url(r'^articles/([0-9]{4})/([0-9]{2})/([0-9]+)/$', 'news.views.article_detail'), ] Notes: @@ -133,9 +133,9 @@ Here's the above example URLconf, rewritten to use named groups:: urlpatterns = [ url(r'^articles/2003/$', 'news.views.special_case_2003'), - url(r'^articles/(?P\d{4})/$', 'news.views.year_archive'), - url(r'^articles/(?P\d{4})/(?P\d{2})/$', 'news.views.month_archive'), - url(r'^articles/(?P\d{4})/(?P\d{2})/(?P\d{2})/$', 'news.views.article_detail'), + url(r'^articles/(?P[0-9]{4})/$', 'news.views.year_archive'), + url(r'^articles/(?P[0-9]{4})/(?P[0-9]{2})/$', 'news.views.month_archive'), + url(r'^articles/(?P[0-9]{4})/(?P[0-9]{2})/(?P[0-9]{2})/$', 'news.views.article_detail'), ] This accomplishes exactly the same thing as the previous example, with one @@ -191,10 +191,10 @@ Each captured argument is sent to the view as a plain Python string, regardless of what sort of match the regular expression makes. For example, in this URLconf line:: - url(r'^articles/(?P\d{4})/$', 'news.views.year_archive'), + url(r'^articles/(?P[0-9]{4})/$', 'news.views.year_archive'), ...the ``year`` argument to ``news.views.year_archive()`` will be a string, not -an integer, even though the ``\d{4}`` will only match integer strings. +an integer, even though the ``[0-9]{4}`` will only match integer strings. Specifying defaults for view arguments ====================================== @@ -207,7 +207,7 @@ Here's an example URLconf and view:: urlpatterns = [ url(r'^blog/$', 'blog.views.page'), - url(r'^blog/page(?P\d+)/$', 'blog.views.page'), + url(r'^blog/page(?P[0-9]+)/$', 'blog.views.page'), ] # View (in blog/views.py) @@ -291,7 +291,7 @@ Another possibility is to include additional URL patterns by using a list of from django.conf.urls import include, url extra_patterns = [ - url(r'^reports/(?P\d+)/$', 'credit.views.report'), + url(r'^reports/(?P[0-9]+)/$', 'credit.views.report'), url(r'^charge/$', 'credit.views.charge'), ] @@ -377,7 +377,7 @@ For example:: from . import views urlpatterns = [ - url(r'^blog/(?P\d{4})/$', views.year_archive, {'foo': 'bar'}), + url(r'^blog/(?P[0-9]{4})/$', views.year_archive, {'foo': 'bar'}), ] In this example, for a request to ``/blog/2005/``, Django will call @@ -558,7 +558,7 @@ Consider again this URLconf entry:: urlpatterns = [ #... - url(r'^articles/(\d{4})/$', 'news.views.year_archive'), + url(r'^articles/([0-9]{4})/$', 'news.views.year_archive'), #... ] @@ -610,8 +610,8 @@ view:: from mysite.views import archive urlpatterns = [ - url(r'^archive/(\d{4})/$', archive), - url(r'^archive-summary/(\d{4})/$', archive, {'summary': True}), + url(r'^archive/([0-9]{4})/$', archive), + url(r'^archive-summary/([0-9]{4})/$', archive, {'summary': True}), ] This is completely valid, but it leads to problems when you try to do reverse @@ -631,8 +631,8 @@ Here's the above example, rewritten to use named URL patterns:: from mysite.views import archive urlpatterns = [ - url(r'^archive/(\d{4})/$', archive, name="full-archive"), - url(r'^archive-summary/(\d{4})/$', archive, {'summary': True}, name="arch-summary"), + url(r'^archive/([0-9]{4})/$', archive, name="full-archive"), + url(r'^archive-summary/([0-9]{4})/$', archive, {'summary': True}, name="arch-summary"), ] With these names in place (``full-archive`` and ``arch-summary``), you can diff --git a/tests/contenttypes_tests/urls.py b/tests/contenttypes_tests/urls.py index bf038c93dec..285a5a20685 100644 --- a/tests/contenttypes_tests/urls.py +++ b/tests/contenttypes_tests/urls.py @@ -4,5 +4,5 @@ from django.conf.urls import url from django.contrib.contenttypes import views urlpatterns = [ - url(r'^shortcut/(\d+)/(.*)/$', views.shortcut), + url(r'^shortcut/([0-9]+)/(.*)/$', views.shortcut), ] diff --git a/tests/fixtures_regress/tests.py b/tests/fixtures_regress/tests.py index 61fc66d9280..82929cfcb94 100644 --- a/tests/fixtures_regress/tests.py +++ b/tests/fixtures_regress/tests.py @@ -372,7 +372,7 @@ class TestFixtures(TestCase): # Get rid of artifacts like '000000002' to eliminate the differences # between different Python versions. - data = re.sub('0{6,}\d', '', data) + data = re.sub('0{6,}[0-9]', '', data) animals_data = sorted([ {"pk": 1, "model": "fixtures_regress.animal", "fields": {"count": 3, "weight": 1.2, "name": "Lion", "latin_name": "Panthera leo"}}, diff --git a/tests/forms_tests/tests/test_error_messages.py b/tests/forms_tests/tests/test_error_messages.py index 86f26df3bc9..0a2bc0a8bfa 100644 --- a/tests/forms_tests/tests/test_error_messages.py +++ b/tests/forms_tests/tests/test_error_messages.py @@ -118,7 +118,7 @@ class FormsErrorMessagesTestCase(TestCase, AssertFormErrorsMixin): 'min_length': 'LENGTH %(show_value)s, MIN LENGTH %(limit_value)s', 'max_length': 'LENGTH %(show_value)s, MAX LENGTH %(limit_value)s', } - f = RegexField(r'^\d+$', min_length=5, max_length=10, error_messages=e) + f = RegexField(r'^[0-9]+$', min_length=5, max_length=10, error_messages=e) self.assertFormErrors(['REQUIRED'], f.clean, '') self.assertFormErrors(['INVALID'], f.clean, 'abcde') self.assertFormErrors(['LENGTH 4, MIN LENGTH 5'], f.clean, '1234') diff --git a/tests/forms_tests/tests/test_fields.py b/tests/forms_tests/tests/test_fields.py index e6bb39a42ad..1a6286451e8 100644 --- a/tests/forms_tests/tests/test_fields.py +++ b/tests/forms_tests/tests/test_fields.py @@ -600,7 +600,7 @@ class FieldsTests(SimpleTestCase): # RegexField ################################################################## def test_regexfield_1(self): - f = RegexField('^\d[A-F]\d$') + f = RegexField('^[0-9][A-F][0-9]$') self.assertEqual('2A2', f.clean('2A2')) self.assertEqual('3F3', f.clean('3F3')) self.assertRaisesMessage(ValidationError, "'Enter a valid value.'", f.clean, '3G3') @@ -609,14 +609,14 @@ class FieldsTests(SimpleTestCase): self.assertRaisesMessage(ValidationError, "'This field is required.'", f.clean, '') def test_regexfield_2(self): - f = RegexField('^\d[A-F]\d$', required=False) + f = RegexField('^[0-9][A-F][0-9]$', required=False) self.assertEqual('2A2', f.clean('2A2')) self.assertEqual('3F3', f.clean('3F3')) self.assertRaisesMessage(ValidationError, "'Enter a valid value.'", f.clean, '3G3') self.assertEqual('', f.clean('')) def test_regexfield_3(self): - f = RegexField(re.compile('^\d[A-F]\d$')) + f = RegexField(re.compile('^[0-9][A-F][0-9]$')) self.assertEqual('2A2', f.clean('2A2')) self.assertEqual('3F3', f.clean('3F3')) self.assertRaisesMessage(ValidationError, "'Enter a valid value.'", f.clean, '3G3') @@ -624,13 +624,13 @@ class FieldsTests(SimpleTestCase): self.assertRaisesMessage(ValidationError, "'Enter a valid value.'", f.clean, '2A2 ') def test_regexfield_4(self): - f = RegexField('^\d\d\d\d$', error_message='Enter a four-digit number.') + f = RegexField('^[0-9][0-9][0-9][0-9]$', error_message='Enter a four-digit number.') self.assertEqual('1234', f.clean('1234')) self.assertRaisesMessage(ValidationError, "'Enter a four-digit number.'", f.clean, '123') self.assertRaisesMessage(ValidationError, "'Enter a four-digit number.'", f.clean, 'abcd') def test_regexfield_5(self): - f = RegexField('^\d+$', min_length=5, max_length=10) + f = RegexField('^[0-9]+$', min_length=5, max_length=10) self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 5 characters (it has 3).'", f.clean, '123') six.assertRaisesRegex(self, ValidationError, "'Ensure this value has at least 5 characters \(it has 3\)\.', u?'Enter a valid value\.'", f.clean, 'abc') self.assertEqual('12345', f.clean('12345')) @@ -648,7 +648,7 @@ class FieldsTests(SimpleTestCase): def test_change_regex_after_init(self): f = RegexField('^[a-z]+$') - f.regex = '^\d+$' + f.regex = '^[0-9]+$' self.assertEqual('1234', f.clean('1234')) self.assertRaisesMessage(ValidationError, "'Enter a valid value.'", f.clean, 'abcd') diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index 2db40ef55c4..051968d14f9 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -1918,7 +1918,7 @@ class FormsTestCase(TestCase): def __init__(self, *args, **kwargs): fields = ( CharField(label='Country Code', validators=[ - RegexValidator(r'^\+\d{1,2}$', message='Enter a valid country code.')]), + RegexValidator(r'^\+[0-9]{1,2}$', message='Enter a valid country code.')]), CharField(label='Phone Number'), CharField(label='Extension', error_messages={'incomplete': 'Enter an extension.'}), CharField(label='Label', required=False, help_text='E.g. home, work.'), diff --git a/tests/forms_tests/urls.py b/tests/forms_tests/urls.py index bd5bc582a3d..e4a91469b1e 100644 --- a/tests/forms_tests/urls.py +++ b/tests/forms_tests/urls.py @@ -4,5 +4,5 @@ from .views import ArticleFormView urlpatterns = [ - url(r'^model_form/(?P\d+)/$', ArticleFormView.as_view(), name="article_form"), + url(r'^model_form/(?P[0-9]+)/$', ArticleFormView.as_view(), name="article_form"), ] diff --git a/tests/generic_views/urls.py b/tests/generic_views/urls.py index 41417c6c490..84239159d1d 100644 --- a/tests/generic_views/urls.py +++ b/tests/generic_views/urls.py @@ -23,27 +23,27 @@ urlpatterns = [ # DetailView url(r'^detail/obj/$', views.ObjectDetail.as_view()), - url(r'^detail/artist/(?P\d+)/$', + url(r'^detail/artist/(?P[0-9]+)/$', views.ArtistDetail.as_view(), name="artist_detail"), - url(r'^detail/author/(?P\d+)/$', + url(r'^detail/author/(?P[0-9]+)/$', views.AuthorDetail.as_view(), name="author_detail"), - url(r'^detail/author/bycustompk/(?P\d+)/$', + url(r'^detail/author/bycustompk/(?P[0-9]+)/$', views.AuthorDetail.as_view(pk_url_kwarg='foo')), url(r'^detail/author/byslug/(?P[\w-]+)/$', views.AuthorDetail.as_view()), url(r'^detail/author/bycustomslug/(?P[\w-]+)/$', views.AuthorDetail.as_view(slug_url_kwarg='foo')), - url(r'^detail/author/(?P\d+)/template_name_suffix/$', + url(r'^detail/author/(?P[0-9]+)/template_name_suffix/$', views.AuthorDetail.as_view(template_name_suffix='_view')), - url(r'^detail/author/(?P\d+)/template_name/$', + url(r'^detail/author/(?P[0-9]+)/template_name/$', views.AuthorDetail.as_view(template_name='generic_views/about.html')), - url(r'^detail/author/(?P\d+)/context_object_name/$', + url(r'^detail/author/(?P[0-9]+)/context_object_name/$', views.AuthorDetail.as_view(context_object_name='thingy')), - url(r'^detail/author/(?P\d+)/dupe_context_object_name/$', + url(r'^detail/author/(?P[0-9]+)/dupe_context_object_name/$', views.AuthorDetail.as_view(context_object_name='object')), - url(r'^detail/page/(?P\d+)/field/$', + url(r'^detail/page/(?P[0-9]+)/field/$', views.PageDetail.as_view()), url(r'^detail/author/invalid/url/$', views.AuthorDetail.as_view()), @@ -51,7 +51,7 @@ urlpatterns = [ views.AuthorDetail.as_view(queryset=None)), url(r'^detail/nonmodel/1/$', views.NonModelDetail.as_view()), - url(r'^detail/doesnotexist/(?P\d+)/$', + url(r'^detail/doesnotexist/(?P[0-9]+)/$', views.ObjectDoesNotExistDetail.as_view()), # FormView url(r'^contact/$', @@ -60,7 +60,7 @@ urlpatterns = [ # Create/UpdateView url(r'^edit/artists/create/$', views.ArtistCreate.as_view()), - url(r'^edit/artists/(?P\d+)/update/$', + url(r'^edit/artists/(?P[0-9]+)/update/$', views.ArtistUpdate.as_view()), url(r'^edit/authors/create/naive/$', @@ -76,27 +76,27 @@ urlpatterns = [ url(r'^edit/authors/create/special/$', views.SpecializedAuthorCreate.as_view()), - url(r'^edit/author/(?P\d+)/update/naive/$', + url(r'^edit/author/(?P[0-9]+)/update/naive/$', views.NaiveAuthorUpdate.as_view()), - url(r'^edit/author/(?P\d+)/update/redirect/$', + url(r'^edit/author/(?P[0-9]+)/update/redirect/$', views.NaiveAuthorUpdate.as_view(success_url='/edit/authors/create/')), - url(r'^edit/author/(?P\d+)/update/interpolate_redirect/$', + url(r'^edit/author/(?P[0-9]+)/update/interpolate_redirect/$', views.NaiveAuthorUpdate.as_view(success_url='/edit/author/%(id)d/update/')), - url(r'^edit/author/(?P\d+)/update/$', + url(r'^edit/author/(?P[0-9]+)/update/$', views.AuthorUpdate.as_view()), url(r'^edit/author/update/$', views.OneAuthorUpdate.as_view()), - url(r'^edit/author/(?P\d+)/update/special/$', + url(r'^edit/author/(?P[0-9]+)/update/special/$', views.SpecializedAuthorUpdate.as_view()), - url(r'^edit/author/(?P\d+)/delete/naive/$', + url(r'^edit/author/(?P[0-9]+)/delete/naive/$', views.NaiveAuthorDelete.as_view()), - url(r'^edit/author/(?P\d+)/delete/redirect/$', + url(r'^edit/author/(?P[0-9]+)/delete/redirect/$', views.NaiveAuthorDelete.as_view(success_url='/edit/authors/create/')), - url(r'^edit/author/(?P\d+)/delete/interpolate_redirect/$', + url(r'^edit/author/(?P[0-9]+)/delete/interpolate_redirect/$', views.NaiveAuthorDelete.as_view(success_url='/edit/authors/create/?deleted=%(id)s')), - url(r'^edit/author/(?P\d+)/delete/$', + url(r'^edit/author/(?P[0-9]+)/delete/$', views.AuthorDelete.as_view()), - url(r'^edit/author/(?P\d+)/delete/special/$', + url(r'^edit/author/(?P[0-9]+)/delete/special/$', views.SpecializedAuthorDelete.as_view()), # ArchiveIndexView @@ -134,7 +134,7 @@ urlpatterns = [ name="authors_list"), url(r'^list/authors/paginated/$', views.AuthorList.as_view(paginate_by=30)), - url(r'^list/authors/paginated/(?P\d+)/$', + url(r'^list/authors/paginated/(?P[0-9]+)/$', views.AuthorList.as_view(paginate_by=30)), url(r'^list/authors/paginated-orphaned/$', views.AuthorList.as_view(paginate_by=30, paginate_orphans=2)), @@ -162,71 +162,71 @@ urlpatterns = [ # YearArchiveView # Mixing keyword and positional captures below is intentional; the views # ought to be able to accept either. - url(r'^dates/books/(?P\d{4})/$', + url(r'^dates/books/(?P[0-9]{4})/$', views.BookYearArchive.as_view()), - url(r'^dates/books/(?P\d{4})/make_object_list/$', + url(r'^dates/books/(?P[0-9]{4})/make_object_list/$', views.BookYearArchive.as_view(make_object_list=True)), - url(r'^dates/books/(?P\d{4})/allow_empty/$', + url(r'^dates/books/(?P[0-9]{4})/allow_empty/$', views.BookYearArchive.as_view(allow_empty=True)), - url(r'^dates/books/(?P\d{4})/allow_future/$', + url(r'^dates/books/(?P[0-9]{4})/allow_future/$', views.BookYearArchive.as_view(allow_future=True)), - url(r'^dates/books/(?P\d{4})/paginated/$', + url(r'^dates/books/(?P[0-9]{4})/paginated/$', views.BookYearArchive.as_view(make_object_list=True, paginate_by=30)), url(r'^dates/books/no_year/$', views.BookYearArchive.as_view()), - url(r'^dates/books/(?P\d{4})/reverse/$', + url(r'^dates/books/(?P[0-9]{4})/reverse/$', views.BookYearArchive.as_view(queryset=models.Book.objects.order_by('pubdate'))), - url(r'^dates/booksignings/(?P\d{4})/$', + url(r'^dates/booksignings/(?P[0-9]{4})/$', views.BookSigningYearArchive.as_view()), # MonthArchiveView - url(r'^dates/books/(?P\d{4})/(?P[a-z]{3})/$', + url(r'^dates/books/(?P[0-9]{4})/(?P[a-z]{3})/$', views.BookMonthArchive.as_view()), - url(r'^dates/books/(?P\d{4})/(?P\d{1,2})/$', + url(r'^dates/books/(?P[0-9]{4})/(?P[0-9]{1,2})/$', views.BookMonthArchive.as_view(month_format='%m')), - url(r'^dates/books/(?P\d{4})/(?P[a-z]{3})/allow_empty/$', + url(r'^dates/books/(?P[0-9]{4})/(?P[a-z]{3})/allow_empty/$', views.BookMonthArchive.as_view(allow_empty=True)), - url(r'^dates/books/(?P\d{4})/(?P[a-z]{3})/allow_future/$', + url(r'^dates/books/(?P[0-9]{4})/(?P[a-z]{3})/allow_future/$', views.BookMonthArchive.as_view(allow_future=True)), - url(r'^dates/books/(?P\d{4})/(?P[a-z]{3})/paginated/$', + url(r'^dates/books/(?P[0-9]{4})/(?P[a-z]{3})/paginated/$', views.BookMonthArchive.as_view(paginate_by=30)), - url(r'^dates/books/(?P\d{4})/no_month/$', + url(r'^dates/books/(?P[0-9]{4})/no_month/$', views.BookMonthArchive.as_view()), - url(r'^dates/booksignings/(?P\d{4})/(?P[a-z]{3})/$', + url(r'^dates/booksignings/(?P[0-9]{4})/(?P[a-z]{3})/$', views.BookSigningMonthArchive.as_view()), # WeekArchiveView - url(r'^dates/books/(?P\d{4})/week/(?P\d{1,2})/$', + url(r'^dates/books/(?P[0-9]{4})/week/(?P[0-9]{1,2})/$', views.BookWeekArchive.as_view()), - url(r'^dates/books/(?P\d{4})/week/(?P\d{1,2})/allow_empty/$', + url(r'^dates/books/(?P[0-9]{4})/week/(?P[0-9]{1,2})/allow_empty/$', views.BookWeekArchive.as_view(allow_empty=True)), - url(r'^dates/books/(?P\d{4})/week/(?P\d{1,2})/allow_future/$', + url(r'^dates/books/(?P[0-9]{4})/week/(?P[0-9]{1,2})/allow_future/$', views.BookWeekArchive.as_view(allow_future=True)), - url(r'^dates/books/(?P\d{4})/week/(?P\d{1,2})/paginated/$', + url(r'^dates/books/(?P[0-9]{4})/week/(?P[0-9]{1,2})/paginated/$', views.BookWeekArchive.as_view(paginate_by=30)), - url(r'^dates/books/(?P\d{4})/week/no_week/$', + url(r'^dates/books/(?P[0-9]{4})/week/no_week/$', views.BookWeekArchive.as_view()), - url(r'^dates/books/(?P\d{4})/week/(?P\d{1,2})/monday/$', + url(r'^dates/books/(?P[0-9]{4})/week/(?P[0-9]{1,2})/monday/$', views.BookWeekArchive.as_view(week_format='%W')), - url(r'^dates/booksignings/(?P\d{4})/week/(?P\d{1,2})/$', + url(r'^dates/booksignings/(?P[0-9]{4})/week/(?P[0-9]{1,2})/$', views.BookSigningWeekArchive.as_view()), # DayArchiveView - url(r'^dates/books/(?P\d{4})/(?P[a-z]{3})/(?P\d{1,2})/$', + url(r'^dates/books/(?P[0-9]{4})/(?P[a-z]{3})/(?P[0-9]{1,2})/$', views.BookDayArchive.as_view()), - url(r'^dates/books/(?P\d{4})/(?P\d{1,2})/(?P\d{1,2})/$', + url(r'^dates/books/(?P[0-9]{4})/(?P[0-9]{1,2})/(?P[0-9]{1,2})/$', views.BookDayArchive.as_view(month_format='%m')), - url(r'^dates/books/(?P\d{4})/(?P[a-z]{3})/(?P\d{1,2})/allow_empty/$', + url(r'^dates/books/(?P[0-9]{4})/(?P[a-z]{3})/(?P[0-9]{1,2})/allow_empty/$', views.BookDayArchive.as_view(allow_empty=True)), - url(r'^dates/books/(?P\d{4})/(?P[a-z]{3})/(?P\d{1,2})/allow_future/$', + url(r'^dates/books/(?P[0-9]{4})/(?P[a-z]{3})/(?P[0-9]{1,2})/allow_future/$', views.BookDayArchive.as_view(allow_future=True)), - url(r'^dates/books/(?P\d{4})/(?P[a-z]{3})/(?P\d{1,2})/allow_empty_and_future/$', + url(r'^dates/books/(?P[0-9]{4})/(?P[a-z]{3})/(?P[0-9]{1,2})/allow_empty_and_future/$', views.BookDayArchive.as_view(allow_empty=True, allow_future=True)), - url(r'^dates/books/(?P\d{4})/(?P[a-z]{3})/(?P\d{1,2})/paginated/$', + url(r'^dates/books/(?P[0-9]{4})/(?P[a-z]{3})/(?P[0-9]{1,2})/paginated/$', views.BookDayArchive.as_view(paginate_by=True)), - url(r'^dates/books/(?P\d{4})/(?P[a-z]{3})/no_day/$', + url(r'^dates/books/(?P[0-9]{4})/(?P[a-z]{3})/no_day/$', views.BookDayArchive.as_view()), - url(r'^dates/booksignings/(?P\d{4})/(?P[a-z]{3})/(?P\d{1,2})/$', + url(r'^dates/booksignings/(?P[0-9]{4})/(?P[a-z]{3})/(?P[0-9]{1,2})/$', views.BookSigningDayArchive.as_view()), # TodayArchiveView @@ -238,22 +238,22 @@ urlpatterns = [ views.BookSigningTodayArchive.as_view()), # DateDetailView - url(r'^dates/books/(?P\d{4})/(?P[a-z]{3})/(?P\d{1,2})/(?P\d+)/$', + url(r'^dates/books/(?P[0-9]{4})/(?P[a-z]{3})/(?P[0-9]{1,2})/(?P[0-9]+)/$', views.BookDetail.as_view()), - url(r'^dates/books/(?P\d{4})/(?P\d{1,2})/(?P\d{1,2})/(?P\d+)/$', + url(r'^dates/books/(?P[0-9]{4})/(?P[0-9]{1,2})/(?P[0-9]{1,2})/(?P[0-9]+)/$', views.BookDetail.as_view(month_format='%m')), - url(r'^dates/books/(?P\d{4})/(?P[a-z]{3})/(?P\d{1,2})/(?P\d+)/allow_future/$', + url(r'^dates/books/(?P[0-9]{4})/(?P[a-z]{3})/(?P[0-9]{1,2})/(?P[0-9]+)/allow_future/$', views.BookDetail.as_view(allow_future=True)), - url(r'^dates/books/(?P\d{4})/(?P[a-z]{3})/(?P\d{1,2})/nopk/$', + url(r'^dates/books/(?P[0-9]{4})/(?P[a-z]{3})/(?P[0-9]{1,2})/nopk/$', views.BookDetail.as_view()), - url(r'^dates/books/(?P\d{4})/(?P[a-z]{3})/(?P\d{1,2})/byslug/(?P[\w-]+)/$', + url(r'^dates/books/(?P[0-9]{4})/(?P[a-z]{3})/(?P[0-9]{1,2})/byslug/(?P[\w-]+)/$', views.BookDetail.as_view()), - url(r'^dates/books/get_object_custom_queryset/(?P\d{4})/(?P[a-z]{3})/(?P\d{1,2})/(?P\d+)/$', + url(r'^dates/books/get_object_custom_queryset/(?P[0-9]{4})/(?P[a-z]{3})/(?P[0-9]{1,2})/(?P[0-9]+)/$', views.BookDetailGetObjectCustomQueryset.as_view()), - url(r'^dates/booksignings/(?P\d{4})/(?P[a-z]{3})/(?P\d{1,2})/(?P\d+)/$', + url(r'^dates/booksignings/(?P[0-9]{4})/(?P[a-z]{3})/(?P[0-9]{1,2})/(?P[0-9]+)/$', views.BookSigningDetail.as_view()), # Useful for testing redirects diff --git a/tests/model_formsets/tests.py b/tests/model_formsets/tests.py index 4c7d2a535e5..ce6f4ab1375 100644 --- a/tests/model_formsets/tests.py +++ b/tests/model_formsets/tests.py @@ -1078,7 +1078,7 @@ class ModelFormsetTest(TestCase): form = formset.forms[0] now = form.fields['date_joined'].initial() result = form.as_p() - result = re.sub(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)?', '__DATETIME__', result) + result = re.sub(r'[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(?:\.[0-9]+)?', '__DATETIME__', result) self.assertHTMLEqual(result, '

\n' '

' diff --git a/tests/template_tests/urls.py b/tests/template_tests/urls.py index 2b7a313206e..a93d4c46495 100644 --- a/tests/template_tests/urls.py +++ b/tests/template_tests/urls.py @@ -8,10 +8,10 @@ from . import views urlpatterns = [ # Test urls for testing reverse lookups url(r'^$', views.index), - url(r'^client/([\d,]+)/$', views.client), - url(r'^client/(?P\d+)/(?P[^/]+)/$', views.client_action), - url(r'^client/(?P\d+)/(?P[^/]+)/$', views.client_action), - url(r'^named-client/(\d+)/$', views.client2, name="named.client"), + url(r'^client/([0-9,]+)/$', views.client), + url(r'^client/(?P[0-9]+)/(?P[^/]+)/$', views.client_action), + url(r'^client/(?P[0-9]+)/(?P[^/]+)/$', views.client_action), + url(r'^named-client/([0-9]+)/$', views.client2, name="named.client"), # Unicode strings are permitted everywhere. url(r'^Юникод/(\w+)/$', views.client2, name="метка_оператора"), diff --git a/tests/test_utils/urls.py b/tests/test_utils/urls.py index 4aade3d5725..4193cabf91d 100644 --- a/tests/test_utils/urls.py +++ b/tests/test_utils/urls.py @@ -4,6 +4,6 @@ from . import views urlpatterns = [ - url(r'^test_utils/get_person/(\d+)/$', views.get_person), + url(r'^test_utils/get_person/([0-9]+)/$', views.get_person), url(r'^test_utils/no_template_used/$', views.no_template_used), ] diff --git a/tests/urlpatterns_reverse/extra_urls.py b/tests/urlpatterns_reverse/extra_urls.py index 4eb2f021300..c30a61a99ab 100644 --- a/tests/urlpatterns_reverse/extra_urls.py +++ b/tests/urlpatterns_reverse/extra_urls.py @@ -8,7 +8,7 @@ from .views import empty_view urlpatterns = [ - url(r'^e-places/(\d+)/$', empty_view, name='extra-places'), + url(r'^e-places/([0-9]+)/$', empty_view, name='extra-places'), url(r'^e-people/(?P\w+)/$', empty_view, name="extra-people"), url('', include('urlpatterns_reverse.included_urls2')), url(r'^prefix/(?P\w+)/', include('urlpatterns_reverse.included_urls2')), diff --git a/tests/urlpatterns_reverse/included_named_urls.py b/tests/urlpatterns_reverse/included_named_urls.py index d8a6a164814..a4c6afea575 100644 --- a/tests/urlpatterns_reverse/included_named_urls.py +++ b/tests/urlpatterns_reverse/included_named_urls.py @@ -6,6 +6,6 @@ from .views import empty_view urlpatterns = [ url(r'^$', empty_view, name="named-url3"), url(r'^extra/(?P\w+)/$', empty_view, name="named-url4"), - url(r'^(?P\d+)|(?P\d+)/$', empty_view), + url(r'^(?P[0-9]+)|(?P[0-9]+)/$', empty_view), url(r'^included/', include('urlpatterns_reverse.included_named_urls2')), ] diff --git a/tests/urlpatterns_reverse/included_named_urls2.py b/tests/urlpatterns_reverse/included_named_urls2.py index cb8c893b48f..47411ec6201 100644 --- a/tests/urlpatterns_reverse/included_named_urls2.py +++ b/tests/urlpatterns_reverse/included_named_urls2.py @@ -6,5 +6,5 @@ from .views import empty_view urlpatterns = [ url(r'^$', empty_view, name="named-url5"), url(r'^extra/(?P\w+)/$', empty_view, name="named-url6"), - url(r'^(?P\d+)|(?P\d+)/$', empty_view), + url(r'^(?P[0-9]+)|(?P[0-9]+)/$', empty_view), ] diff --git a/tests/urlpatterns_reverse/included_namespace_urls.py b/tests/urlpatterns_reverse/included_namespace_urls.py index 1b28552adeb..29947f47cdd 100644 --- a/tests/urlpatterns_reverse/included_namespace_urls.py +++ b/tests/urlpatterns_reverse/included_namespace_urls.py @@ -14,14 +14,14 @@ with warnings.catch_warnings(record=True) as w: urlpatterns = patterns('urlpatterns_reverse.views', url(r'^normal/$', 'empty_view', name='inc-normal-view'), - url(r'^normal/(?P\d+)/(?P\d+)/$', 'empty_view', name='inc-normal-view'), + url(r'^normal/(?P[0-9]+)/(?P[0-9]+)/$', 'empty_view', name='inc-normal-view'), url(r'^\+\\\$\*/$', 'empty_view', name='inc-special-view'), - url(r'^mixed_args/(\d+)/(?P\d+)/$', 'empty_view', name='inc-mixed-args'), - url(r'^no_kwargs/(\d+)/(\d+)/$', 'empty_view', name='inc-no-kwargs'), + url(r'^mixed_args/([0-9]+)/(?P[0-9]+)/$', 'empty_view', name='inc-mixed-args'), + url(r'^no_kwargs/([0-9]+)/([0-9]+)/$', 'empty_view', name='inc-no-kwargs'), - url(r'^view_class/(?P\d+)/(?P\d+)/$', view_class_instance, name='inc-view-class'), + url(r'^view_class/(?P[0-9]+)/(?P[0-9]+)/$', view_class_instance, name='inc-view-class'), (r'^test3/', include(testobj3.urls)), (r'^ns-included3/', include('urlpatterns_reverse.included_urls', namespace='inc-ns3')), diff --git a/tests/urlpatterns_reverse/included_no_kwargs_urls.py b/tests/urlpatterns_reverse/included_no_kwargs_urls.py index bed77f7a18a..0c291e0de27 100644 --- a/tests/urlpatterns_reverse/included_no_kwargs_urls.py +++ b/tests/urlpatterns_reverse/included_no_kwargs_urls.py @@ -4,5 +4,5 @@ from .views import empty_view urlpatterns = [ - url(r'^inner-no-kwargs/(\d+)/', empty_view, name="inner-no-kwargs") + url(r'^inner-no-kwargs/([0-9]+)/', empty_view, name="inner-no-kwargs") ] diff --git a/tests/urlpatterns_reverse/included_urls.py b/tests/urlpatterns_reverse/included_urls.py index bbc8537820a..f8e69cb7618 100644 --- a/tests/urlpatterns_reverse/included_urls.py +++ b/tests/urlpatterns_reverse/included_urls.py @@ -6,5 +6,5 @@ from .views import empty_view urlpatterns = [ url(r'^$', empty_view, name="inner-nothing"), url(r'^extra/(?P\w+)/$', empty_view, name="inner-extra"), - url(r'^(?P\d+)|(?P\d+)/$', empty_view, name="inner-disjunction"), + url(r'^(?P[0-9]+)|(?P[0-9]+)/$', empty_view, name="inner-disjunction"), ] diff --git a/tests/urlpatterns_reverse/named_urls.py b/tests/urlpatterns_reverse/named_urls.py index a4de1e1b874..3f312497355 100644 --- a/tests/urlpatterns_reverse/named_urls.py +++ b/tests/urlpatterns_reverse/named_urls.py @@ -6,6 +6,6 @@ from .views import empty_view urlpatterns = [ url(r'^$', empty_view, name="named-url1"), url(r'^extra/(?P\w+)/$', empty_view, name="named-url2"), - url(r'^(?P\d+)|(?P\d+)/$', empty_view), + url(r'^(?P[0-9]+)|(?P[0-9]+)/$', empty_view), url(r'^included/', include('urlpatterns_reverse.included_named_urls')), ] diff --git a/tests/urlpatterns_reverse/namespace_urls.py b/tests/urlpatterns_reverse/namespace_urls.py index cb4453fe575..19b1b178b7c 100644 --- a/tests/urlpatterns_reverse/namespace_urls.py +++ b/tests/urlpatterns_reverse/namespace_urls.py @@ -11,7 +11,7 @@ class URLObject(object): def urls(self): return ([ url(r'^inner/$', 'empty_view', name='urlobject-view'), - url(r'^inner/(?P\d+)/(?P\d+)/$', 'empty_view', name='urlobject-view'), + url(r'^inner/(?P[0-9]+)/(?P[0-9]+)/$', 'empty_view', name='urlobject-view'), url(r'^inner/\+\\\$\*/$', 'empty_view', name='urlobject-special-view'), ], self.app_name, self.namespace) urls = property(urls) @@ -25,18 +25,18 @@ otherobj2 = URLObject('nodefault', 'other-ns2') urlpatterns = [ url(r'^normal/$', views.empty_view, name='normal-view'), - url(r'^normal/(?P\d+)/(?P\d+)/$', views.empty_view, name='normal-view'), + url(r'^normal/(?P[0-9]+)/(?P[0-9]+)/$', views.empty_view, name='normal-view'), url(r'^resolver_match/$', views.pass_resolver_match_view, name='test-resolver-match'), url(r'^\+\\\$\*/$', views.empty_view, name='special-view'), - url(r'^mixed_args/(\d+)/(?P\d+)/$', views.empty_view, name='mixed-args'), - url(r'^no_kwargs/(\d+)/(\d+)/$', views.empty_view, name='no-kwargs'), + url(r'^mixed_args/([0-9]+)/(?P[0-9]+)/$', views.empty_view, name='mixed-args'), + url(r'^no_kwargs/([0-9]+)/([0-9]+)/$', views.empty_view, name='no-kwargs'), - url(r'^view_class/(?P\d+)/(?P\d+)/$', views.view_class_instance, name='view-class'), + url(r'^view_class/(?P[0-9]+)/(?P[0-9]+)/$', views.view_class_instance, name='view-class'), - url(r'^unnamed/normal/(?P\d+)/(?P\d+)/$', views.empty_view), - url(r'^unnamed/view_class/(?P\d+)/(?P\d+)/$', views.view_class_instance), + url(r'^unnamed/normal/(?P[0-9]+)/(?P[0-9]+)/$', views.empty_view), + url(r'^unnamed/view_class/(?P[0-9]+)/(?P[0-9]+)/$', views.view_class_instance), url(r'^test1/', include(testobj1.urls)), url(r'^test2/', include(testobj2.urls)), @@ -49,9 +49,9 @@ urlpatterns = [ url(r'^ns-included2/', include('urlpatterns_reverse.included_namespace_urls', namespace='inc-ns2')), url(r'^included/', include('urlpatterns_reverse.included_namespace_urls')), - url(r'^inc(?P\d+)/', include('urlpatterns_reverse.included_urls', namespace='inc-ns5')), + url(r'^inc(?P[0-9]+)/', include('urlpatterns_reverse.included_urls', namespace='inc-ns5')), - url(r'^ns-outer/(?P\d+)/', include('urlpatterns_reverse.included_namespace_urls', namespace='inc-outer')), + url(r'^ns-outer/(?P[0-9]+)/', include('urlpatterns_reverse.included_namespace_urls', namespace='inc-outer')), url(r'^\+\\\$\*/', include('urlpatterns_reverse.namespace_urls', namespace='special')), ] diff --git a/tests/urlpatterns_reverse/urls.py b/tests/urlpatterns_reverse/urls.py index cafcb63888a..3e5b53975ac 100644 --- a/tests/urlpatterns_reverse/urls.py +++ b/tests/urlpatterns_reverse/urls.py @@ -14,15 +14,15 @@ with warnings.catch_warnings(record=True): warnings.filterwarnings('ignore', module='django.conf.urls') urlpatterns = patterns('', - url(r'^places/(\d+)/$', empty_view, name='places'), + url(r'^places/([0-9]+)/$', empty_view, name='places'), url(r'^places?/$', empty_view, name="places?"), url(r'^places+/$', empty_view, name="places+"), url(r'^places*/$', empty_view, name="places*"), url(r'^(?:places/)?$', empty_view, name="places2?"), url(r'^(?:places/)+$', empty_view, name="places2+"), url(r'^(?:places/)*$', empty_view, name="places2*"), - url(r'^places/(\d+|[a-z_]+)/', empty_view, name="places3"), - url(r'^places/(?P\d+)/$', empty_view, name="places4"), + url(r'^places/([0-9]+|[a-z_]+)/', empty_view, name="places3"), + url(r'^places/(?P[0-9]+)/$', empty_view, name="places4"), url(r'^people/(?P\w+)/$', empty_view, name="people"), url(r'^people/(?:name/)', empty_view, name="people2"), url(r'^people/(?:name/(\w+)/)?', empty_view, name="people2a"), @@ -31,26 +31,26 @@ with warnings.catch_warnings(record=True): url(r'^hardcoded/$', empty_view, name="hardcoded"), url(r'^hardcoded/doc\.pdf$', empty_view, name="hardcoded2"), url(r'^people/(?P\w\w)/(?P\w+)/$', empty_view, name="people3"), - url(r'^people/(?P\w\w)/(?P\d)/$', empty_view, name="people4"), + url(r'^people/(?P\w\w)/(?P[0-9])/$', empty_view, name="people4"), url(r'^people/((?P\w\w)/test)?/(\w+)/$', empty_view, name="people6"), url(r'^character_set/[abcdef0-9]/$', empty_view, name="range"), url(r'^character_set/[\w]/$', empty_view, name="range2"), - url(r'^price/\$(\d+)/$', empty_view, name="price"), - url(r'^price/[$](\d+)/$', empty_view, name="price2"), - url(r'^price/[\$](\d+)/$', empty_view, name="price3"), - url(r'^product/(?P\w+)\+\(\$(?P\d+(\.\d+)?)\)/$', empty_view, name="product"), - url(r'^headlines/(?P\d+)\.(?P\d+)\.(?P\d+)/$', empty_view, name="headlines"), + url(r'^price/\$([0-9]+)/$', empty_view, name="price"), + url(r'^price/[$]([0-9]+)/$', empty_view, name="price2"), + url(r'^price/[\$]([0-9]+)/$', empty_view, name="price3"), + url(r'^product/(?P\w+)\+\(\$(?P[0-9]+(\.[0-9]+)?)\)/$', empty_view, name="product"), + url(r'^headlines/(?P[0-9]+)\.(?P[0-9]+)\.(?P[0-9]+)/$', empty_view, name="headlines"), url(r'^windows_path/(?P[A-Z]):\\(?P.+)/$', empty_view, name="windows"), url(r'^special_chars/(?P.+)/$', empty_view, name="special"), - url(r'^(?P.+)/\d+/$', empty_view, name="mixed"), + url(r'^(?P.+)/[0-9]+/$', empty_view, name="mixed"), 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\d+)/', include('urlpatterns_reverse.included_urls')), - url(r'^outer-no-kwargs/(\d+)/', include('urlpatterns_reverse.included_no_kwargs_urls')), + url(r'^outer/(?P[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')), # This is non-reversible, but we shouldn't blow up when parsing it. @@ -58,13 +58,13 @@ with warnings.catch_warnings(record=True): # Regression views for #9038. See tests for more details url(r'arg_view/$', 'kwargs_view'), - url(r'arg_view/(?P\d+)/$', 'kwargs_view'), - url(r'absolute_arg_view/(?P\d+)/$', absolute_kwargs_view), + url(r'arg_view/(?P[0-9]+)/$', 'kwargs_view'), + url(r'absolute_arg_view/(?P[0-9]+)/$', absolute_kwargs_view), url(r'absolute_arg_view/$', absolute_kwargs_view), # Tests for #13154. Mixed syntax to test both ways of defining URLs. - url(r'defaults_view1/(?P\d+)/', 'defaults_view', {'arg2': 1}, name='defaults'), - (r'defaults_view2/(?P\d+)/', 'defaults_view', {'arg2': 2}, 'defaults'), + url(r'defaults_view1/(?P[0-9]+)/', 'defaults_view', {'arg2': 1}, name='defaults'), + (r'defaults_view2/(?P[0-9]+)/', 'defaults_view', {'arg2': 2}, 'defaults'), url('^includes/', include(other_patterns)), ) diff --git a/tests/utils_tests/test_jslex.py b/tests/utils_tests/test_jslex.py index 97e6dbc1092..0b5081c5400 100644 --- a/tests/utils_tests/test_jslex.py +++ b/tests/utils_tests/test_jslex.py @@ -63,16 +63,16 @@ class JsTokensTest(TestCase): (r"""/\[[^\]]+\]/gi""", [r"""regex /\[[^\]]+\]/gi"""]), (""" rexl.re = { - NAME: /^(?!\d)(?:\w)+|^"(?:[^"]|"")+"/, - UNQUOTED_LITERAL: /^@(?:(?!\d)(?:\w|\:)+|^"(?:[^"]|"")+")\[[^\]]+\]/, + NAME: /^(?![0-9])(?:\w)+|^"(?:[^"]|"")+"/, + UNQUOTED_LITERAL: /^@(?:(?![0-9])(?:\w|\:)+|^"(?:[^"]|"")+")\[[^\]]+\]/, QUOTED_LITERAL: /^'(?:[^']|'')*'/, NUMERIC_LITERAL: /^[0-9]+(?:\.[0-9]*(?:[eE][-+][0-9]+)?)?/, SYMBOL: /^(?:==|=|<>|<=|<|>=|>|!~~|!~|~~|~|!==|!=|!~=|!~|!|&|\||\.|\:|,|\(|\)|\[|\]|\{|\}|\?|\:|;|@|\^|\/\+|\/|\*|\+|-)/ }; """, ["id rexl", "punct .", "id re", "punct =", "punct {", - "id NAME", "punct :", r"""regex /^(?!\d)(?:\w)+|^"(?:[^"]|"")+"/""", "punct ,", - "id UNQUOTED_LITERAL", "punct :", r"""regex /^@(?:(?!\d)(?:\w|\:)+|^"(?:[^"]|"")+")\[[^\]]+\]/""", "punct ,", + "id NAME", "punct :", r"""regex /^(?![0-9])(?:\w)+|^"(?:[^"]|"")+"/""", "punct ,", + "id UNQUOTED_LITERAL", "punct :", r"""regex /^@(?:(?![0-9])(?:\w|\:)+|^"(?:[^"]|"")+")\[[^\]]+\]/""", "punct ,", "id QUOTED_LITERAL", "punct :", r"""regex /^'(?:[^']|'')*'/""", "punct ,", "id NUMERIC_LITERAL", "punct :", r"""regex /^[0-9]+(?:\.[0-9]*(?:[eE][-+][0-9]+)?)?/""", "punct ,", "id SYMBOL", "punct :", r"""regex /^(?:==|=|<>|<=|<|>=|>|!~~|!~|~~|~|!==|!=|!~=|!~|!|&|\||\.|\:|,|\(|\)|\[|\]|\{|\}|\?|\:|;|@|\^|\/\+|\/|\*|\+|-)/""", @@ -81,8 +81,8 @@ class JsTokensTest(TestCase): (""" rexl.re = { - NAME: /^(?!\d)(?:\w)+|^"(?:[^"]|"")+"/, - UNQUOTED_LITERAL: /^@(?:(?!\d)(?:\w|\:)+|^"(?:[^"]|"")+")\[[^\]]+\]/, + NAME: /^(?![0-9])(?:\w)+|^"(?:[^"]|"")+"/, + UNQUOTED_LITERAL: /^@(?:(?![0-9])(?:\w|\:)+|^"(?:[^"]|"")+")\[[^\]]+\]/, QUOTED_LITERAL: /^'(?:[^']|'')*'/, NUMERIC_LITERAL: /^[0-9]+(?:\.[0-9]*(?:[eE][-+][0-9]+)?)?/, SYMBOL: /^(?:==|=|<>|<=|<|>=|>|!~~|!~|~~|~|!==|!=|!~=|!~|!|&|\||\.|\:|,|\(|\)|\[|\]|\{|\}|\?|\:|;|@|\^|\/\+|\/|\*|\+|-)/ @@ -90,8 +90,8 @@ class JsTokensTest(TestCase): str = '"'; """, ["id rexl", "punct .", "id re", "punct =", "punct {", - "id NAME", "punct :", r"""regex /^(?!\d)(?:\w)+|^"(?:[^"]|"")+"/""", "punct ,", - "id UNQUOTED_LITERAL", "punct :", r"""regex /^@(?:(?!\d)(?:\w|\:)+|^"(?:[^"]|"")+")\[[^\]]+\]/""", "punct ,", + "id NAME", "punct :", r"""regex /^(?![0-9])(?:\w)+|^"(?:[^"]|"")+"/""", "punct ,", + "id UNQUOTED_LITERAL", "punct :", r"""regex /^@(?:(?![0-9])(?:\w|\:)+|^"(?:[^"]|"")+")\[[^\]]+\]/""", "punct ,", "id QUOTED_LITERAL", "punct :", r"""regex /^'(?:[^']|'')*'/""", "punct ,", "id NUMERIC_LITERAL", "punct :", r"""regex /^[0-9]+(?:\.[0-9]*(?:[eE][-+][0-9]+)?)?/""", "punct ,", "id SYMBOL", "punct :", r"""regex /^(?:==|=|<>|<=|<|>=|>|!~~|!~|~~|~|!==|!=|!~=|!~|!|&|\||\.|\:|,|\(|\)|\[|\]|\{|\}|\?|\:|;|@|\^|\/\+|\/|\*|\+|-)/""", diff --git a/tests/version/tests.py b/tests/version/tests.py index b4c4283c049..a7ae848984f 100644 --- a/tests/version/tests.py +++ b/tests/version/tests.py @@ -11,7 +11,7 @@ class VersionTests(TestCase): # This will return a different result when it's run within or outside # of a git clone: 1.4.devYYYYMMDDHHMMSS or 1.4. ver_string = get_version(ver_tuple) - six.assertRegex(self, ver_string, r'1\.4(\.dev\d+)?') + six.assertRegex(self, ver_string, r'1\.4(\.dev[0-9]+)?') def test_releases(self): tuples_to_strings = ( diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py index 75cc8a0b97a..8b56cb583b7 100644 --- a/tests/view_tests/tests/test_debug.py +++ b/tests/view_tests/tests/test_debug.py @@ -94,7 +94,7 @@ class DebugViewTests(TestCase): match = re.search(b'
', response.content) self.assertFalse(match is None) id_repr = match.group('id') - self.assertFalse(re.search(b'[^c\d]', id_repr), + self.assertFalse(re.search(b'[^c0-9]', id_repr), "Numeric IDs in debug response HTML page shouldn't be localized (value: %s)." % id_repr) def test_template_exceptions(self): diff --git a/tests/view_tests/urls.py b/tests/view_tests/urls.py index cefab5af25e..cd7e46663c0 100644 --- a/tests/view_tests/urls.py +++ b/tests/view_tests/urls.py @@ -72,8 +72,8 @@ urlpatterns = [ ] urlpatterns += [ - url(r'view_exception/(?P\d+)/$', views.view_exception, name='view_exception'), - url(r'template_exception/(?P\d+)/$', views.template_exception, name='template_exception'), + url(r'view_exception/(?P[0-9]+)/$', views.view_exception, name='view_exception'), + url(r'template_exception/(?P[0-9]+)/$', views.template_exception, name='template_exception'), url(r'^raises_template_does_not_exist/(?P.+)$', views.raises_template_does_not_exist, name='raises_template_does_not_exist'), url(r'^render_no_template/$', views.render_no_template, name='render_no_template'), ]