[Python-checkins] cpython: #27364: fix "incorrect" uses of escape character in the stdlib.

r.david.murray python-checkins at python.org
Thu Sep 8 14:00:26 EDT 2016


https://hg.python.org/cpython/rev/b4cc62473c13
changeset:   103324:b4cc62473c13
user:        R David Murray <rdmurray at bitdance.com>
date:        Thu Sep 08 13:59:53 2016 -0400
summary:
  #27364: fix "incorrect" uses of escape character in the stdlib.

And most of the tools.

Patch by Emanual Barry, reviewed by me, Serhiy Storchaka, and
Martin Panter.

files:
  Lib/_osx_support.py                              |   10 +-
  Lib/csv.py                                       |    8 +-
  Lib/difflib.py                                   |    2 +-
  Lib/distutils/cmd.py                             |    2 +-
  Lib/distutils/command/bdist_msi.py               |    4 +-
  Lib/distutils/command/build_scripts.py           |    2 +-
  Lib/distutils/cygwinccompiler.py                 |    2 +-
  Lib/distutils/msvc9compiler.py                   |    2 +-
  Lib/distutils/sysconfig.py                       |    2 +-
  Lib/distutils/versionpredicate.py                |    2 +-
  Lib/doctest.py                                   |    8 +-
  Lib/email/_header_value_parser.py                |   16 +-
  Lib/email/feedparser.py                          |    8 +-
  Lib/fnmatch.py                                   |    2 +-
  Lib/ftplib.py                                    |    2 +-
  Lib/html/parser.py                               |    4 +-
  Lib/http/client.py                               |    2 +-
  Lib/http/cookiejar.py                            |    6 +-
  Lib/http/cookies.py                              |    2 +-
  Lib/idlelib/calltips.py                          |    2 +-
  Lib/idlelib/idle_test/test_replace.py            |    6 +-
  Lib/idlelib/idle_test/test_searchengine.py       |   12 +-
  Lib/idlelib/paragraph.py                         |    2 +-
  Lib/imaplib.py                                   |    4 +-
  Lib/msilib/__init__.py                           |    2 +-
  Lib/platform.py                                  |   34 +-
  Lib/string.py                                    |    2 +-
  Lib/sysconfig.py                                 |    2 +-
  Lib/test/_test_multiprocessing.py                |    2 +-
  Lib/test/datetimetester.py                       |    4 +-
  Lib/test/re_tests.py                             |    4 +-
  Lib/test/sortperf.py                             |    2 +-
  Lib/test/support/__init__.py                     |    2 +-
  Lib/test/test_asyncio/test_streams.py            |    2 +-
  Lib/test/test_builtin.py                         |    4 +-
  Lib/test/test_capi.py                            |   10 +-
  Lib/test/test_cgi.py                             |    2 +-
  Lib/test/test_codeccallbacks.py                  |    4 +-
  Lib/test/test_codecs.py                          |   14 +-
  Lib/test/test_coroutines.py                      |    8 +-
  Lib/test/test_doctest.py                         |    2 +-
  Lib/test/test_email/test__header_value_parser.py |    4 +-
  Lib/test/test_email/test_email.py                |    2 +-
  Lib/test/test_faulthandler.py                    |    8 +-
  Lib/test/test_fnmatch.py                         |   16 +-
  Lib/test/test_future.py                          |    2 +-
  Lib/test/test_gdb.py                             |   12 +-
  Lib/test/test_getargs2.py                        |   12 +-
  Lib/test/test_htmlparser.py                      |    2 +-
  Lib/test/test_http_cookiejar.py                  |    6 +-
  Lib/test/test_mailcap.py                         |    2 +-
  Lib/test/test_os.py                              |    2 +-
  Lib/test/test_platform.py                        |    4 +-
  Lib/test/test_re.py                              |  192 +++++-----
  Lib/test/test_regrtest.py                        |    4 +-
  Lib/test/test_ssl.py                             |    2 +-
  Lib/test/test_strftime.py                        |    6 +-
  Lib/test/test_strlit.py                          |    4 +-
  Lib/test/test_strptime.py                        |   10 +-
  Lib/test/test_unicode.py                         |    4 +-
  Lib/test/test_urllib.py                          |    4 +-
  Lib/test/test_xmlrpc.py                          |    2 +-
  Lib/unittest/runner.py                           |    2 +-
  Lib/unittest/test/test_assertions.py             |   18 +-
  Lib/unittest/test/test_loader.py                 |    8 +-
  Lib/xml/etree/ElementPath.py                     |   22 +-
  Lib/xml/etree/ElementTree.py                     |    2 +-
  Tools/clinic/clinic.py                           |    2 +-
  Tools/demo/ss1.py                                |    2 +-
  Tools/freeze/winmakemakefile.py                  |    6 +-
  Tools/pybench/CommandLine.py                     |    4 +-
  Tools/pynche/ColorDB.py                          |    6 +-
  Tools/scripts/fixdiv.py                          |    4 +-
  Tools/scripts/h2py.py                            |    8 +-
  Tools/scripts/highlight.py                       |   16 +-
  Tools/scripts/mailerdaemon.py                    |    2 +-
  Tools/scripts/parseentities.py                   |    4 +-
  Tools/scripts/pathfix.py                         |    2 +-
  Tools/scripts/ptags.py                           |    2 +-
  Tools/scripts/svneol.py                          |    2 +-
  Tools/scripts/texi2html.py                       |   10 +-
  Tools/unicode/gencodec.py                        |   10 +-
  setup.py                                         |    4 +-
  83 files changed, 324 insertions(+), 324 deletions(-)


diff --git a/Lib/_osx_support.py b/Lib/_osx_support.py
--- a/Lib/_osx_support.py
+++ b/Lib/_osx_support.py
@@ -210,7 +210,7 @@
         # Do not alter a config var explicitly overridden by env var
         if cv in _config_vars and cv not in os.environ:
             flags = _config_vars[cv]
-            flags = re.sub('-arch\s+\w+\s', ' ', flags, re.ASCII)
+            flags = re.sub(r'-arch\s+\w+\s', ' ', flags, re.ASCII)
             flags = re.sub('-isysroot [^ \t]*', ' ', flags)
             _save_modified_value(_config_vars, cv, flags)
 
@@ -232,7 +232,7 @@
     if 'CC' in os.environ:
         return _config_vars
 
-    if re.search('-arch\s+ppc', _config_vars['CFLAGS']) is not None:
+    if re.search(r'-arch\s+ppc', _config_vars['CFLAGS']) is not None:
         # NOTE: Cannot use subprocess here because of bootstrap
         # issues when building Python itself
         status = os.system(
@@ -251,7 +251,7 @@
             for cv in _UNIVERSAL_CONFIG_VARS:
                 if cv in _config_vars and cv not in os.environ:
                     flags = _config_vars[cv]
-                    flags = re.sub('-arch\s+ppc\w*\s', ' ', flags)
+                    flags = re.sub(r'-arch\s+ppc\w*\s', ' ', flags)
                     _save_modified_value(_config_vars, cv, flags)
 
     return _config_vars
@@ -267,7 +267,7 @@
         for cv in _UNIVERSAL_CONFIG_VARS:
             if cv in _config_vars and '-arch' in _config_vars[cv]:
                 flags = _config_vars[cv]
-                flags = re.sub('-arch\s+\w+\s', ' ', flags)
+                flags = re.sub(r'-arch\s+\w+\s', ' ', flags)
                 flags = flags + ' ' + arch
                 _save_modified_value(_config_vars, cv, flags)
 
@@ -465,7 +465,7 @@
 
             machine = 'fat'
 
-            archs = re.findall('-arch\s+(\S+)', cflags)
+            archs = re.findall(r'-arch\s+(\S+)', cflags)
             archs = tuple(sorted(set(archs)))
 
             if len(archs) == 1:
diff --git a/Lib/csv.py b/Lib/csv.py
--- a/Lib/csv.py
+++ b/Lib/csv.py
@@ -215,10 +215,10 @@
         """
 
         matches = []
-        for restr in ('(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?",
-                      '(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)',   #  ".*?",
-                      '(?P<delim>>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)',  # ,".*?"
-                      '(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'):                            #  ".*?" (no delim, no space)
+        for restr in (r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?",
+                      r'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)',   #  ".*?",
+                      r'(?P<delim>>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)',  # ,".*?"
+                      r'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'):                            #  ".*?" (no delim, no space)
             regexp = re.compile(restr, re.DOTALL | re.MULTILINE)
             matches = regexp.findall(data)
             if matches:
diff --git a/Lib/difflib.py b/Lib/difflib.py
--- a/Lib/difflib.py
+++ b/Lib/difflib.py
@@ -1415,7 +1415,7 @@
     import re
 
     # regular expression for finding intraline change indices
-    change_re = re.compile('(\++|\-+|\^+)')
+    change_re = re.compile(r'(\++|\-+|\^+)')
 
     # create the difference iterator to generate the differences
     diff_lines_iterator = ndiff(fromlines,tolines,linejunk,charjunk)
diff --git a/Lib/distutils/cmd.py b/Lib/distutils/cmd.py
--- a/Lib/distutils/cmd.py
+++ b/Lib/distutils/cmd.py
@@ -221,7 +221,7 @@
         self._ensure_stringlike(option, "string", default)
 
     def ensure_string_list(self, option):
-        """Ensure that 'option' is a list of strings.  If 'option' is
+        r"""Ensure that 'option' is a list of strings.  If 'option' is
         currently a string, we split it either on /,\s*/ or /\s+/, so
         "foo bar baz", "foo,bar,baz", and "foo,   bar baz" all become
         ["foo", "bar", "baz"].
diff --git a/Lib/distutils/command/bdist_msi.py b/Lib/distutils/command/bdist_msi.py
--- a/Lib/distutils/command/bdist_msi.py
+++ b/Lib/distutils/command/bdist_msi.py
@@ -623,7 +623,7 @@
         cost = PyDialog(db, "DiskCostDlg", x, y, w, h, modal, title,
                         "OK", "OK", "OK", bitmap=False)
         cost.text("Title", 15, 6, 200, 15, 0x30003,
-                  "{\DlgFontBold8}Disk Space Requirements")
+                 r"{\DlgFontBold8}Disk Space Requirements")
         cost.text("Description", 20, 20, 280, 20, 0x30003,
                   "The disk space required for the installation of the selected features.")
         cost.text("Text", 20, 53, 330, 60, 3,
@@ -670,7 +670,7 @@
         progress = PyDialog(db, "ProgressDlg", x, y, w, h, modeless, title,
                             "Cancel", "Cancel", "Cancel", bitmap=False)
         progress.text("Title", 20, 15, 200, 15, 0x30003,
-                      "{\DlgFontBold8}[Progress1] [ProductName]")
+                     r"{\DlgFontBold8}[Progress1] [ProductName]")
         progress.text("Text", 35, 65, 300, 30, 3,
                       "Please wait while the Installer [Progress2] [ProductName]. "
                       "This may take several minutes.")
diff --git a/Lib/distutils/command/build_scripts.py b/Lib/distutils/command/build_scripts.py
--- a/Lib/distutils/command/build_scripts.py
+++ b/Lib/distutils/command/build_scripts.py
@@ -51,7 +51,7 @@
 
 
     def copy_scripts(self):
-        """Copy each script listed in 'self.scripts'; if it's marked as a
+        r"""Copy each script listed in 'self.scripts'; if it's marked as a
         Python script in the Unix way (first line matches 'first_line_re',
         ie. starts with "\#!" and contains "python"), then adjust the first
         line to refer to the current Python interpreter as we copy.
diff --git a/Lib/distutils/cygwinccompiler.py b/Lib/distutils/cygwinccompiler.py
--- a/Lib/distutils/cygwinccompiler.py
+++ b/Lib/distutils/cygwinccompiler.py
@@ -368,7 +368,7 @@
         return (CONFIG_H_UNCERTAIN,
                 "couldn't read '%s': %s" % (fn, exc.strerror))
 
-RE_VERSION = re.compile(b'(\d+\.\d+(\.\d+)*)')
+RE_VERSION = re.compile(br'(\d+\.\d+(\.\d+)*)')
 
 def _find_exe_version(cmd):
     """Find the version of an executable by running `cmd` in the shell.
diff --git a/Lib/distutils/msvc9compiler.py b/Lib/distutils/msvc9compiler.py
--- a/Lib/distutils/msvc9compiler.py
+++ b/Lib/distutils/msvc9compiler.py
@@ -716,7 +716,7 @@
                 r"""VC\d{2}\.CRT("|').*?(/>|</assemblyIdentity>)""",
                 re.DOTALL)
             manifest_buf = re.sub(pattern, "", manifest_buf)
-            pattern = "<dependentAssembly>\s*</dependentAssembly>"
+            pattern = r"<dependentAssembly>\s*</dependentAssembly>"
             manifest_buf = re.sub(pattern, "", manifest_buf)
             # Now see if any other assemblies are referenced - if not, we
             # don't want a manifest embedded.
diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -278,7 +278,7 @@
 
 # Regexes needed for parsing Makefile (and similar syntaxes,
 # like old-style Setup files).
-_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
+_variable_rx = re.compile(r"([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
 _findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
 _findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
 
diff --git a/Lib/distutils/versionpredicate.py b/Lib/distutils/versionpredicate.py
--- a/Lib/distutils/versionpredicate.py
+++ b/Lib/distutils/versionpredicate.py
@@ -154,7 +154,7 @@
     global _provision_rx
     if _provision_rx is None:
         _provision_rx = re.compile(
-            "([a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*)(?:\s*\(\s*([^)\s]+)\s*\))?$",
+            r"([a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*)(?:\s*\(\s*([^)\s]+)\s*\))?$",
             re.ASCII)
     value = value.strip()
     m = _provision_rx.match(value)
diff --git a/Lib/doctest.py b/Lib/doctest.py
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -765,7 +765,7 @@
 
     # This regular expression finds the indentation of every non-blank
     # line in a string.
-    _INDENT_RE = re.compile('^([ ]*)(?=\S)', re.MULTILINE)
+    _INDENT_RE = re.compile(r'^([ ]*)(?=\S)', re.MULTILINE)
 
     def _min_indent(self, s):
         "Return the minimum indentation of any non-blank line in `s`"
@@ -1106,7 +1106,7 @@
         if lineno is not None:
             if source_lines is None:
                 return lineno+1
-            pat = re.compile('(^|.*:)\s*\w*("|\')')
+            pat = re.compile(r'(^|.*:)\s*\w*("|\')')
             for lineno in range(lineno, len(source_lines)):
                 if pat.match(source_lines[lineno]):
                     return lineno
@@ -1608,11 +1608,11 @@
         # blank line, unless the DONT_ACCEPT_BLANKLINE flag is used.
         if not (optionflags & DONT_ACCEPT_BLANKLINE):
             # Replace <BLANKLINE> in want with a blank line.
-            want = re.sub('(?m)^%s\s*?$' % re.escape(BLANKLINE_MARKER),
+            want = re.sub(r'(?m)^%s\s*?$' % re.escape(BLANKLINE_MARKER),
                           '', want)
             # If a line in got contains only spaces, then remove the
             # spaces.
-            got = re.sub('(?m)^\s*?$', '', got)
+            got = re.sub(r'(?m)^\s*?$', '', got)
             if got == want:
                 return True
 
diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py
--- a/Lib/email/_header_value_parser.py
+++ b/Lib/email/_header_value_parser.py
@@ -652,8 +652,8 @@
         if value.token_type == 'comment':
             return str(value)
         return str(value).replace('\\', '\\\\').replace(
-                                  '(', '\(').replace(
-                                  ')', '\)')
+                                  '(', r'\(').replace(
+                                  ')', r'\)')
 
     @property
     def content(self):
@@ -1356,15 +1356,15 @@
 
 _wsp_splitter = re.compile(r'([{}]+)'.format(''.join(WSP))).split
 _non_atom_end_matcher = re.compile(r"[^{}]+".format(
-    ''.join(ATOM_ENDS).replace('\\','\\\\').replace(']','\]'))).match
+    ''.join(ATOM_ENDS).replace('\\','\\\\').replace(']',r'\]'))).match
 _non_printable_finder = re.compile(r"[\x00-\x20\x7F]").findall
 _non_token_end_matcher = re.compile(r"[^{}]+".format(
-    ''.join(TOKEN_ENDS).replace('\\','\\\\').replace(']','\]'))).match
+    ''.join(TOKEN_ENDS).replace('\\','\\\\').replace(']',r'\]'))).match
 _non_attribute_end_matcher = re.compile(r"[^{}]+".format(
-    ''.join(ATTRIBUTE_ENDS).replace('\\','\\\\').replace(']','\]'))).match
+    ''.join(ATTRIBUTE_ENDS).replace('\\','\\\\').replace(']',r'\]'))).match
 _non_extended_attribute_end_matcher = re.compile(r"[^{}]+".format(
     ''.join(EXTENDED_ATTRIBUTE_ENDS).replace(
-                                    '\\','\\\\').replace(']','\]'))).match
+                                    '\\','\\\\').replace(']',r'\]'))).match
 
 def _validate_xtext(xtext):
     """If input token contains ASCII non-printables, register a defect."""
@@ -1517,7 +1517,7 @@
     return unstructured
 
 def get_qp_ctext(value):
-    """ctext = <printable ascii except \ ( )>
+    r"""ctext = <printable ascii except \ ( )>
 
     This is not the RFC ctext, since we are handling nested comments in comment
     and unquoting quoted-pairs here.  We allow anything except the '()'
@@ -1878,7 +1878,7 @@
     return obs_local_part, value
 
 def get_dtext(value):
-    """ dtext = <printable ascii except \ [ ]> / obs-dtext
+    r""" dtext = <printable ascii except \ [ ]> / obs-dtext
         obs-dtext = obs-NO-WS-CTL / quoted-pair
 
     We allow anything except the excluded characters, but if we find any
diff --git a/Lib/email/feedparser.py b/Lib/email/feedparser.py
--- a/Lib/email/feedparser.py
+++ b/Lib/email/feedparser.py
@@ -29,10 +29,10 @@
 from collections import deque
 from io import StringIO
 
-NLCRE = re.compile('\r\n|\r|\n')
-NLCRE_bol = re.compile('(\r\n|\r|\n)')
-NLCRE_eol = re.compile('(\r\n|\r|\n)\Z')
-NLCRE_crack = re.compile('(\r\n|\r|\n)')
+NLCRE = re.compile(r'\r\n|\r|\n')
+NLCRE_bol = re.compile(r'(\r\n|\r|\n)')
+NLCRE_eol = re.compile(r'(\r\n|\r|\n)\Z')
+NLCRE_crack = re.compile(r'(\r\n|\r|\n)')
 # RFC 2822 $3.6.8 Optional fields.  ftext is %d33-57 / %d59-126, Any character
 # except controls, SP, and ":".
 headerRE = re.compile(r'^(From |[\041-\071\073-\176]*:|[\t ])')
diff --git a/Lib/fnmatch.py b/Lib/fnmatch.py
--- a/Lib/fnmatch.py
+++ b/Lib/fnmatch.py
@@ -106,4 +106,4 @@
                 res = '%s[%s]' % (res, stuff)
         else:
             res = res + re.escape(c)
-    return res + '\Z(?ms)'
+    return res + r'\Z(?ms)'
diff --git a/Lib/ftplib.py b/Lib/ftplib.py
--- a/Lib/ftplib.py
+++ b/Lib/ftplib.py
@@ -821,7 +821,7 @@
     if _150_re is None:
         import re
         _150_re = re.compile(
-            "150 .* \((\d+) bytes\)", re.IGNORECASE | re.ASCII)
+            r"150 .* \((\d+) bytes\)", re.IGNORECASE | re.ASCII)
     m = _150_re.match(resp)
     if not m:
         return None
diff --git a/Lib/html/parser.py b/Lib/html/parser.py
--- a/Lib/html/parser.py
+++ b/Lib/html/parser.py
@@ -34,7 +34,7 @@
 #     explode, so don't do it.
 # see http://www.w3.org/TR/html5/tokenization.html#tag-open-state
 # and http://www.w3.org/TR/html5/tokenization.html#tag-name-state
-tagfind_tolerant = re.compile('([a-zA-Z][^\t\n\r\f />\x00]*)(?:\s|/(?!>))*')
+tagfind_tolerant = re.compile(r'([a-zA-Z][^\t\n\r\f />\x00]*)(?:\s|/(?!>))*')
 attrfind_tolerant = re.compile(
     r'((?<=[\'"\s/])[^\s/>][^\s/=>]*)(\s*=+\s*'
     r'(\'[^\']*\'|"[^"]*"|(?![\'"])[^>\s]*))?(?:\s|/(?!>))*')
@@ -56,7 +56,7 @@
 endendtag = re.compile('>')
 # the HTML 5 spec, section 8.1.2.2, doesn't allow spaces between
 # </ and the tag name, so maybe this should be fixed
-endtagfind = re.compile('</\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>')
+endtagfind = re.compile(r'</\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>')
 
 
 
diff --git a/Lib/http/client.py b/Lib/http/client.py
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -1,4 +1,4 @@
-"""HTTP/1.1 client library
+r"""HTTP/1.1 client library
 
 <intro stuff goes here>
 <other stuff, too>
diff --git a/Lib/http/cookiejar.py b/Lib/http/cookiejar.py
--- a/Lib/http/cookiejar.py
+++ b/Lib/http/cookiejar.py
@@ -200,7 +200,7 @@
 
 STRICT_DATE_RE = re.compile(
     r"^[SMTWF][a-z][a-z], (\d\d) ([JFMASOND][a-z][a-z]) "
-    "(\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT$", re.ASCII)
+    r"(\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT$", re.ASCII)
 WEEKDAY_RE = re.compile(
     r"^(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)[a-z]*,?\s*", re.I | re.ASCII)
 LOOSE_HTTP_DATE_RE = re.compile(
@@ -277,7 +277,7 @@
     return _str2time(day, mon, yr, hr, min, sec, tz)
 
 ISO_DATE_RE = re.compile(
-    """^
+    r"""^
     (\d{4})              # year
        [-\/]?
     (\d\d?)              # numerical month
@@ -411,7 +411,7 @@
                 pairs = []
             else:
                 # skip junk
-                non_junk, nr_junk_chars = re.subn("^[=\s;]*", "", text)
+                non_junk, nr_junk_chars = re.subn(r"^[=\s;]*", "", text)
                 assert nr_junk_chars > 0, (
                     "split_header_words bug: '%s', '%s', %s" %
                     (orig_text, text, pairs))
diff --git a/Lib/http/cookies.py b/Lib/http/cookies.py
--- a/Lib/http/cookies.py
+++ b/Lib/http/cookies.py
@@ -456,7 +456,7 @@
 #
 
 _LegalKeyChars  = r"\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\="
-_LegalValueChars = _LegalKeyChars + '\[\]'
+_LegalValueChars = _LegalKeyChars + r'\[\]'
 _CookiePattern = re.compile(r"""
     (?x)                           # This is a verbose pattern
     \s*                            # Optional whitespace at start of cookie
diff --git a/Lib/idlelib/calltips.py b/Lib/idlelib/calltips.py
--- a/Lib/idlelib/calltips.py
+++ b/Lib/idlelib/calltips.py
@@ -120,7 +120,7 @@
 _MAX_COLS = 85
 _MAX_LINES = 5  # enough for bytes
 _INDENT = ' '*4  # for wrapped signatures
-_first_param = re.compile('(?<=\()\w*\,?\s*')
+_first_param = re.compile(r'(?<=\()\w*\,?\s*')
 _default_callable_argspec = "See source or doc"
 
 
diff --git a/Lib/idlelib/idle_test/test_replace.py b/Lib/idlelib/idle_test/test_replace.py
--- a/Lib/idlelib/idle_test/test_replace.py
+++ b/Lib/idlelib/idle_test/test_replace.py
@@ -91,7 +91,7 @@
         text.mark_set('insert', 'end')
         text.insert('insert', '\nline42:')
         before_text = text.get('1.0', 'end')
-        pv.set('[a-z][\d]+')
+        pv.set(r'[a-z][\d]+')
         replace()
         after_text = text.get('1.0', 'end')
         equal(before_text, after_text)
@@ -192,7 +192,7 @@
         self.engine.revar.set(True)
 
         before_text = text.get('1.0', 'end')
-        pv.set('[a-z][\d]+')
+        pv.set(r'[a-z][\d]+')
         rv.set('hello')
         replace()
         after_text = text.get('1.0', 'end')
@@ -207,7 +207,7 @@
         self.assertIn('error', showerror.title)
         self.assertIn('Empty', showerror.message)
 
-        pv.set('[\d')
+        pv.set(r'[\d')
         replace()
         self.assertIn('error', showerror.title)
         self.assertIn('Pattern', showerror.message)
diff --git a/Lib/idlelib/idle_test/test_searchengine.py b/Lib/idlelib/idle_test/test_searchengine.py
--- a/Lib/idlelib/idle_test/test_searchengine.py
+++ b/Lib/idlelib/idle_test/test_searchengine.py
@@ -139,10 +139,10 @@
 
     def test_setcookedpat(self):
         engine = self.engine
-        engine.setcookedpat('\s')
-        self.assertEqual(engine.getpat(), '\s')
+        engine.setcookedpat(r'\s')
+        self.assertEqual(engine.getpat(), r'\s')
         engine.revar.set(1)
-        engine.setcookedpat('\s')
+        engine.setcookedpat(r'\s')
         self.assertEqual(engine.getpat(), r'\\s')
 
     def test_getcookedpat(self):
@@ -156,10 +156,10 @@
         Equal(engine.getcookedpat(), r'\bhello\b')
         engine.wordvar.set(False)
 
-        engine.setpat('\s')
+        engine.setpat(r'\s')
         Equal(engine.getcookedpat(), r'\\s')
         engine.revar.set(True)
-        Equal(engine.getcookedpat(), '\s')
+        Equal(engine.getcookedpat(), r'\s')
 
     def test_getprog(self):
         engine = self.engine
@@ -282,7 +282,7 @@
         cls.pat = re.compile('target')
         cls.res = (2, (10, 16))  # line, slice indexes of 'target'
         cls.failpat = re.compile('xyz')  # not in text
-        cls.emptypat = re.compile('\w*')  # empty match possible
+        cls.emptypat = re.compile(r'\w*')  # empty match possible
 
     def make_search(self, func):
         def search(pat, line, col, wrap, ok=0):
diff --git a/Lib/idlelib/paragraph.py b/Lib/idlelib/paragraph.py
--- a/Lib/idlelib/paragraph.py
+++ b/Lib/idlelib/paragraph.py
@@ -130,7 +130,7 @@
     partial = indent1
     while i < n and not is_all_white(lines[i]):
         # XXX Should take double space after period (etc.) into account
-        words = re.split("(\s+)", lines[i])
+        words = re.split(r"(\s+)", lines[i])
         for j in range(0, len(words), 2):
             word = words[j]
             if not word:
diff --git a/Lib/imaplib.py b/Lib/imaplib.py
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -132,7 +132,7 @@
 
 class IMAP4:
 
-    """IMAP4 client class.
+    r"""IMAP4 client class.
 
     Instantiate with: IMAP4([host[, port]])
 
@@ -1535,7 +1535,7 @@
     ('select', ('/tmp/yyz 2',)),
     ('search', (None, 'SUBJECT', 'test')),
     ('fetch', ('1', '(FLAGS INTERNALDATE RFC822)')),
-    ('store', ('1', 'FLAGS', '(\Deleted)')),
+    ('store', ('1', 'FLAGS', r'(\Deleted)')),
     ('namespace', ()),
     ('expunge', ()),
     ('recent', ()),
diff --git a/Lib/msilib/__init__.py b/Lib/msilib/__init__.py
--- a/Lib/msilib/__init__.py
+++ b/Lib/msilib/__init__.py
@@ -289,7 +289,7 @@
     def make_short(self, file):
         oldfile = file
         file = file.replace('+', '_')
-        file = ''.join(c for c in file if not c in ' "/\[]:;=,')
+        file = ''.join(c for c in file if not c in r' "/\[]:;=,')
         parts = file.split(".")
         if len(parts) > 1:
             prefix = "".join(parts[:-1]).upper()
diff --git a/Lib/platform.py b/Lib/platform.py
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -251,13 +251,13 @@
 
 _release_filename = re.compile(r'(\w+)[-_](release|version)', re.ASCII)
 _lsb_release_version = re.compile(r'(.+)'
-                                   ' release '
-                                   '([\d.]+)'
-                                   '[^(]*(?:\((.+)\))?', re.ASCII)
+                                  r' release '
+                                  r'([\d.]+)'
+                                  r'[^(]*(?:\((.+)\))?', re.ASCII)
 _release_version = re.compile(r'([^0-9]+)'
-                               '(?: release )?'
-                               '([\d.]+)'
-                               '[^(]*(?:\((.+)\))?', re.ASCII)
+                              r'(?: release )?'
+                              r'([\d.]+)'
+                              r'[^(]*(?:\((.+)\))?', re.ASCII)
 
 # See also http://www.novell.com/coolsolutions/feature/11251.html
 # and http://linuxmafia.com/faq/Admin/release-files.html
@@ -407,8 +407,8 @@
     return version
 
 _ver_output = re.compile(r'(?:([\w ]+) ([\w.]+) '
-                         '.*'
-                         '\[.* ([\d.]+)\])')
+                         r'.*'
+                         r'\[.* ([\d.]+)\])')
 
 # Examples of VER command output:
 #
@@ -1153,22 +1153,22 @@
 
 _ironpython_sys_version_parser = re.compile(
     r'IronPython\s*'
-    '([\d\.]+)'
-    '(?: \(([\d\.]+)\))?'
-    ' on (.NET [\d\.]+)', re.ASCII)
+    r'([\d\.]+)'
+    r'(?: \(([\d\.]+)\))?'
+    r' on (.NET [\d\.]+)', re.ASCII)
 
 # IronPython covering 2.6 and 2.7
 _ironpython26_sys_version_parser = re.compile(
     r'([\d.]+)\s*'
-    '\(IronPython\s*'
-    '[\d.]+\s*'
-    '\(([\d.]+)\) on ([\w.]+ [\d.]+(?: \(\d+-bit\))?)\)'
+    r'\(IronPython\s*'
+    r'[\d.]+\s*'
+    r'\(([\d.]+)\) on ([\w.]+ [\d.]+(?: \(\d+-bit\))?)\)'
 )
 
 _pypy_sys_version_parser = re.compile(
     r'([\w.+]+)\s*'
-    '\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*'
-    '\[PyPy [^\]]+\]?')
+    r'\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*'
+    r'\[PyPy [^\]]+\]?')
 
 _sys_version_cache = {}
 
@@ -1403,7 +1403,7 @@
             # see issue #1322 for more information
             warnings.filterwarnings(
                 'ignore',
-                'dist\(\) and linux_distribution\(\) '
+                r'dist\(\) and linux_distribution\(\) '
                 'functions are deprecated .*',
                 PendingDeprecationWarning,
             )
diff --git a/Lib/string.py b/Lib/string.py
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -28,7 +28,7 @@
 digits = '0123456789'
 hexdigits = digits + 'abcdef' + 'ABCDEF'
 octdigits = '01234567'
-punctuation = """!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
+punctuation = r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
 printable = digits + ascii_letters + punctuation + whitespace
 
 # Functions which aren't available as string methods.
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -215,7 +215,7 @@
     # Regexes needed for parsing Makefile (and similar syntaxes,
     # like old-style Setup files).
     import re
-    _variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
+    _variable_rx = re.compile(r"([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
     _findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
     _findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
 
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -3857,7 +3857,7 @@
         p.stderr.close()
         expected = 'semaphore_tracker: There appear to be 2 leaked semaphores'
         self.assertRegex(err, expected)
-        self.assertRegex(err, 'semaphore_tracker: %r: \[Errno' % name1)
+        self.assertRegex(err, r'semaphore_tracker: %r: \[Errno' % name1)
 
 #
 # Mixins
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -4001,12 +4001,12 @@
                              datetime(xx, xx, xx, xx, xx, xx, xx))
 
         with self.assertRaisesRegex(TypeError, '^an integer is required '
-                                               '\(got type str\)$'):
+                                              r'\(got type str\)$'):
             datetime(10, 10, '10')
 
         f10 = Number(10.9)
         with self.assertRaisesRegex(TypeError, '^__int__ returned non-int '
-                                               '\(type float\)$'):
+                                              r'\(type float\)$'):
             datetime(10, 10, f10)
 
         class Float(float):
diff --git a/Lib/test/re_tests.py b/Lib/test/re_tests.py
--- a/Lib/test/re_tests.py
+++ b/Lib/test/re_tests.py
@@ -158,7 +158,7 @@
     ('(abc', '-', SYNTAX_ERROR),
     ('a]', 'a]', SUCCEED, 'found', 'a]'),
     ('a[]]b', 'a]b', SUCCEED, 'found', 'a]b'),
-    ('a[\]]b', 'a]b', SUCCEED, 'found', 'a]b'),
+    ('a[\\]]b', 'a]b', SUCCEED, 'found', 'a]b'),
     ('a[^bc]d', 'aed', SUCCEED, 'found', 'aed'),
     ('a[^bc]d', 'abd', FAIL),
     ('a[^-b]c', 'adc', SUCCEED, 'found', 'adc'),
@@ -551,7 +551,7 @@
     # lookbehind: split by : but not if it is escaped by -.
     ('(?<!-):(.*?)(?<!-):', 'a:bc-:de:f', SUCCEED, 'g1', 'bc-:de' ),
     # escaping with \ as we know it
-    ('(?<!\\\):(.*?)(?<!\\\):', 'a:bc\\:de:f', SUCCEED, 'g1', 'bc\\:de' ),
+    ('(?<!\\\\):(.*?)(?<!\\\\):', 'a:bc\\:de:f', SUCCEED, 'g1', 'bc\\:de' ),
     # terminating with ' and escaping with ? as in edifact
     ("(?<!\\?)'(.*?)(?<!\\?)'", "a'bc?'de'f", SUCCEED, 'g1', "bc?'de" ),
 
diff --git a/Lib/test/sortperf.py b/Lib/test/sortperf.py
--- a/Lib/test/sortperf.py
+++ b/Lib/test/sortperf.py
@@ -64,7 +64,7 @@
     flush()
 
 def tabulate(r):
-    """Tabulate sort speed for lists of various sizes.
+    r"""Tabulate sort speed for lists of various sizes.
 
     The sizes are 2**i for i in r (the argument, a list).
 
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -2202,7 +2202,7 @@
                     os.setxattr(fp.fileno(), b"user.test", b"")
                     # Kernels < 2.6.39 don't respect setxattr flags.
                     kernel_version = platform.release()
-                    m = re.match("2.6.(\d{1,2})", kernel_version)
+                    m = re.match(r"2.6.(\d{1,2})", kernel_version)
                     can = m is None or int(m.group(1)) >= 39
                 except OSError:
                     can = False
diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py
--- a/Lib/test/test_asyncio/test_streams.py
+++ b/Lib/test/test_asyncio/test_streams.py
@@ -831,7 +831,7 @@
         stream._waiter = asyncio.Future(loop=self.loop)
         self.assertRegex(
             repr(stream),
-            "<StreamReader w=<Future pending[\S ]*>>")
+            r"<StreamReader w=<Future pending[\S ]*>>")
         stream._waiter.set_result(None)
         self.loop.run_until_complete(stream._waiter)
         stream._waiter = None
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -83,7 +83,7 @@
         ('', ValueError),
         (' ', ValueError),
         ('  \t\t  ', ValueError),
-        (str(b'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
+        (str(br'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
         (chr(0x200), ValueError),
 ]
 
@@ -105,7 +105,7 @@
         ('', ValueError),
         (' ', ValueError),
         ('  \t\t  ', ValueError),
-        (str(b'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
+        (str(br'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
         (chr(0x200), ValueError),
 ]
 
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -533,21 +533,21 @@
         parse((1, 2, 3), {}, b'OOO', ['', '', 'a'])
         parse((1, 2), {'a': 3}, b'OOO', ['', '', 'a'])
         with self.assertRaisesRegex(TypeError,
-                'Function takes at least 2 positional arguments \(1 given\)'):
+               r'Function takes at least 2 positional arguments \(1 given\)'):
             parse((1,), {'a': 3}, b'OOO', ['', '', 'a'])
         parse((1,), {}, b'O|OO', ['', '', 'a'])
         with self.assertRaisesRegex(TypeError,
-                'Function takes at least 1 positional arguments \(0 given\)'):
+               r'Function takes at least 1 positional arguments \(0 given\)'):
             parse((), {}, b'O|OO', ['', '', 'a'])
         parse((1, 2), {'a': 3}, b'OO$O', ['', '', 'a'])
         with self.assertRaisesRegex(TypeError,
-                'Function takes exactly 2 positional arguments \(1 given\)'):
+               r'Function takes exactly 2 positional arguments \(1 given\)'):
             parse((1,), {'a': 3}, b'OO$O', ['', '', 'a'])
         parse((1,), {}, b'O|O$O', ['', '', 'a'])
         with self.assertRaisesRegex(TypeError,
-                'Function takes at least 1 positional arguments \(0 given\)'):
+               r'Function takes at least 1 positional arguments \(0 given\)'):
             parse((), {}, b'O|O$O', ['', '', 'a'])
-        with self.assertRaisesRegex(SystemError, 'Empty parameter name after \$'):
+        with self.assertRaisesRegex(SystemError, r'Empty parameter name after \$'):
             parse((1,), {}, b'O|$OO', ['', '', 'a'])
         with self.assertRaisesRegex(SystemError, 'Empty keyword'):
             parse((1,), {}, b'O|OO', ['', 'a', ''])
diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py
--- a/Lib/test/test_cgi.py
+++ b/Lib/test/test_cgi.py
@@ -148,7 +148,7 @@
     def test_escape(self):
         # cgi.escape() is deprecated.
         with warnings.catch_warnings():
-            warnings.filterwarnings('ignore', 'cgi\.escape',
+            warnings.filterwarnings('ignore', r'cgi\.escape',
                                      DeprecationWarning)
             self.assertEqual("test & string", cgi.escape("test & string"))
             self.assertEqual("<test string>", cgi.escape("<test string>"))
diff --git a/Lib/test/test_codeccallbacks.py b/Lib/test/test_codeccallbacks.py
--- a/Lib/test/test_codeccallbacks.py
+++ b/Lib/test/test_codeccallbacks.py
@@ -280,12 +280,12 @@
         )
 
         self.assertEqual(
-            b"\\u3042\u3xxx".decode("unicode-escape", "test.handler1"),
+            b"\\u3042\\u3xxx".decode("unicode-escape", "test.handler1"),
             "\u3042[<92><117><51>]xxx"
         )
 
         self.assertEqual(
-            b"\\u3042\u3xx".decode("unicode-escape", "test.handler1"),
+            b"\\u3042\\u3xx".decode("unicode-escape", "test.handler1"),
             "\u3042[<92><117><51>]xx"
         )
 
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -2703,8 +2703,8 @@
         bad_input = "bad input type"
         for encoding in bytes_transform_encodings:
             with self.subTest(encoding=encoding):
-                fmt = ( "{!r} is not a text encoding; "
-                        "use codecs.encode\(\) to handle arbitrary codecs")
+                fmt = (r"{!r} is not a text encoding; "
+                       r"use codecs.encode\(\) to handle arbitrary codecs")
                 msg = fmt.format(encoding)
                 with self.assertRaisesRegex(LookupError, msg) as failure:
                     bad_input.encode(encoding)
@@ -2713,7 +2713,7 @@
     def test_text_to_binary_blacklists_text_transforms(self):
         # Check str.encode gives a good error message for str -> str codecs
         msg = (r"^'rot_13' is not a text encoding; "
-                "use codecs.encode\(\) to handle arbitrary codecs")
+               r"use codecs.encode\(\) to handle arbitrary codecs")
         with self.assertRaisesRegex(LookupError, msg):
             "just an example message".encode("rot_13")
 
@@ -2725,7 +2725,7 @@
             with self.subTest(encoding=encoding):
                 encoded_data = codecs.encode(data, encoding)
                 fmt = (r"{!r} is not a text encoding; "
-                        "use codecs.decode\(\) to handle arbitrary codecs")
+                       r"use codecs.decode\(\) to handle arbitrary codecs")
                 msg = fmt.format(encoding)
                 with self.assertRaisesRegex(LookupError, msg):
                     encoded_data.decode(encoding)
@@ -2737,7 +2737,7 @@
         for bad_input in (b"immutable", bytearray(b"mutable")):
             with self.subTest(bad_input=bad_input):
                 msg = (r"^'rot_13' is not a text encoding; "
-                        "use codecs.decode\(\) to handle arbitrary codecs")
+                       r"use codecs.decode\(\) to handle arbitrary codecs")
                 with self.assertRaisesRegex(LookupError, msg) as failure:
                     bad_input.decode("rot_13")
                 self.assertIsNone(failure.exception.__cause__)
@@ -2956,12 +2956,12 @@
         self.assertEqual(decoded, b"not str!")
         # Text model methods should complain
         fmt = (r"^{!r} encoder returned 'str' instead of 'bytes'; "
-                "use codecs.encode\(\) to encode to arbitrary types$")
+               r"use codecs.encode\(\) to encode to arbitrary types$")
         msg = fmt.format(self.codec_name)
         with self.assertRaisesRegex(TypeError, msg):
             "str_input".encode(self.codec_name)
         fmt = (r"^{!r} decoder returned 'bytes' instead of 'str'; "
-                "use codecs.decode\(\) to decode to arbitrary types$")
+               r"use codecs.decode\(\) to decode to arbitrary types$")
         msg = fmt.format(self.codec_name)
         with self.assertRaisesRegex(TypeError, msg):
             b"bytes input".decode(self.codec_name)
diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py
--- a/Lib/test/test_coroutines.py
+++ b/Lib/test/test_coroutines.py
@@ -891,7 +891,7 @@
             return await Awaitable()
 
         with self.assertRaisesRegex(
-            TypeError, "__await__\(\) returned a coroutine"):
+            TypeError, r"__await__\(\) returned a coroutine"):
 
             run_async(foo())
 
@@ -1333,7 +1333,7 @@
 
         with self.assertRaisesRegex(
                 TypeError,
-                "async for' received an invalid object.*__aiter.*\: I"):
+                r"async for' received an invalid object.*__aiter.*\: I"):
 
             run_async(foo())
 
@@ -1667,8 +1667,8 @@
         try:
             with silence_coro_gc(), self.assertRaisesRegex(
                 RuntimeError,
-                "coroutine wrapper.*\.wrapper at 0x.*attempted to "
-                "recursively wrap .* wrap .*"):
+                r"coroutine wrapper.*\.wrapper at 0x.*attempted to "
+                r"recursively wrap .* wrap .*"):
 
                 foo()
         finally:
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -291,7 +291,7 @@
     ...
     ... Non-example text.
     ...
-    ...     >>> print('another\example')
+    ...     >>> print('another\\example')
     ...     another
     ...     example
     ... '''
diff --git a/Lib/test/test_email/test__header_value_parser.py b/Lib/test/test_email/test__header_value_parser.py
--- a/Lib/test/test_email/test__header_value_parser.py
+++ b/Lib/test/test_email/test__header_value_parser.py
@@ -581,7 +581,7 @@
 
     def test_get_comment_quoted_parens(self):
         self._test_get_x(parser.get_comment,
-            '(foo\) \(\)bar)', '(foo\) \(\)bar)', ' ', [], '', ['foo) ()bar'])
+            r'(foo\) \(\)bar)', r'(foo\) \(\)bar)', ' ', [], '', ['foo) ()bar'])
 
     def test_get_comment_non_printable(self):
         self._test_get_x(parser.get_comment,
@@ -625,7 +625,7 @@
 
     def test_get_comment_qs_in_nested_comment(self):
         comment = self._test_get_x(parser.get_comment,
-            '(foo (b\)))', '(foo (b\)))', ' ', [], '', ['foo (b\))'])
+            r'(foo (b\)))', r'(foo (b\)))', ' ', [], '', [r'foo (b\))'])
         self.assertEqual(comment[2].content, 'b)')
 
     # get_cfws
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -3040,7 +3040,7 @@
 
     def test_escape_backslashes(self):
         self.assertEqual(
-            utils.formataddr(('Arthur \Backslash\ Foobar', 'person at dom.ain')),
+            utils.formataddr((r'Arthur \Backslash\ Foobar', 'person at dom.ain')),
             r'"Arthur \\Backslash\\ Foobar" <person at dom.ain>')
         a = r'Arthur \Backslash\ Foobar'
         b = 'person at dom.ain'
diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py
--- a/Lib/test/test_faulthandler.py
+++ b/Lib/test/test_faulthandler.py
@@ -93,7 +93,7 @@
                 header = 'Thread 0x[0-9a-f]+'
         else:
             header = 'Stack'
-        regex = """
+        regex = r"""
             ^{fatal_error}
 
             {header} \(most recent call first\):
@@ -490,7 +490,7 @@
             lineno = 8
         else:
             lineno = 10
-        regex = """
+        regex = r"""
             ^Thread 0x[0-9a-f]+ \(most recent call first\):
             (?:  File ".*threading.py", line [0-9]+ in [_a-z]+
             ){{1,3}}  File "<string>", line 23 in run
@@ -669,9 +669,9 @@
         trace = '\n'.join(trace)
         if not unregister:
             if all_threads:
-                regex = 'Current thread 0x[0-9a-f]+ \(most recent call first\):\n'
+                regex = r'Current thread 0x[0-9a-f]+ \(most recent call first\):\n'
             else:
-                regex = 'Stack \(most recent call first\):\n'
+                regex = r'Stack \(most recent call first\):\n'
             regex = expected_traceback(14, 32, regex)
             self.assertRegex(trace, regex)
         else:
diff --git a/Lib/test/test_fnmatch.py b/Lib/test/test_fnmatch.py
--- a/Lib/test/test_fnmatch.py
+++ b/Lib/test/test_fnmatch.py
@@ -62,14 +62,14 @@
 class TranslateTestCase(unittest.TestCase):
 
     def test_translate(self):
-        self.assertEqual(translate('*'), '.*\Z(?ms)')
-        self.assertEqual(translate('?'), '.\Z(?ms)')
-        self.assertEqual(translate('a?b*'), 'a.b.*\Z(?ms)')
-        self.assertEqual(translate('[abc]'), '[abc]\Z(?ms)')
-        self.assertEqual(translate('[]]'), '[]]\Z(?ms)')
-        self.assertEqual(translate('[!x]'), '[^x]\Z(?ms)')
-        self.assertEqual(translate('[^x]'), '[\\^x]\Z(?ms)')
-        self.assertEqual(translate('[x'), '\\[x\Z(?ms)')
+        self.assertEqual(translate('*'), r'.*\Z(?ms)')
+        self.assertEqual(translate('?'), r'.\Z(?ms)')
+        self.assertEqual(translate('a?b*'), r'a.b.*\Z(?ms)')
+        self.assertEqual(translate('[abc]'), r'[abc]\Z(?ms)')
+        self.assertEqual(translate('[]]'), r'[]]\Z(?ms)')
+        self.assertEqual(translate('[!x]'), r'[^x]\Z(?ms)')
+        self.assertEqual(translate('[^x]'), r'[\^x]\Z(?ms)')
+        self.assertEqual(translate('[x'), r'\[x\Z(?ms)')
 
 
 class FilterTestCase(unittest.TestCase):
diff --git a/Lib/test/test_future.py b/Lib/test/test_future.py
--- a/Lib/test/test_future.py
+++ b/Lib/test/test_future.py
@@ -4,7 +4,7 @@
 from test import support
 import re
 
-rx = re.compile('\((\S+).py, line (\d+)')
+rx = re.compile(r'\((\S+).py, line (\d+)')
 
 def get_error_location(msg):
     mo = rx.search(str(msg))
diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py
--- a/Lib/test/test_gdb.py
+++ b/Lib/test/test_gdb.py
@@ -244,7 +244,7 @@
         # gdb can insert additional '\n' and space characters in various places
         # in its output, depending on the width of the terminal it's connected
         # to (using its "wrap_here" function)
-        m = re.match('.*#0\s+builtin_id\s+\(self\=.*,\s+v=\s*(.*?)\)\s+at\s+\S*Python/bltinmodule.c.*',
+        m = re.match(r'.*#0\s+builtin_id\s+\(self\=.*,\s+v=\s*(.*?)\)\s+at\s+\S*Python/bltinmodule.c.*',
                      gdb_output, re.DOTALL)
         if not m:
             self.fail('Unexpected gdb output: %r\n%s' % (gdb_output, gdb_output))
@@ -552,7 +552,7 @@
 foo = Foo()
 foo.an_attr = foo
 id(foo)''')
-        self.assertTrue(re.match('<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>',
+        self.assertTrue(re.match(r'<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>',
                                  gdb_repr),
                         'Unexpected gdb representation: %r\n%s' % \
                             (gdb_repr, gdb_output))
@@ -565,7 +565,7 @@
 foo = Foo()
 foo.an_attr = foo
 id(foo)''')
-        self.assertTrue(re.match('<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>',
+        self.assertTrue(re.match(r'<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>',
                                  gdb_repr),
                         'Unexpected gdb representation: %r\n%s' % \
                             (gdb_repr, gdb_output))
@@ -579,7 +579,7 @@
 a.an_attr = b
 b.an_attr = a
 id(a)''')
-        self.assertTrue(re.match('<Foo\(an_attr=<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>\) at remote 0x-?[0-9a-f]+>',
+        self.assertTrue(re.match(r'<Foo\(an_attr=<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>\) at remote 0x-?[0-9a-f]+>',
                                  gdb_repr),
                         'Unexpected gdb representation: %r\n%s' % \
                             (gdb_repr, gdb_output))
@@ -614,7 +614,7 @@
 
     def test_builtin_method(self):
         gdb_repr, gdb_output = self.get_gdb_repr('import sys; id(sys.stdout.readlines)')
-        self.assertTrue(re.match('<built-in method readlines of _io.TextIOWrapper object at remote 0x-?[0-9a-f]+>',
+        self.assertTrue(re.match(r'<built-in method readlines of _io.TextIOWrapper object at remote 0x-?[0-9a-f]+>',
                                  gdb_repr),
                         'Unexpected gdb representation: %r\n%s' % \
                             (gdb_repr, gdb_output))
@@ -629,7 +629,7 @@
                                           breakpoint='builtin_id',
                                           cmds_after_breakpoint=['print (PyFrameObject*)(((PyCodeObject*)v)->co_zombieframe)']
                                           )
-        self.assertTrue(re.match('.*\s+\$1 =\s+Frame 0x-?[0-9a-f]+, for file <string>, line 3, in foo \(\)\s+.*',
+        self.assertTrue(re.match(r'.*\s+\$1 =\s+Frame 0x-?[0-9a-f]+, for file <string>, line 3, in foo \(\)\s+.*',
                                  gdb_output,
                                  re.DOTALL),
                         'Unexpected gdb representation: %r\n%s' % (gdb_output, gdb_output))
diff --git a/Lib/test/test_getargs2.py b/Lib/test/test_getargs2.py
--- a/Lib/test/test_getargs2.py
+++ b/Lib/test/test_getargs2.py
@@ -625,20 +625,20 @@
             )
         # required arg missing
         with self.assertRaisesRegex(TypeError,
-            "Required argument 'required' \(pos 1\) not found"):
+            r"Required argument 'required' \(pos 1\) not found"):
             getargs_keyword_only(optional=2)
 
         with self.assertRaisesRegex(TypeError,
-            "Required argument 'required' \(pos 1\) not found"):
+            r"Required argument 'required' \(pos 1\) not found"):
             getargs_keyword_only(keyword_only=3)
 
     def test_too_many_args(self):
         with self.assertRaisesRegex(TypeError,
-            "Function takes at most 2 positional arguments \(3 given\)"):
+            r"Function takes at most 2 positional arguments \(3 given\)"):
             getargs_keyword_only(1, 2, 3)
 
         with self.assertRaisesRegex(TypeError,
-            "function takes at most 3 arguments \(4 given\)"):
+            r"function takes at most 3 arguments \(4 given\)"):
             getargs_keyword_only(1, 2, 3, keyword_only=5)
 
     def test_invalid_keyword(self):
@@ -673,11 +673,11 @@
         self.assertEqual(self.getargs(1), (1, -1, -1))
         # required positional arg missing
         with self.assertRaisesRegex(TypeError,
-            "Function takes at least 1 positional arguments \(0 given\)"):
+            r"Function takes at least 1 positional arguments \(0 given\)"):
             self.getargs()
 
         with self.assertRaisesRegex(TypeError,
-            "Function takes at least 1 positional arguments \(0 given\)"):
+            r"Function takes at least 1 positional arguments \(0 given\)"):
             self.getargs(keyword=3)
 
     def test_empty_keyword(self):
diff --git a/Lib/test/test_htmlparser.py b/Lib/test/test_htmlparser.py
--- a/Lib/test/test_htmlparser.py
+++ b/Lib/test/test_htmlparser.py
@@ -701,7 +701,7 @@
 
     def test_attr_funky_names2(self):
         self._run_check(
-            "<a $><b $=%><c \=/>",
+            r"<a $><b $=%><c \=/>",
             [("starttag", "a", [("$", None)]),
              ("starttag", "b", [("$", "%")]),
              ("starttag", "c", [("\\", "/")])])
diff --git a/Lib/test/test_http_cookiejar.py b/Lib/test/test_http_cookiejar.py
--- a/Lib/test/test_http_cookiejar.py
+++ b/Lib/test/test_http_cookiejar.py
@@ -1051,7 +1051,7 @@
         url = "http://foo.bar.com/"
         interact_2965(c, url, "spam=eggs; Version=1; Port")
         h = interact_2965(c, url)
-        self.assertRegex(h, "\$Port([^=]|$)",
+        self.assertRegex(h, r"\$Port([^=]|$)",
                          "port with no value not returned with no value")
 
         c = CookieJar(pol)
@@ -1396,9 +1396,9 @@
 
         self.assertRegex(cookie, r'^\$Version="?1"?;')
         self.assertRegex(cookie, r'Part_Number="?Rocket_Launcher_0001"?;'
-                                  '\s*\$Path="\/acme"')
+                                 r'\s*\$Path="\/acme"')
         self.assertRegex(cookie, r'Customer="?WILE_E_COYOTE"?;'
-                                  '\s*\$Path="\/acme"')
+                                 r'\s*\$Path="\/acme"')
 
         #
         #   7.  User Agent -> Server
diff --git a/Lib/test/test_mailcap.py b/Lib/test/test_mailcap.py
--- a/Lib/test/test_mailcap.py
+++ b/Lib/test/test_mailcap.py
@@ -101,7 +101,7 @@
             (["echo foo", "audio/*", "foo.txt"], "echo foo"),
             (["echo %s", "audio/*", "foo.txt"], "echo foo.txt"),
             (["echo %t", "audio/*", "foo.txt"], "echo audio/*"),
-            (["echo \%t", "audio/*", "foo.txt"], "echo %t"),
+            (["echo \\%t", "audio/*", "foo.txt"], "echo %t"),
             (["echo foo", "audio/*", "foo.txt", plist], "echo foo"),
             (["echo %{total}", "audio/*", "foo.txt", plist], "echo 3")
         ]
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -2086,7 +2086,7 @@
 class NonLocalSymlinkTests(unittest.TestCase):
 
     def setUp(self):
-        """
+        r"""
         Create this structure:
 
         base
diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py
--- a/Lib/test/test_platform.py
+++ b/Lib/test/test_platform.py
@@ -255,7 +255,7 @@
         with warnings.catch_warnings():
             warnings.filterwarnings(
                 'ignore',
-                'dist\(\) and linux_distribution\(\) '
+                r'dist\(\) and linux_distribution\(\) '
                 'functions are deprecated .*',
                 PendingDeprecationWarning,
             )
@@ -331,7 +331,7 @@
                 with warnings.catch_warnings():
                     warnings.filterwarnings(
                         'ignore',
-                        'dist\(\) and linux_distribution\(\) '
+                        r'dist\(\) and linux_distribution\(\) '
                         'functions are deprecated .*',
                         PendingDeprecationWarning,
                     )
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -113,10 +113,10 @@
         self.assertEqual(re.sub('(.)', re.escape(s), 'x'), s)
         self.assertEqual(re.sub('(.)', lambda m: s, 'x'), s)
 
-        self.assertEqual(re.sub('(?P<a>x)', '\g<a>\g<a>', 'xx'), 'xxxx')
-        self.assertEqual(re.sub('(?P<a>x)', '\g<a>\g<1>', 'xx'), 'xxxx')
-        self.assertEqual(re.sub('(?P<unk>x)', '\g<unk>\g<unk>', 'xx'), 'xxxx')
-        self.assertEqual(re.sub('(?P<unk>x)', '\g<1>\g<1>', 'xx'), 'xxxx')
+        self.assertEqual(re.sub('(?P<a>x)', r'\g<a>\g<a>', 'xx'), 'xxxx')
+        self.assertEqual(re.sub('(?P<a>x)', r'\g<a>\g<1>', 'xx'), 'xxxx')
+        self.assertEqual(re.sub('(?P<unk>x)', r'\g<unk>\g<unk>', 'xx'), 'xxxx')
+        self.assertEqual(re.sub('(?P<unk>x)', r'\g<1>\g<1>', 'xx'), 'xxxx')
 
         self.assertEqual(re.sub('a', r'\t\n\v\r\f\a\b', 'a'), '\t\n\v\r\f\a\b')
         self.assertEqual(re.sub('a', '\t\n\v\r\f\a\b', 'a'), '\t\n\v\r\f\a\b')
@@ -127,11 +127,11 @@
                 with self.assertRaises(re.error):
                     self.assertEqual(re.sub('a', '\\' + c, 'a'), '\\' + c)
 
-        self.assertEqual(re.sub('^\s*', 'X', 'test'), 'Xtest')
+        self.assertEqual(re.sub(r'^\s*', 'X', 'test'), 'Xtest')
 
     def test_bug_449964(self):
         # fails for group followed by other escape
-        self.assertEqual(re.sub(r'(?P<unk>x)', '\g<1>\g<1>\\b', 'xx'),
+        self.assertEqual(re.sub(r'(?P<unk>x)', r'\g<1>\g<1>\b', 'xx'),
                          'xx\bxx\b')
 
     def test_bug_449000(self):
@@ -218,26 +218,26 @@
         self.assertEqual(re.sub('x+', '-', 'abxd'), 'ab-d')
 
     def test_symbolic_groups(self):
-        re.compile('(?P<a>x)(?P=a)(?(a)y)')
-        re.compile('(?P<a1>x)(?P=a1)(?(a1)y)')
-        re.compile('(?P<a1>x)\1(?(1)y)')
-        self.checkPatternError('(?P<a>)(?P<a>)',
+        re.compile(r'(?P<a>x)(?P=a)(?(a)y)')
+        re.compile(r'(?P<a1>x)(?P=a1)(?(a1)y)')
+        re.compile(r'(?P<a1>x)\1(?(1)y)')
+        self.checkPatternError(r'(?P<a>)(?P<a>)',
                                "redefinition of group name 'a' as group 2; "
                                "was group 1")
-        self.checkPatternError('(?P<a>(?P=a))',
+        self.checkPatternError(r'(?P<a>(?P=a))',
                                "cannot refer to an open group", 10)
-        self.checkPatternError('(?Pxy)', 'unknown extension ?Px')
-        self.checkPatternError('(?P<a>)(?P=a', 'missing ), unterminated name', 11)
-        self.checkPatternError('(?P=', 'missing group name', 4)
-        self.checkPatternError('(?P=)', 'missing group name', 4)
-        self.checkPatternError('(?P=1)', "bad character in group name '1'", 4)
-        self.checkPatternError('(?P=a)', "unknown group name 'a'")
-        self.checkPatternError('(?P=a1)', "unknown group name 'a1'")
-        self.checkPatternError('(?P=a.)', "bad character in group name 'a.'", 4)
-        self.checkPatternError('(?P<)', 'missing >, unterminated name', 4)
-        self.checkPatternError('(?P<a', 'missing >, unterminated name', 4)
-        self.checkPatternError('(?P<', 'missing group name', 4)
-        self.checkPatternError('(?P<>)', 'missing group name', 4)
+        self.checkPatternError(r'(?Pxy)', 'unknown extension ?Px')
+        self.checkPatternError(r'(?P<a>)(?P=a', 'missing ), unterminated name', 11)
+        self.checkPatternError(r'(?P=', 'missing group name', 4)
+        self.checkPatternError(r'(?P=)', 'missing group name', 4)
+        self.checkPatternError(r'(?P=1)', "bad character in group name '1'", 4)
+        self.checkPatternError(r'(?P=a)', "unknown group name 'a'")
+        self.checkPatternError(r'(?P=a1)', "unknown group name 'a1'")
+        self.checkPatternError(r'(?P=a.)', "bad character in group name 'a.'", 4)
+        self.checkPatternError(r'(?P<)', 'missing >, unterminated name', 4)
+        self.checkPatternError(r'(?P<a', 'missing >, unterminated name', 4)
+        self.checkPatternError(r'(?P<', 'missing group name', 4)
+        self.checkPatternError(r'(?P<>)', 'missing group name', 4)
         self.checkPatternError(r'(?P<1>)', "bad character in group name '1'", 4)
         self.checkPatternError(r'(?P<a.>)', "bad character in group name 'a.'", 4)
         self.checkPatternError(r'(?(', 'missing group name', 3)
@@ -256,35 +256,35 @@
         self.assertEqual(re.match(pat, 'xc8yz').span(), (0, 5))
 
     def test_symbolic_refs(self):
-        self.checkTemplateError('(?P<a>x)', '\g<a', 'xx',
+        self.checkTemplateError('(?P<a>x)', r'\g<a', 'xx',
                                 'missing >, unterminated name', 3)
-        self.checkTemplateError('(?P<a>x)', '\g<', 'xx',
+        self.checkTemplateError('(?P<a>x)', r'\g<', 'xx',
                                 'missing group name', 3)
-        self.checkTemplateError('(?P<a>x)', '\g', 'xx', 'missing <', 2)
-        self.checkTemplateError('(?P<a>x)', '\g<a a>', 'xx',
+        self.checkTemplateError('(?P<a>x)', r'\g', 'xx', 'missing <', 2)
+        self.checkTemplateError('(?P<a>x)', r'\g<a a>', 'xx',
                                 "bad character in group name 'a a'", 3)
-        self.checkTemplateError('(?P<a>x)', '\g<>', 'xx',
+        self.checkTemplateError('(?P<a>x)', r'\g<>', 'xx',
                                 'missing group name', 3)
-        self.checkTemplateError('(?P<a>x)', '\g<1a1>', 'xx',
+        self.checkTemplateError('(?P<a>x)', r'\g<1a1>', 'xx',
                                 "bad character in group name '1a1'", 3)
         self.checkTemplateError('(?P<a>x)', r'\g<2>', 'xx',
                                 'invalid group reference')
         self.checkTemplateError('(?P<a>x)', r'\2', 'xx',
                                 'invalid group reference')
         with self.assertRaisesRegex(IndexError, "unknown group name 'ab'"):
-            re.sub('(?P<a>x)', '\g<ab>', 'xx')
+            re.sub('(?P<a>x)', r'\g<ab>', 'xx')
         self.assertEqual(re.sub('(?P<a>x)|(?P<b>y)', r'\g<b>', 'xx'), '')
         self.assertEqual(re.sub('(?P<a>x)|(?P<b>y)', r'\2', 'xx'), '')
-        self.checkTemplateError('(?P<a>x)', '\g<-1>', 'xx',
+        self.checkTemplateError('(?P<a>x)', r'\g<-1>', 'xx',
                                 "bad character in group name '-1'", 3)
         # New valid/invalid identifiers in Python 3
         self.assertEqual(re.sub('(?P<µ>x)', r'\g<µ>', 'xx'), 'xx')
         self.assertEqual(re.sub('(?P<𝔘𝔫𝔦𝔠𝔬𝔡𝔢>x)', r'\g<𝔘𝔫𝔦𝔠𝔬𝔡𝔢>', 'xx'), 'xx')
-        self.checkTemplateError('(?P<a>x)', '\g<©>', 'xx',
+        self.checkTemplateError('(?P<a>x)', r'\g<©>', 'xx',
                                 "bad character in group name '©'", 3)
         # Support > 100 groups.
         pat = '|'.join('x(?P<a%d>%x)y' % (i, i) for i in range(1, 200 + 1))
-        self.assertEqual(re.sub(pat, '\g<200>', 'xc8yzxc8y'), 'c8zc8')
+        self.assertEqual(re.sub(pat, r'\g<200>', 'xc8yzxc8y'), 'c8zc8')
 
     def test_re_subn(self):
         self.assertEqual(re.subn("(?i)b+", "x", "bbbb BBBB"), ('x x', 2))
@@ -472,19 +472,19 @@
             re.compile(r".*?").fullmatch("abcd", pos=1, endpos=3).span(), (1, 3))
 
     def test_re_groupref_exists(self):
-        self.assertEqual(re.match('^(\()?([^()]+)(?(1)\))$', '(a)').groups(),
+        self.assertEqual(re.match(r'^(\()?([^()]+)(?(1)\))$', '(a)').groups(),
                          ('(', 'a'))
-        self.assertEqual(re.match('^(\()?([^()]+)(?(1)\))$', 'a').groups(),
+        self.assertEqual(re.match(r'^(\()?([^()]+)(?(1)\))$', 'a').groups(),
                          (None, 'a'))
-        self.assertIsNone(re.match('^(\()?([^()]+)(?(1)\))$', 'a)'))
-        self.assertIsNone(re.match('^(\()?([^()]+)(?(1)\))$', '(a'))
+        self.assertIsNone(re.match(r'^(\()?([^()]+)(?(1)\))$', 'a)'))
+        self.assertIsNone(re.match(r'^(\()?([^()]+)(?(1)\))$', '(a'))
         self.assertEqual(re.match('^(?:(a)|c)((?(1)b|d))$', 'ab').groups(),
                          ('a', 'b'))
-        self.assertEqual(re.match('^(?:(a)|c)((?(1)b|d))$', 'cd').groups(),
+        self.assertEqual(re.match(r'^(?:(a)|c)((?(1)b|d))$', 'cd').groups(),
                          (None, 'd'))
-        self.assertEqual(re.match('^(?:(a)|c)((?(1)|d))$', 'cd').groups(),
+        self.assertEqual(re.match(r'^(?:(a)|c)((?(1)|d))$', 'cd').groups(),
                          (None, 'd'))
-        self.assertEqual(re.match('^(?:(a)|c)((?(1)|d))$', 'a').groups(),
+        self.assertEqual(re.match(r'^(?:(a)|c)((?(1)|d))$', 'a').groups(),
                          ('a', ''))
 
         # Tests for bug #1177831: exercise groups other than the first group
@@ -509,7 +509,7 @@
                                'two branches', 10)
 
     def test_re_groupref_overflow(self):
-        self.checkTemplateError('()', '\g<%s>' % sre_constants.MAXGROUPS, 'xx',
+        self.checkTemplateError('()', r'\g<%s>' % sre_constants.MAXGROUPS, 'xx',
                                 'invalid group reference', 3)
         self.checkPatternError(r'(?P<a>)(?(%d))' % sre_constants.MAXGROUPS,
                                'invalid group reference', 10)
@@ -544,37 +544,37 @@
                          " ")
 
     def test_repeat_minmax(self):
-        self.assertIsNone(re.match("^(\w){1}$", "abc"))
-        self.assertIsNone(re.match("^(\w){1}?$", "abc"))
-        self.assertIsNone(re.match("^(\w){1,2}$", "abc"))
-        self.assertIsNone(re.match("^(\w){1,2}?$", "abc"))
+        self.assertIsNone(re.match(r"^(\w){1}$", "abc"))
+        self.assertIsNone(re.match(r"^(\w){1}?$", "abc"))
+        self.assertIsNone(re.match(r"^(\w){1,2}$", "abc"))
+        self.assertIsNone(re.match(r"^(\w){1,2}?$", "abc"))
 
-        self.assertEqual(re.match("^(\w){3}$", "abc").group(1), "c")
-        self.assertEqual(re.match("^(\w){1,3}$", "abc").group(1), "c")
-        self.assertEqual(re.match("^(\w){1,4}$", "abc").group(1), "c")
-        self.assertEqual(re.match("^(\w){3,4}?$", "abc").group(1), "c")
-        self.assertEqual(re.match("^(\w){3}?$", "abc").group(1), "c")
-        self.assertEqual(re.match("^(\w){1,3}?$", "abc").group(1), "c")
-        self.assertEqual(re.match("^(\w){1,4}?$", "abc").group(1), "c")
-        self.assertEqual(re.match("^(\w){3,4}?$", "abc").group(1), "c")
+        self.assertEqual(re.match(r"^(\w){3}$", "abc").group(1), "c")
+        self.assertEqual(re.match(r"^(\w){1,3}$", "abc").group(1), "c")
+        self.assertEqual(re.match(r"^(\w){1,4}$", "abc").group(1), "c")
+        self.assertEqual(re.match(r"^(\w){3,4}?$", "abc").group(1), "c")
+        self.assertEqual(re.match(r"^(\w){3}?$", "abc").group(1), "c")
+        self.assertEqual(re.match(r"^(\w){1,3}?$", "abc").group(1), "c")
+        self.assertEqual(re.match(r"^(\w){1,4}?$", "abc").group(1), "c")
+        self.assertEqual(re.match(r"^(\w){3,4}?$", "abc").group(1), "c")
 
-        self.assertIsNone(re.match("^x{1}$", "xxx"))
-        self.assertIsNone(re.match("^x{1}?$", "xxx"))
-        self.assertIsNone(re.match("^x{1,2}$", "xxx"))
-        self.assertIsNone(re.match("^x{1,2}?$", "xxx"))
+        self.assertIsNone(re.match(r"^x{1}$", "xxx"))
+        self.assertIsNone(re.match(r"^x{1}?$", "xxx"))
+        self.assertIsNone(re.match(r"^x{1,2}$", "xxx"))
+        self.assertIsNone(re.match(r"^x{1,2}?$", "xxx"))
 
-        self.assertTrue(re.match("^x{3}$", "xxx"))
-        self.assertTrue(re.match("^x{1,3}$", "xxx"))
-        self.assertTrue(re.match("^x{3,3}$", "xxx"))
-        self.assertTrue(re.match("^x{1,4}$", "xxx"))
-        self.assertTrue(re.match("^x{3,4}?$", "xxx"))
-        self.assertTrue(re.match("^x{3}?$", "xxx"))
-        self.assertTrue(re.match("^x{1,3}?$", "xxx"))
-        self.assertTrue(re.match("^x{1,4}?$", "xxx"))
-        self.assertTrue(re.match("^x{3,4}?$", "xxx"))
+        self.assertTrue(re.match(r"^x{3}$", "xxx"))
+        self.assertTrue(re.match(r"^x{1,3}$", "xxx"))
+        self.assertTrue(re.match(r"^x{3,3}$", "xxx"))
+        self.assertTrue(re.match(r"^x{1,4}$", "xxx"))
+        self.assertTrue(re.match(r"^x{3,4}?$", "xxx"))
+        self.assertTrue(re.match(r"^x{3}?$", "xxx"))
+        self.assertTrue(re.match(r"^x{1,3}?$", "xxx"))
+        self.assertTrue(re.match(r"^x{1,4}?$", "xxx"))
+        self.assertTrue(re.match(r"^x{3,4}?$", "xxx"))
 
-        self.assertIsNone(re.match("^x{}$", "xxx"))
-        self.assertTrue(re.match("^x{}$", "x{}"))
+        self.assertIsNone(re.match(r"^x{}$", "xxx"))
+        self.assertTrue(re.match(r"^x{}$", "x{}"))
 
         self.checkPatternError(r'x{2,1}',
                                'min repeat greater than max repeat', 2)
@@ -697,10 +697,10 @@
                          "a\n\nb")
 
     def test_lookahead(self):
-        self.assertEqual(re.match("(a(?=\s[^a]))", "a b").group(1), "a")
-        self.assertEqual(re.match("(a(?=\s[^a]*))", "a b").group(1), "a")
-        self.assertEqual(re.match("(a(?=\s[abc]))", "a b").group(1), "a")
-        self.assertEqual(re.match("(a(?=\s[abc]*))", "a bc").group(1), "a")
+        self.assertEqual(re.match(r"(a(?=\s[^a]))", "a b").group(1), "a")
+        self.assertEqual(re.match(r"(a(?=\s[^a]*))", "a b").group(1), "a")
+        self.assertEqual(re.match(r"(a(?=\s[abc]))", "a b").group(1), "a")
+        self.assertEqual(re.match(r"(a(?=\s[abc]*))", "a bc").group(1), "a")
         self.assertEqual(re.match(r"(a)(?=\s\1)", "a a").group(1), "a")
         self.assertEqual(re.match(r"(a)(?=\s\1*)", "a aa").group(1), "a")
         self.assertEqual(re.match(r"(a)(?=\s(abc|a))", "a a").group(1), "a")
@@ -848,12 +848,12 @@
         self.assertEqual(re.match(b"abc", b"ABC", re.I|re.L).group(0), b"ABC")
 
     def test_not_literal(self):
-        self.assertEqual(re.search("\s([^a])", " b").group(1), "b")
-        self.assertEqual(re.search("\s([^a]*)", " bb").group(1), "bb")
+        self.assertEqual(re.search(r"\s([^a])", " b").group(1), "b")
+        self.assertEqual(re.search(r"\s([^a]*)", " bb").group(1), "bb")
 
     def test_search_coverage(self):
-        self.assertEqual(re.search("\s(b)", " b").group(1), "b")
-        self.assertEqual(re.search("a\s", "a ").group(0), "a ")
+        self.assertEqual(re.search(r"\s(b)", " b").group(1), "b")
+        self.assertEqual(re.search(r"a\s", "a ").group(0), "a ")
 
     def assertMatch(self, pattern, text, match=None, span=None,
                     matcher=re.match):
@@ -1055,8 +1055,8 @@
         self.assertIsNone(re.match(r'(a)?a','a').lastindex)
         self.assertEqual(re.match(r'(a)(b)?b','ab').lastindex, 1)
         self.assertEqual(re.match(r'(?P<a>a)(?P<b>b)?b','ab').lastgroup, 'a')
-        self.assertEqual(re.match("(?P<a>a(b))", "ab").lastgroup, 'a')
-        self.assertEqual(re.match("((a))", "a").lastindex, 1)
+        self.assertEqual(re.match(r"(?P<a>a(b))", "ab").lastgroup, 'a')
+        self.assertEqual(re.match(r"((a))", "a").lastindex, 1)
 
     def test_bug_418626(self):
         # bugs 418626 at al. -- Testing Greg Chapman's addition of op code
@@ -1228,7 +1228,7 @@
             '\uff10', # '\N{FULLWIDTH DIGIT ZERO}', category 'Nd'
             ]
         for x in decimal_digits:
-            self.assertEqual(re.match('^\d$', x).group(0), x)
+            self.assertEqual(re.match(r'^\d$', x).group(0), x)
 
         not_decimal_digits = [
             '\u2165', # '\N{ROMAN NUMERAL SIX}', category 'Nl'
@@ -1237,7 +1237,7 @@
             '\u32b4', # '\N{CIRCLED NUMBER THIRTY NINE}', category 'No'
             ]
         for x in not_decimal_digits:
-            self.assertIsNone(re.match('^\d$', x))
+            self.assertIsNone(re.match(r'^\d$', x))
 
     def test_empty_array(self):
         # SF buf 1647541
@@ -1306,29 +1306,29 @@
         for flags in (0, re.UNICODE):
             pat = re.compile('\xc0', flags | re.IGNORECASE)
             self.assertTrue(pat.match('\xe0'))
-            pat = re.compile('\w', flags)
+            pat = re.compile(r'\w', flags)
             self.assertTrue(pat.match('\xe0'))
         pat = re.compile('\xc0', re.ASCII | re.IGNORECASE)
         self.assertIsNone(pat.match('\xe0'))
         pat = re.compile('(?a)\xc0', re.IGNORECASE)
         self.assertIsNone(pat.match('\xe0'))
-        pat = re.compile('\w', re.ASCII)
+        pat = re.compile(r'\w', re.ASCII)
         self.assertIsNone(pat.match('\xe0'))
-        pat = re.compile('(?a)\w')
+        pat = re.compile(r'(?a)\w')
         self.assertIsNone(pat.match('\xe0'))
         # Bytes patterns
         for flags in (0, re.ASCII):
             pat = re.compile(b'\xc0', flags | re.IGNORECASE)
             self.assertIsNone(pat.match(b'\xe0'))
-            pat = re.compile(b'\w', flags)
+            pat = re.compile(br'\w', flags)
             self.assertIsNone(pat.match(b'\xe0'))
         # Incompatibilities
-        self.assertRaises(ValueError, re.compile, b'\w', re.UNICODE)
-        self.assertRaises(ValueError, re.compile, b'(?u)\w')
-        self.assertRaises(ValueError, re.compile, '\w', re.UNICODE | re.ASCII)
-        self.assertRaises(ValueError, re.compile, '(?u)\w', re.ASCII)
-        self.assertRaises(ValueError, re.compile, '(?a)\w', re.UNICODE)
-        self.assertRaises(ValueError, re.compile, '(?au)\w')
+        self.assertRaises(ValueError, re.compile, br'\w', re.UNICODE)
+        self.assertRaises(ValueError, re.compile, br'(?u)\w')
+        self.assertRaises(ValueError, re.compile, r'\w', re.UNICODE | re.ASCII)
+        self.assertRaises(ValueError, re.compile, r'(?u)\w', re.ASCII)
+        self.assertRaises(ValueError, re.compile, r'(?a)\w', re.UNICODE)
+        self.assertRaises(ValueError, re.compile, r'(?au)\w')
 
     def test_locale_flag(self):
         import locale
@@ -1359,13 +1359,13 @@
         pat = re.compile(bpat, re.IGNORECASE)
         if bletter:
             self.assertIsNone(pat.match(bletter))
-        pat = re.compile(b'\w', re.LOCALE)
+        pat = re.compile(br'\w', re.LOCALE)
         if bletter:
             self.assertTrue(pat.match(bletter))
-        pat = re.compile(b'(?L)\w')
+        pat = re.compile(br'(?L)\w')
         if bletter:
             self.assertTrue(pat.match(bletter))
-        pat = re.compile(b'\w')
+        pat = re.compile(br'\w')
         if bletter:
             self.assertIsNone(pat.match(bletter))
         # Incompatibilities
@@ -1379,7 +1379,7 @@
     def test_bug_6509(self):
         # Replacement strings of both types must parse properly.
         # all strings
-        pat = re.compile('a(\w)')
+        pat = re.compile(r'a(\w)')
         self.assertEqual(pat.sub('b\\1', 'ac'), 'bc')
         pat = re.compile('a(.)')
         self.assertEqual(pat.sub('b\\1', 'a\u1234'), 'b\u1234')
@@ -1387,7 +1387,7 @@
         self.assertEqual(pat.sub(lambda m: 'str', 'a5'), 'str')
 
         # all bytes
-        pat = re.compile(b'a(\w)')
+        pat = re.compile(br'a(\w)')
         self.assertEqual(pat.sub(b'b\\1', b'ac'), b'bc')
         pat = re.compile(b'a(.)')
         self.assertEqual(pat.sub(b'b\\1', b'a\xCD'), b'b\xCD')
@@ -1509,7 +1509,7 @@
         for string in (b'[abracadabra]', B(b'[abracadabra]'),
                        bytearray(b'[abracadabra]'),
                        memoryview(b'[abracadabra]')):
-            m = re.search(rb'(.+)(.*?)\1', string)
+            m = re.search(br'(.+)(.*?)\1', string)
             self.assertEqual(repr(m), "<%s.%s object; "
                              "span=(1, 12), match=b'abracadabra'>" %
                              (type(m).__module__, type(m).__qualname__))
diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py
--- a/Lib/test/test_regrtest.py
+++ b/Lib/test/test_regrtest.py
@@ -704,8 +704,8 @@
         test = self.create_test('coverage')
         output = self.run_tests("--coverage", test)
         self.check_executed_tests(output, [test])
-        regex = ('lines +cov% +module +\(path\)\n'
-                 '(?: *[0-9]+ *[0-9]{1,2}% *[^ ]+ +\([^)]+\)+)+')
+        regex = (r'lines +cov% +module +\(path\)\n'
+                 r'(?: *[0-9]+ *[0-9]{1,2}% *[^ ]+ +\([^)]+\)+)+')
         self.check_line(output, regex)
 
     def test_wait(self):
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -3405,7 +3405,7 @@
         with warnings.catch_warnings():
             warnings.filterwarnings(
                 'ignore',
-                'dist\(\) and linux_distribution\(\) '
+                r'dist\(\) and linux_distribution\(\) '
                 'functions are deprecated .*',
                 PendingDeprecationWarning,
             )
diff --git a/Lib/test/test_strftime.py b/Lib/test/test_strftime.py
--- a/Lib/test/test_strftime.py
+++ b/Lib/test/test_strftime.py
@@ -23,9 +23,9 @@
     """
     new_text = re.escape(text)
     new_text = new_text.replace(re.escape(ampm), ampm)
-    new_text = new_text.replace('\%', '%')
-    new_text = new_text.replace('\:', ':')
-    new_text = new_text.replace('\?', '?')
+    new_text = new_text.replace(r'\%', '%')
+    new_text = new_text.replace(r'\:', ':')
+    new_text = new_text.replace(r'\?', '?')
     return new_text
 
 
diff --git a/Lib/test/test_strlit.py b/Lib/test/test_strlit.py
--- a/Lib/test/test_strlit.py
+++ b/Lib/test/test_strlit.py
@@ -121,9 +121,9 @@
         self.assertEqual(eval(""" b'\x01' """), byte(1))
         self.assertEqual(eval(r""" b'\x81' """), byte(0x81))
         self.assertRaises(SyntaxError, eval, """ b'\x81' """)
-        self.assertEqual(eval(r""" b'\u1881' """), b'\\' + b'u1881')
+        self.assertEqual(eval(r""" br'\u1881' """), b'\\' + b'u1881')
         self.assertRaises(SyntaxError, eval, """ b'\u1881' """)
-        self.assertEqual(eval(r""" b'\U0001d120' """), b'\\' + b'U0001d120')
+        self.assertEqual(eval(r""" br'\U0001d120' """), b'\\' + b'U0001d120')
         self.assertRaises(SyntaxError, eval, """ b'\U0001d120' """)
 
     def test_eval_bytes_incomplete(self):
diff --git a/Lib/test/test_strptime.py b/Lib/test/test_strptime.py
--- a/Lib/test/test_strptime.py
+++ b/Lib/test/test_strptime.py
@@ -129,7 +129,7 @@
     def test_pattern_escaping(self):
         # Make sure any characters in the format string that might be taken as
         # regex syntax is escaped.
-        pattern_string = self.time_re.pattern("\d+")
+        pattern_string = self.time_re.pattern(r"\d+")
         self.assertIn(r"\\d\+", pattern_string,
                       "%s does not have re characters escaped properly" %
                       pattern_string)
@@ -170,9 +170,9 @@
 
     def test_matching_with_escapes(self):
         # Make sure a format that requires escaping of characters works
-        compiled_re = self.time_re.compile("\w+ %m")
-        found = compiled_re.match("\w+ 10")
-        self.assertTrue(found, "Escaping failed of format '\w+ 10'")
+        compiled_re = self.time_re.compile(r"\w+ %m")
+        found = compiled_re.match(r"\w+ 10")
+        self.assertTrue(found, r"Escaping failed of format '\w+ 10'")
 
     def test_locale_data_w_regex_metacharacters(self):
         # Check that if locale data contains regex metacharacters they are
@@ -403,7 +403,7 @@
         # unbalanced parentheses when the regex is compiled if they are not
         # escaped.
         # Test instigated by bug #796149 .
-        need_escaping = ".^$*+?{}\[]|)("
+        need_escaping = r".^$*+?{}\[]|)("
         self.assertTrue(_strptime._strptime_time(need_escaping, need_escaping))
 
     def test_feb29_on_leap_year_without_year(self):
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -1564,7 +1564,7 @@
             ('+', b'+-'),
             ('+-', b'+--'),
             ('+?', b'+-?'),
-            ('\?', b'+AFw?'),
+            (r'\?', b'+AFw?'),
             ('+?', b'+-?'),
             (r'\\?', b'+AFwAXA?'),
             (r'\\\?', b'+AFwAXABc?'),
@@ -2326,7 +2326,7 @@
         # non-ascii format, ascii argument: ensure that PyUnicode_FromFormatV()
         # raises an error
         self.assertRaisesRegex(ValueError,
-            '^PyUnicode_FromFormatV\(\) expects an ASCII-encoded format '
+            r'^PyUnicode_FromFormatV\(\) expects an ASCII-encoded format '
             'string, got a non-ASCII byte: 0xe9$',
             PyUnicode_FromFormat, b'unicode\xe9=%s', 'ascii')
 
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -729,7 +729,7 @@
 
 
 class QuotingTests(unittest.TestCase):
-    """Tests for urllib.quote() and urllib.quote_plus()
+    r"""Tests for urllib.quote() and urllib.quote_plus()
 
     According to RFC 2396 (Uniform Resource Identifiers), to escape a
     character you write it as '%' + <2 character US-ASCII hex value>.
@@ -804,7 +804,7 @@
         # Make sure all characters that should be quoted are by default sans
         # space (separate test for that).
         should_quote = [chr(num) for num in range(32)] # For 0x00 - 0x1F
-        should_quote.append('<>#%"{}|\^[]`')
+        should_quote.append(r'<>#%"{}|\^[]`')
         should_quote.append(chr(127)) # For 0x7F
         should_quote = ''.join(should_quote)
         for char in should_quote:
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -1218,7 +1218,7 @@
         content = handle[handle.find("<?xml"):]
 
         self.assertEqual(
-            int(re.search('Content-Length: (\d+)', handle).group(1)),
+            int(re.search(r'Content-Length: (\d+)', handle).group(1)),
             len(content))
 
 
diff --git a/Lib/unittest/runner.py b/Lib/unittest/runner.py
--- a/Lib/unittest/runner.py
+++ b/Lib/unittest/runner.py
@@ -167,7 +167,7 @@
                 if self.warnings in ['default', 'always']:
                     warnings.filterwarnings('module',
                             category=DeprecationWarning,
-                            message='Please use assert\w+ instead.')
+                            message=r'Please use assert\w+ instead.')
             startTime = time.time()
             startTestRun = getattr(result, 'startTestRun', None)
             if startTestRun is not None:
diff --git a/Lib/unittest/test/test_assertions.py b/Lib/unittest/test/test_assertions.py
--- a/Lib/unittest/test/test_assertions.py
+++ b/Lib/unittest/test/test_assertions.py
@@ -240,7 +240,7 @@
         # Error messages are multiline so not testing on full message
         # assertTupleEqual and assertListEqual delegate to this method
         self.assertMessages('assertSequenceEqual', ([], [None]),
-                            ["\+ \[None\]$", "^oops$", r"\+ \[None\]$",
+                            [r"\+ \[None\]$", "^oops$", r"\+ \[None\]$",
                              r"\+ \[None\] : oops$"])
 
     def testAssertSetEqual(self):
@@ -250,21 +250,21 @@
 
     def testAssertIn(self):
         self.assertMessages('assertIn', (None, []),
-                            ['^None not found in \[\]$', "^oops$",
-                             '^None not found in \[\]$',
-                             '^None not found in \[\] : oops$'])
+                            [r'^None not found in \[\]$', "^oops$",
+                             r'^None not found in \[\]$',
+                             r'^None not found in \[\] : oops$'])
 
     def testAssertNotIn(self):
         self.assertMessages('assertNotIn', (None, [None]),
-                            ['^None unexpectedly found in \[None\]$', "^oops$",
-                             '^None unexpectedly found in \[None\]$',
-                             '^None unexpectedly found in \[None\] : oops$'])
+                            [r'^None unexpectedly found in \[None\]$', "^oops$",
+                             r'^None unexpectedly found in \[None\]$',
+                             r'^None unexpectedly found in \[None\] : oops$'])
 
     def testAssertDictEqual(self):
         self.assertMessages('assertDictEqual', ({}, {'key': 'value'}),
                             [r"\+ \{'key': 'value'\}$", "^oops$",
-                             "\+ \{'key': 'value'\}$",
-                             "\+ \{'key': 'value'\} : oops$"])
+                             r"\+ \{'key': 'value'\}$",
+                             r"\+ \{'key': 'value'\} : oops$"])
 
     def testAssertDictContainsSubset(self):
         with warnings.catch_warnings():
diff --git a/Lib/unittest/test/test_loader.py b/Lib/unittest/test/test_loader.py
--- a/Lib/unittest/test/test_loader.py
+++ b/Lib/unittest/test/test_loader.py
@@ -390,7 +390,7 @@
         suite = loader.loadTestsFromName('abc () //')
         error, test = self.check_deferred_error(loader, suite)
         expected = "Failed to import test module: abc () //"
-        expected_regex = "Failed to import test module: abc \(\) //"
+        expected_regex = r"Failed to import test module: abc \(\) //"
         self.assertIn(
             expected, error,
             'missing error string in %r' % error)
@@ -502,7 +502,7 @@
         suite = loader.loadTestsFromName('abc () //', unittest)
         error, test = self.check_deferred_error(loader, suite)
         expected = "module 'unittest' has no attribute 'abc () //'"
-        expected_regex = "module 'unittest' has no attribute 'abc \(\) //'"
+        expected_regex = r"module 'unittest' has no attribute 'abc \(\) //'"
         self.assertIn(
             expected, error,
             'missing error string in %r' % error)
@@ -809,7 +809,7 @@
         suite = loader.loadTestsFromNames(['abc () //'])
         error, test = self.check_deferred_error(loader, list(suite)[0])
         expected = "Failed to import test module: abc () //"
-        expected_regex = "Failed to import test module: abc \(\) //"
+        expected_regex = r"Failed to import test module: abc \(\) //"
         self.assertIn(
             expected,  error,
             'missing error string in %r' % error)
@@ -928,7 +928,7 @@
         suite = loader.loadTestsFromNames(['abc () //'], unittest)
         error, test = self.check_deferred_error(loader, list(suite)[0])
         expected = "module 'unittest' has no attribute 'abc () //'"
-        expected_regex = "module 'unittest' has no attribute 'abc \(\) //'"
+        expected_regex = r"module 'unittest' has no attribute 'abc \(\) //'"
         self.assertIn(
             expected, error,
             'missing error string in %r' % error)
diff --git a/Lib/xml/etree/ElementPath.py b/Lib/xml/etree/ElementPath.py
--- a/Lib/xml/etree/ElementPath.py
+++ b/Lib/xml/etree/ElementPath.py
@@ -59,15 +59,15 @@
 import re
 
 xpath_tokenizer_re = re.compile(
-    "("
-    "'[^']*'|\"[^\"]*\"|"
-    "::|"
-    "//?|"
-    "\.\.|"
-    "\(\)|"
-    "[/.*:\[\]\(\)@=])|"
-    "((?:\{[^}]+\})?[^/\[\]\(\)@=\s]+)|"
-    "\s+"
+    r"("
+    r"'[^']*'|\"[^\"]*\"|"
+    r"::|"
+    r"//?|"
+    r"\.\.|"
+    r"\(\)|"
+    r"[/.*:\[\]\(\)@=])|"
+    r"((?:\{[^}]+\})?[^/\[\]\(\)@=\s]+)|"
+    r"\s+"
     )
 
 def xpath_tokenizer(pattern, namespaces=None):
@@ -180,7 +180,7 @@
                 if elem.get(key) == value:
                     yield elem
         return select
-    if signature == "-" and not re.match("\-?\d+$", predicate[0]):
+    if signature == "-" and not re.match(r"\-?\d+$", predicate[0]):
         # [tag]
         tag = predicate[0]
         def select(context, result):
@@ -188,7 +188,7 @@
                 if elem.find(tag) is not None:
                     yield elem
         return select
-    if signature == "-='" and not re.match("\-?\d+$", predicate[0]):
+    if signature == "-='" and not re.match(r"\-?\d+$", predicate[0]):
         # [tag='value']
         tag = predicate[0]
         value = predicate[-1]
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -1030,7 +1030,7 @@
     ValueError is raised if prefix is reserved or is invalid.
 
     """
-    if re.match("ns\d+$", prefix):
+    if re.match(r"ns\d+$", prefix):
         raise ValueError("Prefix format reserved for internal use")
     for k, v in list(_namespace_map.items()):
         if k == uri or v == prefix:
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -1222,7 +1222,7 @@
 
 def create_regex(before, after, word=True, whole_line=True):
     """Create an re object for matching marker lines."""
-    group_re = "\w+" if word else ".+"
+    group_re = r"\w+" if word else ".+"
     pattern = r'{}({}){}'
     if whole_line:
         pattern = '^' + pattern + '$'
diff --git a/Tools/demo/ss1.py b/Tools/demo/ss1.py
--- a/Tools/demo/ss1.py
+++ b/Tools/demo/ss1.py
@@ -413,7 +413,7 @@
 
     def renumber(self, x1, y1, x2, y2, dx, dy):
         out = []
-        for part in re.split('(\w+)', self.formula):
+        for part in re.split(r'(\w+)', self.formula):
             m = re.match('^([A-Z]+)([1-9][0-9]*)$', part)
             if m is not None:
                 sx, sy = m.groups()
diff --git a/Tools/freeze/winmakemakefile.py b/Tools/freeze/winmakemakefile.py
--- a/Tools/freeze/winmakemakefile.py
+++ b/Tools/freeze/winmakemakefile.py
@@ -95,7 +95,7 @@
     print()
 
     print('$(temp_dir):')
-    print('  if not exist $(temp_dir)\. mkdir $(temp_dir)')
+    print(r'  if not exist $(temp_dir)\. mkdir $(temp_dir)')
     print()
 
     objects = []
@@ -106,7 +106,7 @@
             base = os.path.basename(file)
             base, ext = os.path.splitext(base)
             objects.append(base + ".obj")
-            print('$(temp_dir)\%s.obj: "%s"' % (base, file))
+            print(r'$(temp_dir)\%s.obj: "%s"' % (base, file))
             print("\t@$(CC) -c -nologo /Fo$* $(cdl) $(c_debug) /D BUILD_FREEZE", end=' ')
             print('"-I$(pythonhome)/Include"  "-I$(pythonhome)/PC" \\')
             print("\t\t$(cflags) $(cdebug) $(cinclude) \\")
@@ -126,7 +126,7 @@
     print() ; print()
 
     print("OBJS=", end=' ')
-    for obj in objects: print('"$(temp_dir)\%s"' % (obj), end=' ')
+    for obj in objects: print(r'"$(temp_dir)\%s"' % (obj), end=' ')
     print() ; print()
 
     print("LIBS=", end=' ')
diff --git a/Tools/pybench/CommandLine.py b/Tools/pybench/CommandLine.py
--- a/Tools/pybench/CommandLine.py
+++ b/Tools/pybench/CommandLine.py
@@ -99,8 +99,8 @@
 # Alias
 getpasswd = invisible_input
 
-_integerRE = re.compile('\s*(-?\d+)\s*$')
-_integerRangeRE = re.compile('\s*(-?\d+)\s*-\s*(-?\d+)\s*$')
+_integerRE = re.compile(r'\s*(-?\d+)\s*$')
+_integerRangeRE = re.compile(r'\s*(-?\d+)\s*-\s*(-?\d+)\s*$')
 
 def srange(s,
 
diff --git a/Tools/pynche/ColorDB.py b/Tools/pynche/ColorDB.py
--- a/Tools/pynche/ColorDB.py
+++ b/Tools/pynche/ColorDB.py
@@ -134,17 +134,17 @@
 

 class RGBColorDB(ColorDB):
     _re = re.compile(
-        '\s*(?P<red>\d+)\s+(?P<green>\d+)\s+(?P<blue>\d+)\s+(?P<name>.*)')
+        r'\s*(?P<red>\d+)\s+(?P<green>\d+)\s+(?P<blue>\d+)\s+(?P<name>.*)')
 
 
 class HTML40DB(ColorDB):
-    _re = re.compile('(?P<name>\S+)\s+(?P<hexrgb>#[0-9a-fA-F]{6})')
+    _re = re.compile(r'(?P<name>\S+)\s+(?P<hexrgb>#[0-9a-fA-F]{6})')
 
     def _extractrgb(self, mo):
         return rrggbb_to_triplet(mo.group('hexrgb'))
 
 class LightlinkDB(HTML40DB):
-    _re = re.compile('(?P<name>(.+))\s+(?P<hexrgb>#[0-9a-fA-F]{6})')
+    _re = re.compile(r'(?P<name>(.+))\s+(?P<hexrgb>#[0-9a-fA-F]{6})')
 
     def _extractname(self, mo):
         return mo.group('name').strip()
diff --git a/Tools/scripts/fixdiv.py b/Tools/scripts/fixdiv.py
--- a/Tools/scripts/fixdiv.py
+++ b/Tools/scripts/fixdiv.py
@@ -174,8 +174,8 @@
     sys.stderr.write("Usage: %s [-m] warnings\n" % sys.argv[0])
     sys.stderr.write("Try `%s -h' for more information.\n" % sys.argv[0])
 
-PATTERN = ("^(.+?):(\d+): DeprecationWarning: "
-           "classic (int|long|float|complex) division$")
+PATTERN = (r"^(.+?):(\d+): DeprecationWarning: "
+           r"classic (int|long|float|complex) division$")
 
 def readwarnings(warningsfile):
     prog = re.compile(PATTERN)
diff --git a/Tools/scripts/h2py.py b/Tools/scripts/h2py.py
--- a/Tools/scripts/h2py.py
+++ b/Tools/scripts/h2py.py
@@ -23,13 +23,13 @@
 
 import sys, re, getopt, os
 
-p_define = re.compile('^[\t ]*#[\t ]*define[\t ]+([a-zA-Z0-9_]+)[\t ]+')
+p_define = re.compile(r'^[\t ]*#[\t ]*define[\t ]+([a-zA-Z0-9_]+)[\t ]+')
 
 p_macro = re.compile(
-  '^[\t ]*#[\t ]*define[\t ]+'
-  '([a-zA-Z0-9_]+)\(([_a-zA-Z][_a-zA-Z0-9]*)\)[\t ]+')
+  r'^[\t ]*#[\t ]*define[\t ]+'
+  r'([a-zA-Z0-9_]+)\(([_a-zA-Z][_a-zA-Z0-9]*)\)[\t ]+')
 
-p_include = re.compile('^[\t ]*#[\t ]*include[\t ]+<([^>\n]+)>')
+p_include = re.compile(r'^[\t ]*#[\t ]*include[\t ]+<([^>\n]+)>')
 
 p_comment = re.compile(r'/\*([^*]+|\*+[^/])*(\*+/)?')
 p_cpp_comment = re.compile('//.*')
diff --git a/Tools/scripts/highlight.py b/Tools/scripts/highlight.py
--- a/Tools/scripts/highlight.py
+++ b/Tools/scripts/highlight.py
@@ -147,14 +147,14 @@
 #### LaTeX Output ##########################################
 
 default_latex_commands = {
-    'comment': '{\color{red}#1}',
-    'string': '{\color{ForestGreen}#1}',
-    'docstring': '{\emph{\color{ForestGreen}#1}}',
-    'keyword': '{\color{orange}#1}',
-    'builtin': '{\color{purple}#1}',
-    'definition': '{\color{orange}#1}',
-    'defname': '{\color{blue}#1}',
-    'operator': '{\color{brown}#1}',
+    'comment': r'{\color{red}#1}',
+    'string': r'{\color{ForestGreen}#1}',
+    'docstring': r'{\emph{\color{ForestGreen}#1}}',
+    'keyword': r'{\color{orange}#1}',
+    'builtin': r'{\color{purple}#1}',
+    'definition': r'{\color{orange}#1}',
+    'defname': r'{\color{blue}#1}',
+    'operator': r'{\color{brown}#1}',
 }
 
 default_latex_document = r'''
diff --git a/Tools/scripts/mailerdaemon.py b/Tools/scripts/mailerdaemon.py
--- a/Tools/scripts/mailerdaemon.py
+++ b/Tools/scripts/mailerdaemon.py
@@ -88,7 +88,7 @@
 # no more expressions are searched for.  So, order is important.
 emparse_list_reason = [
     r'^5\d{2} <>\.\.\. (?P<reason>.*)',
-    '<>\.\.\. (?P<reason>.*)',
+    r'<>\.\.\. (?P<reason>.*)',
     re.compile(r'^<<< 5\d{2} (?P<reason>.*)', re.MULTILINE),
     re.compile('===== stderr was =====\nrmail: (?P<reason>.*)'),
     re.compile('^Diagnostic-Code: (?P<reason>.*)', re.MULTILINE),
diff --git a/Tools/scripts/parseentities.py b/Tools/scripts/parseentities.py
--- a/Tools/scripts/parseentities.py
+++ b/Tools/scripts/parseentities.py
@@ -14,7 +14,7 @@
 """
 import re,sys
 
-entityRE = re.compile('<!ENTITY +(\w+) +CDATA +"([^"]+)" +-- +((?:.|\n)+?) *-->')
+entityRE = re.compile(r'<!ENTITY +(\w+) +CDATA +"([^"]+)" +-- +((?:.|\n)+?) *-->')
 
 def parse(text,pos=0,endpos=None):
 
@@ -39,7 +39,7 @@
         if charcode[:2] == '&#':
             code = int(charcode[2:-1])
             if code < 256:
-                charcode = "'\%o'" % code
+                charcode = r"'\%o'" % code
             else:
                 charcode = repr(charcode)
         else:
diff --git a/Tools/scripts/pathfix.py b/Tools/scripts/pathfix.py
--- a/Tools/scripts/pathfix.py
+++ b/Tools/scripts/pathfix.py
@@ -64,7 +64,7 @@
             if fix(arg): bad = 1
     sys.exit(bad)
 
-ispythonprog = re.compile('^[a-zA-Z0-9_]+\.py$')
+ispythonprog = re.compile(r'^[a-zA-Z0-9_]+\.py$')
 def ispython(name):
     return bool(ispythonprog.match(name))
 
diff --git a/Tools/scripts/ptags.py b/Tools/scripts/ptags.py
--- a/Tools/scripts/ptags.py
+++ b/Tools/scripts/ptags.py
@@ -24,7 +24,7 @@
         for s in tags: fp.write(s)
 
 
-expr = '^[ \t]*(def|class)[ \t]+([a-zA-Z0-9_]+)[ \t]*[:\(]'
+expr = r'^[ \t]*(def|class)[ \t]+([a-zA-Z0-9_]+)[ \t]*[:\(]'
 matcher = re.compile(expr)
 
 def treat_file(filename):
diff --git a/Tools/scripts/svneol.py b/Tools/scripts/svneol.py
--- a/Tools/scripts/svneol.py
+++ b/Tools/scripts/svneol.py
@@ -1,6 +1,6 @@
 #! /usr/bin/env python3
 
-"""
+r"""
 SVN helper script.
 
 Try to set the svn:eol-style property to "native" on every .py, .txt, .c and
diff --git a/Tools/scripts/texi2html.py b/Tools/scripts/texi2html.py
--- a/Tools/scripts/texi2html.py
+++ b/Tools/scripts/texi2html.py
@@ -78,11 +78,11 @@
                                                   # running text
                                                   #
                                                   # menu item (Yuck!)
-miprog = re.compile('^\* ([^:]*):(:|[ \t]*([^\t,\n.]+)([^ \t\n]*))[ \t\n]*')
-#                   0    1     1 2        3          34         42        0
-#                         -----            ----------  ---------
-#                                 -|-----------------------------
-#                    -----------------------------------------------------
+miprog = re.compile(r'^\* ([^:]*):(:|[ \t]*([^\t,\n.]+)([^ \t\n]*))[ \t\n]*')
+#                    0    1     1 2        3          34         42        0
+#                          -----            ----------  ---------
+#                                  -|-----------------------------
+#                     -----------------------------------------------------
 
 
 
diff --git a/Tools/unicode/gencodec.py b/Tools/unicode/gencodec.py
--- a/Tools/unicode/gencodec.py
+++ b/Tools/unicode/gencodec.py
@@ -37,11 +37,11 @@
 # Placeholder for a missing code point
 MISSING_CODE = -1
 
-mapRE = re.compile('((?:0x[0-9a-fA-F]+\+?)+)'
-                   '\s+'
-                   '((?:(?:0x[0-9a-fA-Z]+|<[A-Za-z]+>)\+?)*)'
-                   '\s*'
-                   '(#.+)?')
+mapRE = re.compile(r'((?:0x[0-9a-fA-F]+\+?)+)'
+                   r'\s+'
+                   r'((?:(?:0x[0-9a-fA-Z]+|<[A-Za-z]+>)\+?)*)'
+                   r'\s*'
+                   r'(#.+)?')
 
 def parsecodes(codes, len=len, range=range):
 
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -838,7 +838,7 @@
         # find out which version of OpenSSL we have
         openssl_ver = 0
         openssl_ver_re = re.compile(
-            '^\s*#\s*define\s+OPENSSL_VERSION_NUMBER\s+(0x[0-9a-fA-F]+)' )
+            r'^\s*#\s*define\s+OPENSSL_VERSION_NUMBER\s+(0x[0-9a-fA-F]+)' )
 
         # look for the openssl version header on the compiler search path.
         opensslv_h = find_file('openssl/opensslv.h', [],
@@ -1724,7 +1724,7 @@
         # All existing framework builds of Tcl/Tk don't support 64-bit
         # architectures.
         cflags = sysconfig.get_config_vars('CFLAGS')[0]
-        archs = re.findall('-arch\s+(\w+)', cflags)
+        archs = re.findall(r'-arch\s+(\w+)', cflags)
 
         tmpfile = os.path.join(self.build_temp, 'tk.arch')
         if not os.path.exists(self.build_temp):

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list