diff options
42 files changed, 82 insertions, 82 deletions
diff --git a/django/contrib/admindocs/urls.py b/django/contrib/admindocs/urls.py index e0b2259ef9..bfc9648e83 100644 --- a/django/contrib/admindocs/urls.py +++ b/django/contrib/admindocs/urls.py @@ -2,31 +2,31 @@ from django.conf.urls import url from django.contrib.admindocs import views urlpatterns = [ - url('^$', + url(r'^$', views.BaseAdminDocsView.as_view(template_name='admin_doc/index.html'), name='django-admindocs-docroot'), - url('^bookmarklets/$', + url(r'^bookmarklets/$', views.BookmarkletsView.as_view(), name='django-admindocs-bookmarklets'), - url('^tags/$', + url(r'^tags/$', views.TemplateTagIndexView.as_view(), name='django-admindocs-tags'), - url('^filters/$', + url(r'^filters/$', views.TemplateFilterIndexView.as_view(), name='django-admindocs-filters'), - url('^views/$', + url(r'^views/$', views.ViewIndexView.as_view(), name='django-admindocs-views-index'), - url('^views/(?P<view>[^/]+)/$', + url(r'^views/(?P<view>[^/]+)/$', views.ViewDetailView.as_view(), name='django-admindocs-views-detail'), - url('^models/$', + url(r'^models/$', views.ModelIndexView.as_view(), name='django-admindocs-models-index'), - url('^models/(?P<app_label>[^\.]+)\.(?P<model_name>[^/]+)/$', + url(r'^models/(?P<app_label>[^\.]+)\.(?P<model_name>[^/]+)/$', views.ModelDetailView.as_view(), name='django-admindocs-models-detail'), - url('^templates/(?P<template>.*)/$', + url(r'^templates/(?P<template>.*)/$', views.TemplateDetailView.as_view(), name='django-admindocs-templates'), ] diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py index 5fa3c46a8e..476d883a8d 100644 --- a/django/contrib/admindocs/views.py +++ b/django/contrib/admindocs/views.py @@ -430,7 +430,7 @@ non_named_group_matcher = re.compile(r'\(.*?\)') def simplify_regex(pattern): - """ + r""" Clean up urlpattern regexes into something more readable by humans. For example, turn "^(?P<sport_slug>\w+)/athletes/(?P<athlete_slug>\w+)/$" into "/<sport_slug>/athletes/<athlete_slug>/". diff --git a/django/contrib/auth/password_validation.py b/django/contrib/auth/password_validation.py index 5fdae05a84..bee6bff942 100644 --- a/django/contrib/auth/password_validation.py +++ b/django/contrib/auth/password_validation.py @@ -143,7 +143,7 @@ class UserAttributeSimilarityValidator(object): value = getattr(user, attribute_name, None) if not value or not isinstance(value, string_types): continue - value_parts = re.split('\W+', value) + [value] + value_parts = re.split(r'\W+', value) + [value] for value_part in value_parts: if SequenceMatcher(a=password.lower(), b=value_part.lower()).quick_ratio() > self.max_similarity: try: diff --git a/django/contrib/humanize/templatetags/humanize.py b/django/contrib/humanize/templatetags/humanize.py index bb9bc7b1ca..6c43ace840 100644 --- a/django/contrib/humanize/templatetags/humanize.py +++ b/django/contrib/humanize/templatetags/humanize.py @@ -49,7 +49,7 @@ def intcomma(value, use_l10n=True): else: return number_format(value, force_grouping=True) orig = force_text(value) - new = re.sub("^(-?\d+)(\d{3})", '\g<1>,\g<2>', orig) + new = re.sub(r"^(-?\d+)(\d{3})", r'\g<1>,\g<2>', orig) if orig == new: return new else: diff --git a/django/core/checks/urls.py b/django/core/checks/urls.py index 8356fc2f00..e744cc0ca4 100644 --- a/django/core/checks/urls.py +++ b/django/core/checks/urls.py @@ -78,7 +78,7 @@ def check_include_trailing_dollar(pattern): Check that include is not used with a regex ending with a dollar. """ regex_pattern = pattern.regex.pattern - if regex_pattern.endswith('$') and not regex_pattern.endswith('\$'): + if regex_pattern.endswith('$') and not regex_pattern.endswith(r'\$'): warning = Warning( "Your URL pattern {} uses include with a regex ending with a '$'. " "Remove the dollar from the regex to avoid problems including " diff --git a/django/core/validators.py b/django/core/validators.py index 805dd8860f..5a7fd1a49b 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -88,12 +88,12 @@ class URLValidator(RegexValidator): # Max length for domain name labels is 63 characters per RFC 1034 sec. 3.1 domain_re = r'(?:\.(?!-)[a-z' + ul + r'0-9-]{1,63}(?<!-))*' tld_re = ( - '\.' # dot - '(?!-)' # can't start with a dash - '(?:[a-z' + ul + '-]{2,63}' # domain label - '|xn--[a-z0-9]{1,59})' # or punycode label - '(?<!-)' # can't end with a dash - '\.?' # may have a trailing dot + r'\.' # dot + r'(?!-)' # can't start with a dash + r'(?:[a-z' + ul + '-]{2,63}' # domain label + r'|xn--[a-z0-9]{1,59})' # or punycode label + r'(?<!-)' # can't end with a dash + r'\.?' # may have a trailing dot ) host_re = '(' + hostname_re + domain_re + tld_re + '|localhost)' @@ -156,7 +156,7 @@ class URLValidator(RegexValidator): raise ValidationError(self.message, code=self.code) integer_validator = RegexValidator( - _lazy_re_compile('^-?\d+\Z'), + _lazy_re_compile(r'^-?\d+\Z'), message=_('Enter a valid integer.'), code='invalid', ) @@ -295,7 +295,7 @@ def ip_address_validators(protocol, unpack_ipv4): def int_list_validator(sep=',', message=None, code='invalid', allow_negative=False): - regexp = _lazy_re_compile('^%(neg)s\d+(?:%(sep)s%(neg)s\d+)*\Z' % { + regexp = _lazy_re_compile(r'^%(neg)s\d+(?:%(sep)s%(neg)s\d+)*\Z' % { 'neg': '(-)?' if allow_negative else '', 'sep': re.escape(sep), }) diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py index 1ed11b178e..a072687ebb 100644 --- a/django/db/backends/base/operations.py +++ b/django/db/backends/base/operations.py @@ -428,7 +428,7 @@ class BaseDatabaseOperations(object): def prep_for_like_query(self, x): """Prepares a value for use in a LIKE query.""" - return force_text(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_") + return force_text(x).replace("\\", "\\\\").replace("%", r"\%").replace("_", r"\_") # Same as prep_for_like_query(), but called for "iexact" matches, which # need not necessarily be implemented using "LIKE" in the backend. diff --git a/django/db/backends/sqlite3/introspection.py b/django/db/backends/sqlite3/introspection.py index 2ed629f94a..ce5e7032fb 100644 --- a/django/db/backends/sqlite3/introspection.py +++ b/django/db/backends/sqlite3/introspection.py @@ -125,14 +125,14 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): if field_desc.startswith("UNIQUE"): continue - m = re.search('references (\S*) ?\(["|]?(.*)["|]?\)', field_desc, re.I) + m = re.search(r'references (\S*) ?\(["|]?(.*)["|]?\)', field_desc, re.I) if not m: continue table, column = [s.strip('"') for s in m.groups()] if field_desc.startswith("FOREIGN KEY"): # Find name of the target FK field - m = re.match('FOREIGN KEY\(([^\)]*)\).*', field_desc, re.I) + m = re.match(r'FOREIGN KEY\(([^\)]*)\).*', field_desc, re.I) field_name = m.groups()[0].strip('"') else: field_name = field_desc.split()[0].strip('"') @@ -175,7 +175,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): if field_desc.startswith("UNIQUE"): continue - m = re.search('"(.*)".*references (.*) \(["|](.*)["|]\)', field_desc, re.I) + m = re.search(r'"(.*)".*references (.*) \(["|](.*)["|]\)', field_desc, re.I) if not m: continue diff --git a/django/db/migrations/writer.py b/django/db/migrations/writer.py index 7c39cdc931..e75f5bfdd1 100644 --- a/django/db/migrations/writer.py +++ b/django/db/migrations/writer.py @@ -181,7 +181,7 @@ class MigrationWriter(object): # for comments migration_imports = set() for line in list(imports): - if re.match("^import (.*)\.\d+[^\s]*$", line): + if re.match(r"^import (.*)\.\d+[^\s]*$", line): migration_imports.add(line.split("import")[1].strip()) imports.remove(line) self.needs_manual_porting = True diff --git a/django/template/base.py b/django/template/base.py index 778d82be55..13037c31aa 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -639,7 +639,7 @@ filter_raw_string = r""" )""" % { 'constant': constant_string, 'num': r'[-+\.]?\d[\d\.e]*', - 'var_chars': "\w\.", + 'var_chars': r'\w\.', 'filter_sep': re.escape(FILTER_SEPARATOR), 'arg_sep': re.escape(FILTER_ARGUMENT_SEPARATOR), } diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index e3dc48e474..b258cf269b 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -259,7 +259,7 @@ def stringformat(value, arg): def title(value): """Converts a string into titlecase.""" t = re.sub("([a-z])'([A-Z])", lambda m: m.group(0).lower(), value.title()) - return re.sub("\d([A-Z])", lambda m: m.group(0).lower(), t) + return re.sub(r"\d([A-Z])", lambda m: m.group(0).lower(), t) @register.filter(is_safe=True) diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index ece6f7501d..71fcbbaab3 100644 --- a/django/template/defaulttags.py +++ b/django/template/defaulttags.py @@ -1329,7 +1329,7 @@ def templatetag(parser, token): @register.tag def url(parser, token): - """ + r""" Return an absolute URL matching the given view with its parameters. This is a way to define links that aren't tied to a particular URL diff --git a/django/test/client.py b/django/test/client.py index af55f9efb4..aea051ed2b 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -33,7 +33,7 @@ __all__ = ('Client', 'RedirectCycleError', 'RequestFactory', 'encode_file', 'enc BOUNDARY = 'BoUnDaRyStRiNg' MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY -CONTENT_TYPE_RE = re.compile('.*; charset=([\w\d-]+);?') +CONTENT_TYPE_RE = re.compile(r'.*; charset=([\w\d-]+);?') class RedirectCycleError(Exception): diff --git a/django/test/html.py b/django/test/html.py index 195c61ede0..dfff8d6369 100644 --- a/django/test/html.py +++ b/django/test/html.py @@ -10,7 +10,7 @@ from django.utils import six from django.utils.encoding import force_text, python_2_unicode_compatible from django.utils.html_parser import HTMLParseError, HTMLParser -WHITESPACE = re.compile('\s+') +WHITESPACE = re.compile(r'\s+') def normalize_whitespace(string): diff --git a/django/utils/html.py b/django/utils/html.py index a5cb56ec9e..84379caa9c 100644 --- a/django/utils/html.py +++ b/django/utils/html.py @@ -36,7 +36,7 @@ simple_email_re = re.compile(r'^\S+@\S+\.\S+$') link_target_attribute_re = re.compile(r'(<a [^>]*?)target=[^\s>]+') html_gunk_re = re.compile( r'(?:<br clear="all">|<i><\/i>|<b><\/b>|<em><\/em>|<strong><\/strong>|' - '<\/?smallcaps>|<\/?uppercase>)', re.IGNORECASE) + r'<\/?smallcaps>|<\/?uppercase>)', re.IGNORECASE) hard_coded_bullets_re = re.compile( r'((?:<p>(?:%s).*?[a-zA-Z].*?</p>\s*)+)' % '|'.join(re.escape(x) for x in DOTS), re.DOTALL ) diff --git a/django/utils/regex_helper.py b/django/utils/regex_helper.py index 4a697b2920..622d822759 100644 --- a/django/utils/regex_helper.py +++ b/django/utils/regex_helper.py @@ -48,7 +48,7 @@ class NonCapture(list): def normalize(pattern): - """ + r""" Given a reg-exp pattern, normalizes it to an iterable of forms that suffice for reverse matching. This does the following: @@ -203,7 +203,7 @@ def normalize(pattern): def next_char(input_iter): - """ + r""" An iterator that yields the next character from "pattern_iter", respecting escape sequences. An escaped character is replaced by a representative of its class (e.g. \w -> "x"). If the escaped character is one that is diff --git a/django/utils/text.py b/django/utils/text.py index 3b8fc581bf..a77f27eed7 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -423,11 +423,11 @@ def slugify(value, allow_unicode=False): value = force_text(value) if allow_unicode: value = unicodedata.normalize('NFKC', value) - value = re.sub('[^\w\s-]', '', value, flags=re.U).strip().lower() - return mark_safe(re.sub('[-\s]+', '-', value, flags=re.U)) + value = re.sub(r'[^\w\s-]', '', value, flags=re.U).strip().lower() + return mark_safe(re.sub(r'[-\s]+', '-', value, flags=re.U)) value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii') - value = re.sub('[^\w\s-]', '', value).strip().lower() - return mark_safe(re.sub('[-\s]+', '-', value)) + value = re.sub(r'[^\w\s-]', '', value).strip().lower() + return mark_safe(re.sub(r'[-\s]+', '-', value)) def camel_case_to_spaces(value): diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py index 9154ceeb7b..a5975b005c 100644 --- a/django/utils/translation/__init__.py +++ b/django/utils/translation/__init__.py @@ -255,7 +255,7 @@ def get_language_info(lang_code): info['name_translated'] = ugettext_lazy(info['name']) return info -trim_whitespace_re = re.compile('\s*\n\s*') +trim_whitespace_re = re.compile(r'\s*\n\s*') def trim_whitespace(s): diff --git a/django/views/debug.py b/django/views/debug.py index a92f487bb1..f7c685893c 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -537,7 +537,7 @@ TECHNICAL_500_TEMPLATE = (""" <meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta name="robots" content="NONE,NOARCHIVE"> <title>{% if exception_type %}{{ exception_type }}{% else %}Report{% endif %}""" -"""{% if request %} at {{ request.path_info|escape }}{% endif %}</title> +r"""{% if request %} at {{ request.path_info|escape }}{% endif %}</title> <style type="text/css"> html * { padding:0; margin:0; } body * { padding:10px 20px; } diff --git a/tests/admin_docs/tests.py b/tests/admin_docs/tests.py index f57a9c8117..6f6f8838f3 100644 --- a/tests/admin_docs/tests.py +++ b/tests/admin_docs/tests.py @@ -153,8 +153,8 @@ class AdminDocViewTests(TestDataMixin, AdminDocsTestCase): def test_simplify_regex(self): tests = ( ('^a', '/a'), - ('^(?P<a>\w+)/b/(?P<c>\w+)/$', '/<a>/b/<c>/'), - ('^(?P<a>\w+)/b/(?P<c>\w+)$', '/<a>/b/<c>'), + (r'^(?P<a>\w+)/b/(?P<c>\w+)/$', '/<a>/b/<c>/'), + (r'^(?P<a>\w+)/b/(?P<c>\w+)$', '/<a>/b/<c>'), ) for pattern, output in tests: self.assertEqual(simplify_regex(pattern), output) diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index 567a8f14f8..84b44931b3 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -717,7 +717,7 @@ class ManageNoSettings(AdminScriptTestCase): args = ['check', 'admin_scripts'] out, err = self.run_manage(args) self.assertNoOutput(out) - self.assertOutput(err, "No module named '?(test_project\.)?settings'?", regex=True) + self.assertOutput(err, r"No module named '?(test_project\.)?settings'?", regex=True) def test_builtin_with_bad_settings(self): "no settings: manage.py builtin commands fail if settings file (from argument) doesn't exist" @@ -950,7 +950,7 @@ class ManageAlternateSettings(AdminScriptTestCase): args = ['check', 'admin_scripts'] out, err = self.run_manage(args) self.assertNoOutput(out) - self.assertOutput(err, "No module named '?(test_project\.)?settings'?", regex=True) + self.assertOutput(err, r"No module named '?(test_project\.)?settings'?", regex=True) def test_builtin_with_settings(self): "alternate: manage.py builtin commands work with settings provided as argument" @@ -985,7 +985,7 @@ class ManageAlternateSettings(AdminScriptTestCase): args = ['noargs_command'] out, err = self.run_manage(args) self.assertNoOutput(out) - self.assertOutput(err, "No module named '?(test_project\.)?settings'?", regex=True) + self.assertOutput(err, r"No module named '?(test_project\.)?settings'?", regex=True) def test_custom_command_with_settings(self): "alternate: manage.py can execute user commands if settings are provided as argument" diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index fd8056513b..ef0e44029f 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -2289,7 +2289,7 @@ class AdminViewStringPrimaryKeyTest(TestCase): cls.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title') cls.pk = ( "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 " - """-_.!~*'() ;/?:@&=+$, <>#%" {}|\^[]`""" + r"""-_.!~*'() ;/?:@&=+$, <>#%" {}|\^[]`""" ) cls.m1 = ModelWithStringPrimaryKey.objects.create(string_pk=cls.pk) content_type_pk = ContentType.objects.get_for_model(ModelWithStringPrimaryKey).pk @@ -4323,7 +4323,7 @@ class SeleniumTests(AdminSeleniumTestCase): self.selenium.find_element_by_id('id_relatedprepopulated_set-2-1-pubdate').send_keys('1981-08-22') self.get_select_option('#id_relatedprepopulated_set-2-1-status', 'option one').click() self.selenium.find_element_by_id('id_relatedprepopulated_set-2-1-name').send_keys( - 'a tÃbűlaŘ inline with ignored ;"&*^\%$#@-/`~ characters' + r'a tÃbűlaŘ inline with ignored ;"&*^\%$#@-/`~ characters' ) slug1 = self.selenium.find_element_by_id('id_relatedprepopulated_set-2-1-slug1').get_attribute('value') slug2 = self.selenium.find_element_by_id('id_relatedprepopulated_set-2-1-slug2').get_attribute('value') @@ -4365,7 +4365,7 @@ class SeleniumTests(AdminSeleniumTestCase): slug2='option-two-and-now-tabular-inline', ) RelatedPrepopulated.objects.get( - name='a tÃbűlaŘ inline with ignored ;"&*^\%$#@-/`~ characters', + name=r'a tÃbűlaŘ inline with ignored ;"&*^\%$#@-/`~ characters', pubdate='1981-08-22', status='option one', slug1='tabular-inline-ignored-characters-1981-08-22', diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py index baf4b8adc6..057771bfa4 100644 --- a/tests/admin_widgets/tests.py +++ b/tests/admin_widgets/tests.py @@ -419,7 +419,7 @@ class AdminFileWidgetTests(TestDataMixin, TestCase): self.assertHTMLEqual( w.render('test', self.album.cover_art), '<p class="file-upload">Currently: <a href="%(STORAGE_URL)salbums/' - 'hybrid_theory.jpg">albums\hybrid_theory.jpg</a> ' + r'hybrid_theory.jpg">albums\hybrid_theory.jpg</a> ' '<span class="clearable-file-input">' '<input type="checkbox" name="test-clear" id="test-clear_id" /> ' '<label for="test-clear_id">Clear</label></span><br />' @@ -441,7 +441,7 @@ class AdminFileWidgetTests(TestDataMixin, TestCase): self.assertContains( response, '<p><a href="%(STORAGE_URL)salbums/hybrid_theory.jpg">' - 'albums\hybrid_theory.jpg</a></p>' % {'STORAGE_URL': default_storage.url('')}, + r'albums\hybrid_theory.jpg</a></p>' % {'STORAGE_URL': default_storage.url('')}, html=True, ) self.assertNotContains( diff --git a/tests/auth_tests/test_models.py b/tests/auth_tests/test_models.py index 5f66a48141..a92f882de0 100644 --- a/tests/auth_tests/test_models.py +++ b/tests/auth_tests/test_models.py @@ -117,8 +117,8 @@ class UserManagerTestCase(TestCase): self.assertEqual(returned, 'normal@domain.com') def test_create_user_email_domain_normalize_with_whitespace(self): - returned = UserManager.normalize_email('email\ with_whitespace@D.COM') - self.assertEqual(returned, 'email\ with_whitespace@d.com') + returned = UserManager.normalize_email(r'email\ with_whitespace@D.COM') + self.assertEqual(returned, r'email\ with_whitespace@d.com') def test_empty_username(self): with self.assertRaisesMessage(ValueError, 'The given username must be set'): diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py index 033a5e8912..e46fdab8e3 100644 --- a/tests/expressions/tests.py +++ b/tests/expressions/tests.py @@ -552,7 +552,7 @@ class ExpressionsTests(TestCase): self.assertEqual(c_qs.get(), c) def test_patterns_escape(self): - """ + r""" Test that special characters (e.g. %, _ and \) stored in database are properly escaped when using a pattern lookup with an expression refs #16731 @@ -584,7 +584,7 @@ class ExpressionsTests(TestCase): ordered=False) def test_insensitive_patterns_escape(self): - """ + r""" Test that special characters (e.g. %, _ and \) stored in database are properly escaped when using a case insensitive pattern lookup with an expression -- refs #16731 diff --git a/tests/field_deconstruction/tests.py b/tests/field_deconstruction/tests.py index 6f4b9fd2cd..1a6385dbf9 100644 --- a/tests/field_deconstruction/tests.py +++ b/tests/field_deconstruction/tests.py @@ -158,11 +158,11 @@ class FieldDeconstructionTests(SimpleTestCase): self.assertEqual(kwargs, {"upload_to": "foo/bar", "max_length": 200}) def test_file_path_field(self): - field = models.FilePathField(match=".*\.txt$") + field = models.FilePathField(match=r".*\.txt$") name, path, args, kwargs = field.deconstruct() self.assertEqual(path, "django.db.models.FilePathField") self.assertEqual(args, []) - self.assertEqual(kwargs, {"match": ".*\.txt$"}) + self.assertEqual(kwargs, {"match": r".*\.txt$"}) field = models.FilePathField(recursive=True, allow_folders=True, max_length=123) name, path, args, kwargs = field.deconstruct() self.assertEqual(path, "django.db.models.FilePathField") diff --git a/tests/forms_tests/field_tests/test_filepathfield.py b/tests/forms_tests/field_tests/test_filepathfield.py index e747189c3e..5c4bd1bbb2 100644 --- a/tests/forms_tests/field_tests/test_filepathfield.py +++ b/tests/forms_tests/field_tests/test_filepathfield.py @@ -53,7 +53,7 @@ class FilePathFieldTest(SimpleTestCase): def test_filepathfield_3(self): path = upath(forms.__file__) path = os.path.dirname(os.path.abspath(path)) + '/' - f = FilePathField(path=path, match='^.*?\.py$') + f = FilePathField(path=path, match=r'^.*?\.py$') f.choices.sort() expected = [ ('/django/forms/__init__.py', '__init__.py'), @@ -72,7 +72,7 @@ class FilePathFieldTest(SimpleTestCase): def test_filepathfield_4(self): path = os.path.abspath(upath(forms.__file__)) path = os.path.dirname(path) + '/' - f = FilePathField(path=path, recursive=True, match='^.*?\.py$') + f = FilePathField(path=path, recursive=True, match=r'^.*?\.py$') f.choices.sort() expected = [ ('/django/forms/__init__.py', '__init__.py'), diff --git a/tests/forms_tests/field_tests/test_regexfield.py b/tests/forms_tests/field_tests/test_regexfield.py index ece958e509..c0e75438f6 100644 --- a/tests/forms_tests/field_tests/test_regexfield.py +++ b/tests/forms_tests/field_tests/test_regexfield.py @@ -48,8 +48,8 @@ class RegexFieldTest(SimpleTestCase): f.clean('123') six.assertRaisesRegex( self, ValidationError, - "'Ensure this value has at least 5 characters \(it has 3\)\.'," - " u?'Enter a valid value\.'", + r"'Ensure this value has at least 5 characters \(it has 3\)\.'," + r" u?'Enter a valid value\.'", f.clean, 'abc' ) self.assertEqual('12345', f.clean('12345')) @@ -60,7 +60,7 @@ class RegexFieldTest(SimpleTestCase): f.clean('12345a') def test_regexfield_unicode_characters(self): - f = RegexField('^\w+$') + f = RegexField(r'^\w+$') self.assertEqual('éèøçÎÎ你好', f.clean('éèøçÎÎ你好')) def test_change_regex_after_init(self): diff --git a/tests/forms_tests/field_tests/test_splitdatetimefield.py b/tests/forms_tests/field_tests/test_splitdatetimefield.py index 1febb57b28..e46eb163a8 100644 --- a/tests/forms_tests/field_tests/test_splitdatetimefield.py +++ b/tests/forms_tests/field_tests/test_splitdatetimefield.py @@ -23,7 +23,7 @@ class SplitDateTimeFieldTest(SimpleTestCase): f.clean('') with self.assertRaisesMessage(ValidationError, "'Enter a list of values.'"): f.clean('hello') - with six.assertRaisesRegex(self, ValidationError, "'Enter a valid date\.', u?'Enter a valid time\.'"): + with six.assertRaisesRegex(self, ValidationError, r"'Enter a valid date\.', u?'Enter a valid time\.'"): f.clean(['hello', 'there']) with self.assertRaisesMessage(ValidationError, "'Enter a valid time.'"): f.clean(['2006-01-10', 'there']) @@ -43,7 +43,7 @@ class SplitDateTimeFieldTest(SimpleTestCase): self.assertIsNone(f.clean(['', ''])) with self.assertRaisesMessage(ValidationError, "'Enter a list of values.'"): f.clean('hello') - with six.assertRaisesRegex(self, ValidationError, "'Enter a valid date\.', u?'Enter a valid time\.'"): + with six.assertRaisesRegex(self, ValidationError, r"'Enter a valid date\.', u?'Enter a valid time\.'"): f.clean(['hello', 'there']) with self.assertRaisesMessage(ValidationError, "'Enter a valid time.'"): f.clean(['2006-01-10', 'there']) diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index f86ab2d43c..44034d310d 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -2914,7 +2914,7 @@ Good luck picking a username that doesn't already exist.</p> self.assertEqual('+61.287654321 ext. 123 (label: )', f.clean(['+61', '287654321', '123'])) six.assertRaisesRegex( self, ValidationError, - "'Enter a complete value\.', u?'Enter an extension\.'", f.clean, ['', '', '', 'Home'] + r"'Enter a complete value\.', u?'Enter an extension\.'", f.clean, ['', '', '', 'Home'] ) with self.assertRaisesMessage(ValidationError, "'Enter a valid country code.'"): f.clean(['61', '287654321', '123', 'Home']) @@ -2930,7 +2930,7 @@ Good luck picking a username that doesn't already exist.</p> self.assertEqual('+61.287654321 ext. 123 (label: )', f.clean(['+61', '287654321', '123'])) six.assertRaisesRegex( self, ValidationError, - "'Enter a complete value\.', u?'Enter an extension\.'", f.clean, ['', '', '', 'Home'] + r"'Enter a complete value\.', u?'Enter an extension\.'", f.clean, ['', '', '', 'Home'] ) with self.assertRaisesMessage(ValidationError, "'Enter a valid country code.'"): f.clean(['61', '287654321', '123', 'Home']) diff --git a/tests/gis_tests/gdal_tests/test_raster.py b/tests/gis_tests/gdal_tests/test_raster.py index 8a0aa09b00..8137aeaeb0 100644 --- a/tests/gis_tests/gdal_tests/test_raster.py +++ b/tests/gis_tests/gdal_tests/test_raster.py @@ -71,7 +71,7 @@ class GDALRasterTests(unittest.TestCase): def test_rs_name_repr(self): self.assertEqual(self.rs_path, self.rs.name) - six.assertRegex(self, repr(self.rs), "<Raster object at 0x\w+>") + six.assertRegex(self, repr(self.rs), r"<Raster object at 0x\w+>") def test_rs_driver(self): self.assertEqual(self.rs.driver.name, 'GTiff') diff --git a/tests/gis_tests/test_spatialrefsys.py b/tests/gis_tests/test_spatialrefsys.py index 652dab3130..93ff3f6263 100644 --- a/tests/gis_tests/test_spatialrefsys.py +++ b/tests/gis_tests/test_spatialrefsys.py @@ -19,7 +19,7 @@ test_srs = ({ # From proj's "cs2cs -le" and Wikipedia (semi-minor only) 'ellipsoid': (6378137.0, 6356752.3, 298.257223563), 'eprec': (1, 1, 9), - 'wkt': re.sub('[\s+]', '', """ + 'wkt': re.sub(r'[\s+]', '', """ GEOGCS["WGS 84", DATUM["WGS_1984", SPHEROID["WGS 84",6378137,298.257223563, diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py index 5ea574530f..75b1d80b79 100644 --- a/tests/i18n/test_extraction.py +++ b/tests/i18n/test_extraction.py @@ -97,7 +97,7 @@ class ExtractorTests(POFileAssertionMixin, RunInTmpDirMixin, SimpleTestCase): self.fail("The token '%s' could not be found in %s, please check the test config" % (token, path)) def assertLocationCommentPresent(self, po_filename, line_number, *comment_parts): - """ + r""" self.assertLocationCommentPresent('django.po', 42, 'dirA', 'dirB', 'foo.py') verifies that the django.po file has a gettext-style location comment of the form @@ -307,7 +307,7 @@ class BasicExtractorTests(ExtractorTests): self, str(ws[2].message), r"The translator-targeted comment 'Translators: ignored i18n " r"comment #4' \(file templates[/\\]comments.thtml, line 8\) " - "was ignored, because it wasn't the last item on the line\." + r"was ignored, because it wasn't the last item on the line\." ) # Now test .po file contents self.assertTrue(os.path.exists(self.PO_FILE)) diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index b0f77cfe06..5a05d16082 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -747,7 +747,7 @@ class FormattingTests(SimpleTestCase): self.maxDiff = 3000 # Catalan locale with translation.override('ca', deactivate=True): - self.assertEqual('j \d\e F \d\e Y', get_format('DATE_FORMAT')) + self.assertEqual(r'j \d\e F \d\e Y', get_format('DATE_FORMAT')) self.assertEqual(1, get_format('FIRST_DAY_OF_WEEK')) self.assertEqual(',', get_format('DECIMAL_SEPARATOR')) self.assertEqual('10:15', time_format(self.t)) diff --git a/tests/lookup/tests.py b/tests/lookup/tests.py index 588e2a9efb..c1b4e9be51 100644 --- a/tests/lookup/tests.py +++ b/tests/lookup/tests.py @@ -411,7 +411,7 @@ class LookupTests(TestCase): Article.objects.create(headline='Article with \\ backslash', pub_date=datetime(2005, 11, 22)) self.assertQuerysetEqual( Article.objects.filter(headline__contains='\\'), - ['<Article: Article with \ backslash>'] + [r'<Article: Article with \ backslash>'] ) def test_exclude(self): diff --git a/tests/migrations/test_executor.py b/tests/migrations/test_executor.py index 847b11c088..93651d74bc 100644 --- a/tests/migrations/test_executor.py +++ b/tests/migrations/test_executor.py @@ -686,7 +686,7 @@ class ExecutorUnitTests(TestCase): self.assertEqual(plan, [(a2_impl, True)]) def test_minimize_rollbacks_branchy(self): - """ + r""" Minimize rollbacks when target has multiple in-app children. a: 1 <---- 3 <--\ @@ -731,7 +731,7 @@ class ExecutorUnitTests(TestCase): self.assertEqual(plan, exp) def test_backwards_nothing_to_do(self): - """ + r""" If the current state satisfies the given target, do nothing. a: 1 <--- 2 diff --git a/tests/migrations/test_graph.py b/tests/migrations/test_graph.py index 472ec5a3ed..ad7e04581c 100644 --- a/tests/migrations/test_graph.py +++ b/tests/migrations/test_graph.py @@ -68,7 +68,7 @@ class GraphTests(SimpleTestCase): ) def test_complex_graph(self): - """ + r""" Tests a complex dependency graph: app_a: 0001 <-- 0002 <--- 0003 <-- 0004 diff --git a/tests/migrations/test_loader.py b/tests/migrations/test_loader.py index e8f3b71ee8..b464209a98 100644 --- a/tests/migrations/test_loader.py +++ b/tests/migrations/test_loader.py @@ -427,7 +427,7 @@ class LoaderTests(TestCase): ]}) def test_loading_squashed_ref_squashed(self): "Tests loading a squashed migration with a new migration referencing it" - """ + r""" The sample migrations are structured like this: app_1 1 --> 2 ---------------------*--> 3 *--> 4 diff --git a/tests/model_forms/models.py b/tests/model_forms/models.py index 0de67eb1f9..1b64477a20 100644 --- a/tests/model_forms/models.py +++ b/tests/model_forms/models.py @@ -169,7 +169,7 @@ class CustomFF(models.Model): class FilePathModel(models.Model): - path = models.FilePathField(path=os.path.dirname(upath(__file__)), match=".*\.py$", blank=True) + path = models.FilePathField(path=os.path.dirname(upath(__file__)), match=r".*\.py$", blank=True) try: diff --git a/tests/template_tests/syntax_tests/test_if_equal.py b/tests/template_tests/syntax_tests/test_if_equal.py index db02b090c0..6124608b08 100644 --- a/tests/template_tests/syntax_tests/test_if_equal.py +++ b/tests/template_tests/syntax_tests/test_if_equal.py @@ -98,7 +98,7 @@ class IfEqualTagTests(SimpleTestCase): @setup({'ifequal-split09': r"{% ifequal a 'slash\man' %}yes{% else %}no{% endifequal %}"}) def test_ifequal_split09(self): - output = self.engine.render_to_string('ifequal-split09', {'a': 'slash\man'}) + output = self.engine.render_to_string('ifequal-split09', {'a': r'slash\man'}) self.assertEqual(output, 'yes') @setup({'ifequal-split10': r"{% ifequal a 'slash\man' %}yes{% else %}no{% endifequal %}"}) diff --git a/tests/utils_tests/test_http.py b/tests/utils_tests/test_http.py index ef4cb90ac4..e90d5e397d 100644 --- a/tests/utils_tests/test_http.py +++ b/tests/utils_tests/test_http.py @@ -95,9 +95,9 @@ class TestUtilsHttp(unittest.TestCase): r'\/example.com', r'/\example.com', 'http:///example.com', - 'http:/\//example.com', - 'http:\/example.com', - 'http:/\example.com', + r'http:/\//example.com', + r'http:\/example.com', + r'http:/\example.com', 'javascript:alert("XSS")', '\njavascript:alert(x)', '\x08//example.com', diff --git a/tests/utils_tests/test_jslex.py b/tests/utils_tests/test_jslex.py index 8308d2830b..dbf0d41b77 100644 --- a/tests/utils_tests/test_jslex.py +++ b/tests/utils_tests/test_jslex.py @@ -67,7 +67,7 @@ class JsTokensTest(SimpleTestCase): (r"""/a[\]]b/""", [r"""regex /a[\]]b/"""]), (r"""/[\]/]/gi""", [r"""regex /[\]/]/gi"""]), (r"""/\[[^\]]+\]/gi""", [r"""regex /\[[^\]]+\]/gi"""]), - (""" + (r""" rexl.re = { NAME: /^(?![0-9])(?:\w)+|^"(?:[^"]|"")+"/, UNQUOTED_LITERAL: /^@(?:(?![0-9])(?:\w|\:)+|^"(?:[^"]|"")+")\[[^\]]+\]/, @@ -86,7 +86,7 @@ class JsTokensTest(SimpleTestCase): "punct }", "punct ;" ]), - (""" + (r""" rexl.re = { NAME: /^(?![0-9])(?:\w)+|^"(?:[^"]|"")+"/, UNQUOTED_LITERAL: /^@(?:(?![0-9])(?:\w|\:)+|^"(?:[^"]|"")+")\[[^\]]+\]/, |
