grit: clean up anomalous backslash in string warnings

Use r prefix for strings that have embedded backslashes,
and for any regex expression as that's the norm.

Bug: 983071
Test: `./grit/test_suite_all.py` passes
Change-Id: Id045e3bd9627f6c8234151104d757aeaf1469dbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1758425
Reviewed-by: Nico Weber <thakis@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688659}
diff --git a/tools/grit/grit/clique.py b/tools/grit/grit/clique.py
index 752e905..e7be3ec 100644
--- a/tools/grit/grit/clique.py
+++ b/tools/grit/grit/clique.py
@@ -66,7 +66,7 @@
       # can trigger some build environments (Visual Studio, we're
       # looking at you) to consider invocation of grit to have failed,
       # so we make sure never to output that word.
-      extract = re.sub('(?i)error', 'REDACTED', text[0:40])[0:40]
+      extract = re.sub(r'(?i)error', 'REDACTED', text[0:40])[0:40]
       ellipsis = ''
       if len(text) > 40:
         ellipsis = '...'
@@ -312,7 +312,7 @@
   CONSTANT_TRANSLATION = tclib.Translation(text='TTTTTT')
 
   # A pattern to match messages that are empty or whitespace only.
-  WHITESPACE_MESSAGE = lazy_re.compile(u'^\s*$')
+  WHITESPACE_MESSAGE = lazy_re.compile(r'^\s*$')
 
   def __init__(self, uber_clique, message, translateable=True,
                custom_type=None):
@@ -419,7 +419,7 @@
     translation if requested.
 
     Args:
-      lang_re: re.compile('fr|en')
+      lang_re: re.compile(r'fr|en')
       include_pseudo: True
 
     Return:
diff --git a/tools/grit/grit/format/android_xml.py b/tools/grit/grit/format/android_xml.py
index 62d61169..7eb2888 100644
--- a/tools/grit/grit/format/android_xml.py
+++ b/tools/grit/grit/format/android_xml.py
@@ -77,7 +77,7 @@
 # In tagged-only mode, only messages with this tag will be ouputted.
 _EMIT_TAG = 'android_java'
 
-_NAME_PATTERN = lazy_re.compile('IDS_(?P<name>[A-Z0-9_]+)\Z')
+_NAME_PATTERN = lazy_re.compile(r'IDS_(?P<name>[A-Z0-9_]+)\Z')
 
 # Most strings are output as a <string> element. Note the double quotes
 # around the value to preserve whitespace.
@@ -95,7 +95,7 @@
 # Repeatedly matched against the <items> capture in _PLURALS_PATTERN,
 # to match "<quantity>{<value>}".
 _PLURALS_ITEM_PATTERN = lazy_re.compile(r'(?P<quantity>\S+?)\s*'
-                                        '\{(?P<value>.*?)\}')
+                                        r'\{(?P<value>.*?)\}')
 _PLURALS_QUANTITY_MAP = {
   '=0': 'zero',
   'zero': 'zero',
diff --git a/tools/grit/grit/format/gen_predetermined_ids.py b/tools/grit/grit/format/gen_predetermined_ids.py
index 05e3ca8..9b2aa7b 100755
--- a/tools/grit/grit/format/gen_predetermined_ids.py
+++ b/tools/grit/grit/format/gen_predetermined_ids.py
@@ -21,9 +21,9 @@
 #   #define IDS_FOO_MESSAGE 1234
 # With generate whitelist flag:
 #   #define IDS_FOO_MESSAGE (::ui::WhitelistedResource<1234>(), 1234)
-RESOURCE_EXTRACT_REGEX = re.compile('^#define (\S*).* (\d+)\)?$', re.MULTILINE)
+RESOURCE_EXTRACT_REGEX = re.compile(r'^#define (\S*).* (\d+)\)?$', re.MULTILINE)
 
-ORDERED_RESOURCE_IDS_REGEX = re.compile('^Resource=(\d*)$', re.MULTILINE)
+ORDERED_RESOURCE_IDS_REGEX = re.compile(r'^Resource=(\d*)$', re.MULTILINE)
 
 
 def _GetResourceNameIdPairsIter(string_to_scan):
diff --git a/tools/grit/grit/format/html_inline.py b/tools/grit/grit/format/html_inline.py
index 4c454fe..45c2eebd 100755
--- a/tools/grit/grit/format/html_inline.py
+++ b/tools/grit/grit/format/html_inline.py
@@ -39,18 +39,18 @@
 
 # Matches beginning of an "if" block.
 _BEGIN_IF_BLOCK = lazy_re.compile(
-    '<if [^>]*?expr=("(?P<expr1>[^">]*)"|\'(?P<expr2>[^\'>]*)\')[^>]*?>')
+    r'<if [^>]*?expr=("(?P<expr1>[^">]*)"|\'(?P<expr2>[^\'>]*)\')[^>]*?>')
 
 # Matches ending of an "if" block.
-_END_IF_BLOCK = lazy_re.compile('</if>')
+_END_IF_BLOCK = lazy_re.compile(r'</if>')
 
 # Used by DoInline to replace various links with inline content.
 _STYLESHEET_RE = lazy_re.compile(
-    '<link rel="stylesheet"[^>]+?href="(?P<filename>[^"]*)".*?>(\s*</link>)?',
+    r'<link rel="stylesheet"[^>]+?href="(?P<filename>[^"]*)".*?>(\s*</link>)?',
     re.DOTALL)
 _INCLUDE_RE = lazy_re.compile(
-    '<include[^>]+?src=("(?P<file1>[^">]*)"|\'(?P<file2>[^\'>]*)\').*?>' +
-    '(\s*</include>)?',
+    r'<include[^>]+?src=("(?P<file1>[^">]*)"|\'(?P<file2>[^\'>]*)\').*?>'
+    r'(\s*</include>)?',
     re.DOTALL)
 _SRC_RE = lazy_re.compile(
     r'<(?!script)(?:[^>]+?\s)src="(?!\[\[|{{)(?P<filename>[^"\']*)"',
@@ -73,7 +73,7 @@
     re.MULTILINE)
 _ICON_RE = lazy_re.compile(
     r'<link rel="icon"\s(?:[^>]+?\s)?'
-    'href=(?P<quote>")(?P<filename>[^"\']*)\1',
+    r'href=(?P<quote>")(?P<filename>[^"\']*)\1',
     re.MULTILINE)
 
 
@@ -443,17 +443,18 @@
     """Helper function that returns a string for a regex that matches url('')
        but not url([[ ]]) or url({{ }}). Appends |postfix| to group names.
     """
-    url_re = 'url\((?!\[\[|{{)(?P<q%s>"|\'|)(?P<filename%s>[^"\'()]*)(?P=q%s)\)'
+    url_re = (r'url\((?!\[\[|{{)(?P<q%s>"|\'|)(?P<filename%s>[^"\'()]*)'
+              r'(?P=q%s)\)')
     return url_re % (postfix, postfix, postfix)
 
   def InlineCSSImages(text, filepath=input_filepath):
     """Helper function that inlines external images in CSS backgrounds."""
     # Replace contents of url() for css attributes: content, background,
     # or *-image.
-    property_re = '(content|background|[\w-]*-image):[^;]*'
+    property_re = r'(content|background|[\w-]*-image):[^;]*'
     # Replace group names to prevent duplicates when forming value_re.
-    image_set_value_re = 'image-set\(([ ]*' + GetUrlRegexString('2') + \
-        '[ ]*[0-9.]*x[ ]*(,[ ]*)?)+\)'
+    image_set_value_re = (r'image-set\(([ ]*' + GetUrlRegexString('2') +
+        r'[ ]*[0-9.]*x[ ]*(,[ ]*)?)+\)')
     value_re = '(%s|%s)' % (GetUrlRegexString(), image_set_value_re)
     css_re = property_re + value_re
     return re.sub(css_re, lambda m: InlineCSSUrls(m, filepath), text)
@@ -469,7 +470,7 @@
     """Helper function that inlines CSS files included via the @import
        directive.
     """
-    return re.sub('@import\s+' + GetUrlRegexString() + ';',
+    return re.sub(r'@import\s+' + GetUrlRegexString() + r';',
                   lambda m: InlineCSSFile(m, '%s', filepath),
                   text)
 
@@ -491,8 +492,8 @@
     if not allow_external_script:
       # We need to inline css and js before we inline images so that image
       # references gets inlined in the css and js
-      flat_text = re.sub('<script (?P<attrs1>.*?)src="(?P<filename>[^"\']*)"' +
-                         '(?P<attrs2>.*?)></script>',
+      flat_text = re.sub(r'<script (?P<attrs1>.*?)src="(?P<filename>[^"\']*)"'
+                         r'(?P<attrs2>.*?)></script>',
                          InlineScript,
                          flat_text)
 
diff --git a/tools/grit/grit/format/rc_unittest.py b/tools/grit/grit/format/rc_unittest.py
index f23702c..adf9523 100755
--- a/tools/grit/grit/format/rc_unittest.py
+++ b/tools/grit/grit/format/rc_unittest.py
@@ -52,14 +52,14 @@
 
 class FormatRcUnittest(unittest.TestCase):
   def testMessages(self):
-    root = util.ParseGrdForUnittest('''
+    root = util.ParseGrdForUnittest("""
       <messages>
           <message name="IDS_BTN_GO" desc="Button text" meaning="verb">Go!</message>
           <message name="IDS_GREETING" desc="Printed to greet the currently logged in user">
             Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today?
           </message>
           <message name="BONGO" desc="Flippo nippo">
-            Howdie "Mr. Elephant", how are you doing?   \'\'\'
+            Howdie "Mr. Elephant", how are you doing?   '''
           </message>
           <message name="IDS_WITH_LINEBREAKS">
 Good day sir,
@@ -67,7 +67,7 @@
 Sting sting
           </message>
       </messages>
-      ''')
+      """)
 
     buf = StringIO()
     build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en'), buf)
@@ -82,11 +82,11 @@
 END''', output)
 
   def testRcSection(self):
-    root = util.ParseGrdForUnittest('''
+    root = util.ParseGrdForUnittest(r'''
       <structures>
-          <structure type="menu" name="IDC_KLONKMENU" file="grit\\testdata\klonk.rc" encoding="utf-16" />
-          <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\testdata\klonk.rc" encoding="utf-16" />
-          <structure type="version" name="VS_VERSION_INFO" file="grit\\testdata\klonk.rc" encoding="utf-16" />
+          <structure type="menu" name="IDC_KLONKMENU" file="grit\testdata\klonk.rc" encoding="utf-16" />
+          <structure type="dialog" name="IDD_ABOUTBOX" file="grit\testdata\klonk.rc" encoding="utf-16" />
+          <structure type="version" name="VS_VERSION_INFO" file="grit\testdata\klonk.rc" encoding="utf-16" />
       </structures>''')
     root.SetOutputLanguage('en')
     root.RunGatherers()
@@ -177,7 +177,7 @@
                 % (util.normpath('/temp/bingo.html').replace('\\', '\\\\'),
                    util.normpath('/temp/bingo2.html').replace('\\', '\\\\')))
     # hackety hack to work on win32&lin
-    output = re.sub('"[c-zC-Z]:', '"', output)
+    output = re.sub(r'"[c-zC-Z]:', '"', output)
     self.assertEqual(expected, output)
 
   def testRcIncludeFile(self):
@@ -196,7 +196,7 @@
                 % (util.normpath('/temp/bingo.txt').replace('\\', '\\\\'),
                    'bingo2.txt'))
     # hackety hack to work on win32&lin
-    output = re.sub('"[c-zC-Z]:', '"', output)
+    output = re.sub(r'"[c-zC-Z]:', '"', output)
     self.assertEqual(expected, output)
 
   def testRcIncludeFlattenedHtmlFile(self):
@@ -215,7 +215,7 @@
     expected = (_PREAMBLE +
         u'HTML_FILE1         BINDATA            "HTML_FILE1_include_test.html"')
     # hackety hack to work on win32&lin
-    output = re.sub('"[c-zC-Z]:', '"', output)
+    output = re.sub(r'"[c-zC-Z]:', '"', output)
     self.assertEqual(expected, output)
 
     file_contents = util.ReadFile(output_file, util.RAW_TEXT)
@@ -238,7 +238,7 @@
 
   def testStructureNodeOutputfile(self):
     input_file = util.PathFromRoot('grit/testdata/simple.html')
-    root = util.ParseGrdForUnittest('''\
+    root = util.ParseGrdForUnittest('''
         <structures>
           <structure type="tr_html" name="IDR_HTML" file="%s" />
         </structures>''' % input_file)
@@ -263,7 +263,7 @@
   def testChromeHtmlNodeOutputfile(self):
     input_file = util.PathFromRoot('grit/testdata/chrome_html.html')
     output_file = '%s/HTML_FILE1_chrome_html.html' % tempfile.gettempdir()
-    root = util.ParseGrdForUnittest('''\
+    root = util.ParseGrdForUnittest('''
         <structures>
           <structure type="chrome_html" name="HTML_FILE1" file="%s" flattenhtml="true" />
         </structures>''' % input_file)
@@ -281,7 +281,7 @@
     expected = (_PREAMBLE +
         u'HTML_FILE1         BINDATA            "HTML_FILE1_chrome_html.html"')
     # hackety hack to work on win32&lin
-    output = re.sub('"[c-zC-Z]:', '"', output)
+    output = re.sub(r'"[c-zC-Z]:', '"', output)
     self.assertEqual(expected, output)
 
     file_contents = util.ReadFile(output_file, util.RAW_TEXT)
@@ -320,9 +320,9 @@
     os.remove(ar_file)
 
   def testFallbackToEnglish(self):
-    root = util.ParseGrdForUnittest('''\
+    root = util.ParseGrdForUnittest(r'''
         <structures fallback_to_english="True">
-          <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\testdata\klonk.rc" encoding="utf-16" />
+          <structure type="dialog" name="IDD_ABOUTBOX" file="grit\testdata\klonk.rc" encoding="utf-16" />
         </structures>''', base_dir=util.PathFromRoot('.'))
     root.SetOutputLanguage('en')
     root.RunGatherers()
@@ -348,16 +348,16 @@
 
 
   def testSubstitutionRc(self):
-    root = grd_reader.Parse(StringIO('''<?xml version="1.0" encoding="UTF-8"?>
+    root = grd_reader.Parse(StringIO(r'''<?xml version="1.0" encoding="UTF-8"?>
     <grit latest_public_release="2" source_lang_id="en-US" current_release="3"
           base_dir=".">
       <outputs>
-        <output lang="en" type="rc_all" filename="grit\\testdata\klonk_resources.rc"/>
+        <output lang="en" type="rc_all" filename="grit\testdata\klonk_resources.rc"/>
       </outputs>
       <release seq="1" allow_pseudo="False">
         <structures>
           <structure type="menu" name="IDC_KLONKMENU"
-              file="grit\\testdata\klonk.rc" encoding="utf-16"
+              file="grit\testdata\klonk.rc" encoding="utf-16"
               expand_variables="true" />
         </structures>
         <messages>
diff --git a/tools/grit/grit/gather/admin_template.py b/tools/grit/grit/gather/admin_template.py
index 15876b4..c26b6a8 100644
--- a/tools/grit/grit/gather/admin_template.py
+++ b/tools/grit/grit/gather/admin_template.py
@@ -30,12 +30,12 @@
 
   # Finds the strings section as the group named 'strings'
   _STRINGS_SECTION = lazy_re.compile(
-      '(?P<first_part>.+^\[strings\])(?P<strings>.+)\Z',
+      r'(?P<first_part>.+^\[strings\])(?P<strings>.+)\Z',
       re.MULTILINE | re.DOTALL)
 
   # Finds the translateable sections from within the [strings] section.
   _TRANSLATEABLES = lazy_re.compile(
-      '^\s*[A-Za-z0-9_]+\s*=\s*"(?P<text>.+)"\s*$',
+      r'^\s*[A-Za-z0-9_]+\s*=\s*"(?P<text>.+)"\s*$',
       re.MULTILINE)
 
   def Escape(self, text):
diff --git a/tools/grit/grit/gather/chrome_html.py b/tools/grit/grit/gather/chrome_html.py
index 9547964..68f677b 100644
--- a/tools/grit/grit/gather/chrome_html.py
+++ b/tools/grit/grit/gather/chrome_html.py
@@ -31,27 +31,27 @@
 
 # Matches a chrome theme source URL.
 _THEME_SOURCE = lazy_re.compile(
-    '(?P<baseurl>chrome://theme/IDR_[A-Z0-9_]*)(?P<query>\?.*)?')
+    r'(?P<baseurl>chrome://theme/IDR_[A-Z0-9_]*)(?P<query>\?.*)?')
 # Pattern for matching CSS url() function.
-_CSS_URL_PATTERN = 'url\((?P<quote>"|\'|)(?P<filename>[^"\'()]*)(?P=quote)\)'
+_CSS_URL_PATTERN = r'url\((?P<quote>"|\'|)(?P<filename>[^"\'()]*)(?P=quote)\)'
 # Matches CSS url() functions with the capture group 'filename'.
 _CSS_URL = lazy_re.compile(_CSS_URL_PATTERN)
 # Matches one or more CSS image urls used in given properties.
 _CSS_IMAGE_URLS = lazy_re.compile(
-    '(?P<attribute>content|background|[\w-]*-image):\s*' +
-        '(?P<urls>(' + _CSS_URL_PATTERN + '\s*,?\s*)+)')
+    r'(?P<attribute>content|background|[\w-]*-image):\s*'
+        r'(?P<urls>(' + _CSS_URL_PATTERN + r'\s*,?\s*)+)')
 # Matches CSS image sets.
 _CSS_IMAGE_SETS = lazy_re.compile(
-    '(?P<attribute>content|background|[\w-]*-image):[ ]*' +
-        '-webkit-image-set\((?P<images>' +
-        '(\s*,?\s*url\((?P<quote>"|\'|)[^"\'()]*(?P=quote)\)[ ]*[0-9.]*x)*)\)',
+    r'(?P<attribute>content|background|[\w-]*-image):[ ]*'
+        r'-webkit-image-set\((?P<images>'
+        r'(\s*,?\s*url\((?P<quote>"|\'|)[^"\'()]*(?P=quote)\)[ ]*[0-9.]*x)*)\)',
     re.MULTILINE)
 # Matches a single image in a CSS image set with the capture group scale.
-_CSS_IMAGE_SET_IMAGE = lazy_re.compile('\s*,?\s*' +
-    'url\((?P<quote>"|\'|)[^"\'()]*(?P=quote)\)[ ]*(?P<scale>[0-9.]*x)',
+_CSS_IMAGE_SET_IMAGE = lazy_re.compile(r'\s*,?\s*'
+    r'url\((?P<quote>"|\'|)[^"\'()]*(?P=quote)\)[ ]*(?P<scale>[0-9.]*x)',
     re.MULTILINE)
 _HTML_IMAGE_SRC = lazy_re.compile(
-    '<img[^>]+src=\"(?P<filename>[^">]*)\"[^>]*>')
+    r'<img[^>]+src=\"(?P<filename>[^">]*)\"[^>]*>')
 
 def GetImageList(
     base_path, filename, scale_factors, distribution,
diff --git a/tools/grit/grit/gather/rc.py b/tools/grit/grit/gather/rc.py
index 03135bdd..dd091d1e 100644
--- a/tools/grit/grit/gather/rc.py
+++ b/tools/grit/grit/gather/rc.py
@@ -119,7 +119,7 @@
   # group in alphabetical order. We also assume that there cannot be
   # more than one description per regular expression match.
   # If that's not the case some descriptions will be clobbered.
-  dialog_re_ = lazy_re.compile('''
+  dialog_re_ = lazy_re.compile(r'''
     # The dialog's ID in the first line
     (?P<id1>[A-Z0-9_]+)\s+DIALOG(EX)?
     |
@@ -185,7 +185,7 @@
 
   # A dandy regexp to suck all the IDs and translateables out of a menu
   # resource
-  menu_re_ = lazy_re.compile('''
+  menu_re_ = lazy_re.compile(r'''
     # Match the MENU ID on the first line
     ^(?P<id1>[A-Z0-9_]+)\s+MENU
     |
@@ -249,7 +249,7 @@
   # In addition to the above fields, VALUE fields named "Comments" and
   # "LegalTrademarks" may also be translateable.
 
-  version_re_ = lazy_re.compile('''
+  version_re_ = lazy_re.compile(r'''
     # Match the ID on the first line
     ^(?P<id1>[A-Z0-9_]+)\s+VERSIONINFO
     |
@@ -277,7 +277,7 @@
   #
   # IDR_BLAH        RCDATA      { 1, 2, 3, 4 }
 
-  dialog_re_ = lazy_re.compile('''
+  dialog_re_ = lazy_re.compile(r'''
     ^(?P<id1>[A-Z0-9_]+)\s+RCDATA\s+(DISCARDABLE)?\s+\{.*?\}
     ''', re.MULTILINE | re.VERBOSE | re.DOTALL)
 
@@ -326,7 +326,7 @@
   #   VK_INSERT,      ID_ACCELERATOR32772,    VIRTKEY, CONTROL, NOINVERT
   # END
 
-  accelerators_re_ = lazy_re.compile('''
+  accelerators_re_ = lazy_re.compile(r'''
     # Match the ID on the first line
     ^(?P<id1>[A-Z0-9_]+)\s+ACCELERATORS\s+
     |
diff --git a/tools/grit/grit/node/custom/filename.py b/tools/grit/grit/node/custom/filename.py
index cee18ec2..55a27e5 100644
--- a/tools/grit/grit/node/custom/filename.py
+++ b/tools/grit/grit/node/custom/filename.py
@@ -15,7 +15,7 @@
   illegal characters out of translations.
   '''
 
-  BANNED = lazy_re.compile('\+|:|\/|\\\\|\*|\?|\"|\<|\>|\|')
+  BANNED = lazy_re.compile(r'\+|:|\/|\\\\|\*|\?|\"|\<|\>|\|')
 
   def Validate(self, message):
     return not self.BANNED.search(message.GetPresentableContent())
diff --git a/tools/grit/grit/node/message.py b/tools/grit/grit/node/message.py
index cc8d217..83cc82c3d 100644
--- a/tools/grit/grit/node/message.py
+++ b/tools/grit/grit/node/message.py
@@ -59,7 +59,7 @@
 
   # For splitting a list of things that can be separated by commas or
   # whitespace
-  _SPLIT_RE = lazy_re.compile('\s*,\s*|\s+')
+  _SPLIT_RE = lazy_re.compile(r'\s*,\s*|\s+')
 
   def __init__(self):
     super(MessageNode, self).__init__()
@@ -101,7 +101,7 @@
     return True
 
   def SetReplaceEllipsis(self, value):
-    '''Sets whether to replace ... with \u2026.
+    r'''Sets whether to replace ... with \u2026.
     '''
     self._replace_ellipsis = value
 
diff --git a/tools/grit/grit/node/misc_unittest.py b/tools/grit/grit/node/misc_unittest.py
index 54bda95..c192b09 100755
--- a/tools/grit/grit/node/misc_unittest.py
+++ b/tools/grit/grit/node/misc_unittest.py
@@ -392,7 +392,7 @@
     self.assertNotEquals(outputs, ['uncond1.rc', 'uncond2.adm', 'iftest.h'])
 
   def testChildrenAccepted(self):
-    grd_reader.Parse(StringIO('''<?xml version="1.0"?>
+    grd_reader.Parse(StringIO(r'''<?xml version="1.0"?>
       <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
         <release seq="3">
           <includes>
@@ -407,11 +407,11 @@
           </includes>
           <structures>
             <if expr="'bingo' in defs">
-              <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\test\data\klonk.rc" encoding="utf-16" />
+              <structure type="dialog" name="IDD_ABOUTBOX" file="grit\test\data\klonk.rc" encoding="utf-16" />
             </if>
             <if expr="'bingo' in defs">
               <if expr="'hello' in defs">
-                <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\test\data\klonk.rc" encoding="utf-16" />
+                <structure type="dialog" name="IDD_ABOUTBOX" file="grit\test\data\klonk.rc" encoding="utf-16" />
               </if>
             </if>
           </structures>
@@ -440,24 +440,24 @@
 
   def testIfBadChildrenNesting(self):
     # includes
-    xml = StringIO('''<?xml version="1.0"?>
+    xml = StringIO(r'''<?xml version="1.0"?>
       <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
         <release seq="3">
           <includes>
             <if expr="'bingo' in defs">
-              <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\test\data\klonk.rc" encoding="utf-16" />
+              <structure type="dialog" name="IDD_ABOUTBOX" file="grit\test\data\klonk.rc" encoding="utf-16" />
             </if>
           </includes>
         </release>
       </grit>''')
     self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml)
     # messages
-    xml = StringIO('''<?xml version="1.0"?>
+    xml = StringIO(r'''<?xml version="1.0"?>
       <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
         <release seq="3">
           <messages>
             <if expr="'bingo' in defs">
-              <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\test\data\klonk.rc" encoding="utf-16" />
+              <structure type="dialog" name="IDD_ABOUTBOX" file="grit\test\data\klonk.rc" encoding="utf-16" />
             </if>
           </messages>
         </release>
@@ -486,26 +486,26 @@
       </grit>''')
     self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml)
     # same with nesting
-    xml = StringIO('''<?xml version="1.0"?>
+    xml = StringIO(r'''<?xml version="1.0"?>
       <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
         <release seq="3">
           <includes>
             <if expr="'bingo' in defs">
               <if expr="'hello' in defs">
-                <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\test\data\klonk.rc" encoding="utf-16" />
+                <structure type="dialog" name="IDD_ABOUTBOX" file="grit\test\data\klonk.rc" encoding="utf-16" />
               </if>
             </if>
           </includes>
         </release>
       </grit>''')
     self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml)
-    xml = StringIO('''<?xml version="1.0"?>
+    xml = StringIO(r'''<?xml version="1.0"?>
       <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
         <release seq="3">
           <messages>
             <if expr="'bingo' in defs">
               <if expr="'hello' in defs">
-                <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\test\data\klonk.rc" encoding="utf-16" />
+                <structure type="dialog" name="IDD_ABOUTBOX" file="grit\test\data\klonk.rc" encoding="utf-16" />
               </if>
             </if>
           </messages>
diff --git a/tools/grit/grit/node/structure.py b/tools/grit/grit/node/structure.py
index ed6e7c8..9c883590 100644
--- a/tools/grit/grit/node/structure.py
+++ b/tools/grit/grit/node/structure.py
@@ -54,7 +54,7 @@
   # VALUE must escape all commas: ',' -> ',,'.  Each variable definition
   # should be separated by a comma with no extra whitespace.
   # Example: THING1=foo,THING2=bar
-  variable_pattern = re.compile('([^,=\s]+)=((?:,,|[^,])*)')
+  variable_pattern = re.compile(r'([^,=\s]+)=((?:,,|[^,])*)')
 
   def __init__(self):
     super(StructureNode, self).__init__()
diff --git a/tools/grit/grit/tclib_unittest.py b/tools/grit/grit/tclib_unittest.py
index 8570c8f..7a08654 100755
--- a/tools/grit/grit/tclib_unittest.py
+++ b/tools/grit/grit/tclib_unittest.py
@@ -131,7 +131,7 @@
       'AddinMenus=notegdsplugin.dll\r\n'
       '\r\n'
       'If the notesgdsplugin.dll file is not in the application directory\r\n'
-      '(e.g., C:\Program Files\Lotus\Notes) after Google Desktop \r\n'
+      r'(e.g., C:\Program Files\Lotus\Notes) after Google Desktop \r\n'
       'installation, it is likely that Notes was not installed correctly. \r\n'
       '\r\n'
       'Only local databases can be indexed.  If they can be determined, \r\n'
@@ -156,7 +156,7 @@
       'you can get to the preferences, add the following line to your \r\n'
       'notes.ini file:\r\n'
       'GDSNoIndexHistory=1\r\n')
-    self.failUnless(id == '3138901326664699350')
+    self.assertEqual(id, '7660964495923572726')
 
   def testPlaceholderNameChecking(self):
     try:
diff --git a/tools/grit/grit/tool/android2grd.py b/tools/grit/grit/tool/android2grd.py
index afb61c4..005297b 100644
--- a/tools/grit/grit/tool/android2grd.py
+++ b/tools/grit/grit/tool/android2grd.py
@@ -34,12 +34,12 @@
 
 # Finds String.Format() style format specifiers such as "%-5.2f".
 _FORMAT_SPECIFIER = lazy_re.compile(
-  '%'
-  '([1-9][0-9]*\$|<)?'            # argument_index
-  '([-#+ 0,(]*)'                  # flags
-  '([0-9]+)?'                     # width
-  '(\.[0-9]+)?'                   # precision
-  '([bBhHsScCdoxXeEfgGaAtT%n])')  # conversion
+  r'%'
+  r'([1-9][0-9]*\$|<)?'            # argument_index
+  r'([-#+ 0,(]*)'                  # flags
+  r'([0-9]+)?'                     # width
+  r'(\.[0-9]+)?'                   # precision
+  r'([bBhHsScCdoxXeEfgGaAtT%n])')  # conversion
 
 
 class Android2Grd(interface.Tool):
diff --git a/tools/grit/grit/tool/rc2grd.py b/tools/grit/grit/tool/rc2grd.py
index 57fb682..ffbbba36 100644
--- a/tools/grit/grit/tool/rc2grd.py
+++ b/tools/grit/grit/tool/rc2grd.py
@@ -33,7 +33,7 @@
 
 
 # Matches files referenced from an .rc file
-_FILE_REF = lazy_re.compile('''
+_FILE_REF = lazy_re.compile(r'''
   ^(?P<id>[A-Z_0-9.]+)[ \t]+
   (?P<type>[A-Z_0-9]+)[ \t]+
   "(?P<file>.*?([^"]|""))"[ \t]*$''', re.VERBOSE | re.MULTILINE)
@@ -41,31 +41,31 @@
 
 # Matches a dialog section
 _DIALOG = lazy_re.compile(
-    '^(?P<id>[A-Z0-9_]+)\s+DIALOG(EX)?\s.+?^BEGIN\s*$.+?^END\s*$',
+    r'^(?P<id>[A-Z0-9_]+)\s+DIALOG(EX)?\s.+?^BEGIN\s*$.+?^END\s*$',
     re.MULTILINE | re.DOTALL)
 
 
 # Matches a menu section
-_MENU = lazy_re.compile('^(?P<id>[A-Z0-9_]+)\s+MENU.+?^BEGIN\s*$.+?^END\s*$',
+_MENU = lazy_re.compile(r'^(?P<id>[A-Z0-9_]+)\s+MENU.+?^BEGIN\s*$.+?^END\s*$',
                         re.MULTILINE | re.DOTALL)
 
 
 # Matches a versioninfo section
 _VERSIONINFO = lazy_re.compile(
-    '^(?P<id>[A-Z0-9_]+)\s+VERSIONINFO\s.+?^BEGIN\s*$.+?^END\s*$',
+    r'^(?P<id>[A-Z0-9_]+)\s+VERSIONINFO\s.+?^BEGIN\s*$.+?^END\s*$',
     re.MULTILINE | re.DOTALL)
 
 
 # Matches a stringtable
 _STRING_TABLE = lazy_re.compile(
-    ('^STRINGTABLE(\s+(PRELOAD|DISCARDABLE|CHARACTERISTICS.+|LANGUAGE.+|'
-     'VERSION.+))*\s*\nBEGIN\s*$(?P<body>.+?)^END\s*$'),
+    (r'^STRINGTABLE(\s+(PRELOAD|DISCARDABLE|CHARACTERISTICS.+|LANGUAGE.+|'
+     r'VERSION.+))*\s*\nBEGIN\s*$(?P<body>.+?)^END\s*$'),
     re.MULTILINE | re.DOTALL)
 
 
 # Matches each message inside a stringtable, breaking it up into comments,
 # the ID of the message, and the (RC-escaped) message text.
-_MESSAGE = lazy_re.compile('''
+_MESSAGE = lazy_re.compile(r'''
   (?P<comment>(^\s+//.+?)*)  # 0 or more lines of comments preceding the message
   ^\s*
   (?P<id>[A-Za-z0-9_]+)  # id
@@ -75,11 +75,11 @@
 
 
 # Matches each line of comment text in a multi-line comment.
-_COMMENT_TEXT = lazy_re.compile('^\s*//\s*(?P<text>.+?)$', re.MULTILINE)
+_COMMENT_TEXT = lazy_re.compile(r'^\s*//\s*(?P<text>.+?)$', re.MULTILINE)
 
 
 # Matches a string that is empty or all whitespace
-_WHITESPACE_ONLY = lazy_re.compile('\A\s*\Z', re.MULTILINE)
+_WHITESPACE_ONLY = lazy_re.compile(r'\A\s*\Z', re.MULTILINE)
 
 
 # Finds printf and FormatMessage style format specifiers
@@ -88,9 +88,9 @@
 # replace with placeholders.
 # TODO(joi) Check documentation for printf (and Windows variants) and FormatMessage
 _FORMAT_SPECIFIER = lazy_re.compile(
-  '(%[-# +]?(?:[0-9]*|\*)(?:\.(?:[0-9]+|\*))?(?:h|l|L)?' # printf up to last char
-  '(?:d|i|o|u|x|X|e|E|f|F|g|G|c|r|s|ls|ws)'              # printf last char
-  '|\$[1-9][0-9]*)')                                     # FormatMessage
+  r'(%[-# +]?(?:[0-9]*|\*)(?:\.(?:[0-9]+|\*))?(?:h|l|L)?' # printf up to last char
+  r'(?:d|i|o|u|x|X|e|E|f|F|g|G|c|r|s|ls|ws)'              # printf last char
+  r'|\$[1-9][0-9]*)')                                     # FormatMessage
 
 
 class Rc2Grd(interface.Tool):
diff --git a/tools/grit/grit/tool/resize.py b/tools/grit/grit/tool/resize.py
index 54c9801..6a897c0 100644
--- a/tools/grit/grit/tool/resize.py
+++ b/tools/grit/grit/tool/resize.py
@@ -50,7 +50,7 @@
       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
       <File
-        RelativePath=".\[[DIALOG_NAME]].rc">
+        RelativePath=".\\[[DIALOG_NAME]].rc">
       </File>
     </Filter>
   </Files>
diff --git a/tools/grit/grit/util.py b/tools/grit/grit/util.py
index d3755f1..9c524f8 100644
--- a/tools/grit/grit/util.py
+++ b/tools/grit/grit/util.py
@@ -324,7 +324,7 @@
 
 
 def PathFromRoot(path):
-  '''Takes a path relative to the root directory for GRIT (the one that grit.py
+  r'''Takes a path relative to the root directory for GRIT (the one that grit.py
   resides in) and returns a path that is either absolute or relative to the
   current working directory (i.e .a path you can use to open the file).
 
@@ -574,8 +574,8 @@
       A regular expression object.
     '''
     if self.dirty_:
-      components = ['\[%s\]' % (k,) for k in self.substitutions_]
-      self.exp = re.compile("(%s)" % ('|'.join(components),))
+      components = [r'\[%s\]' % (k,) for k in self.substitutions_]
+      self.exp = re.compile(r'(%s)' % ('|'.join(components),))
       self.dirty_ = False
     return self.exp