Commit a547a3f9 authored by Mike Frysinger's avatar Mike Frysinger Committed by Commit Bot

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/+/1758425Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688659}
parent bac502d7
...@@ -66,7 +66,7 @@ class UberClique(object): ...@@ -66,7 +66,7 @@ class UberClique(object):
# can trigger some build environments (Visual Studio, we're # can trigger some build environments (Visual Studio, we're
# looking at you) to consider invocation of grit to have failed, # looking at you) to consider invocation of grit to have failed,
# so we make sure never to output that word. # 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 = '' ellipsis = ''
if len(text) > 40: if len(text) > 40:
ellipsis = '...' ellipsis = '...'
...@@ -312,7 +312,7 @@ class MessageClique(object): ...@@ -312,7 +312,7 @@ class MessageClique(object):
CONSTANT_TRANSLATION = tclib.Translation(text='TTTTTT') CONSTANT_TRANSLATION = tclib.Translation(text='TTTTTT')
# A pattern to match messages that are empty or whitespace only. # 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, def __init__(self, uber_clique, message, translateable=True,
custom_type=None): custom_type=None):
...@@ -419,7 +419,7 @@ class MessageClique(object): ...@@ -419,7 +419,7 @@ class MessageClique(object):
translation if requested. translation if requested.
Args: Args:
lang_re: re.compile('fr|en') lang_re: re.compile(r'fr|en')
include_pseudo: True include_pseudo: True
Return: Return:
......
...@@ -77,7 +77,7 @@ _TAGGED_ONLY_DEFAULT = False ...@@ -77,7 +77,7 @@ _TAGGED_ONLY_DEFAULT = False
# In tagged-only mode, only messages with this tag will be ouputted. # In tagged-only mode, only messages with this tag will be ouputted.
_EMIT_TAG = 'android_java' _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 # Most strings are output as a <string> element. Note the double quotes
# around the value to preserve whitespace. # around the value to preserve whitespace.
...@@ -95,7 +95,7 @@ _PLURALS_PATTERN = lazy_re.compile(r'\{[A-Z_]+,\s*plural,(?P<items>.*)\}$', ...@@ -95,7 +95,7 @@ _PLURALS_PATTERN = lazy_re.compile(r'\{[A-Z_]+,\s*plural,(?P<items>.*)\}$',
# Repeatedly matched against the <items> capture in _PLURALS_PATTERN, # Repeatedly matched against the <items> capture in _PLURALS_PATTERN,
# to match "<quantity>{<value>}". # to match "<quantity>{<value>}".
_PLURALS_ITEM_PATTERN = lazy_re.compile(r'(?P<quantity>\S+?)\s*' _PLURALS_ITEM_PATTERN = lazy_re.compile(r'(?P<quantity>\S+?)\s*'
'\{(?P<value>.*?)\}') r'\{(?P<value>.*?)\}')
_PLURALS_QUANTITY_MAP = { _PLURALS_QUANTITY_MAP = {
'=0': 'zero', '=0': 'zero',
'zero': 'zero', 'zero': 'zero',
......
...@@ -21,9 +21,9 @@ import sys ...@@ -21,9 +21,9 @@ import sys
# #define IDS_FOO_MESSAGE 1234 # #define IDS_FOO_MESSAGE 1234
# With generate whitelist flag: # With generate whitelist flag:
# #define IDS_FOO_MESSAGE (::ui::WhitelistedResource<1234>(), 1234) # #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): def _GetResourceNameIdPairsIter(string_to_scan):
......
...@@ -39,18 +39,18 @@ DIST_SUBSTR = '%DISTRIBUTION%' ...@@ -39,18 +39,18 @@ DIST_SUBSTR = '%DISTRIBUTION%'
# Matches beginning of an "if" block. # Matches beginning of an "if" block.
_BEGIN_IF_BLOCK = lazy_re.compile( _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. # 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. # Used by DoInline to replace various links with inline content.
_STYLESHEET_RE = lazy_re.compile( _STYLESHEET_RE = lazy_re.compile(
'<link rel="stylesheet"[^>]+?href="(?P<filename>[^"]*)".*?>(\s*</link>)?', r'<link rel="stylesheet"[^>]+?href="(?P<filename>[^"]*)".*?>(\s*</link>)?',
re.DOTALL) re.DOTALL)
_INCLUDE_RE = lazy_re.compile( _INCLUDE_RE = lazy_re.compile(
'<include[^>]+?src=("(?P<file1>[^">]*)"|\'(?P<file2>[^\'>]*)\').*?>' + r'<include[^>]+?src=("(?P<file1>[^">]*)"|\'(?P<file2>[^\'>]*)\').*?>'
'(\s*</include>)?', r'(\s*</include>)?',
re.DOTALL) re.DOTALL)
_SRC_RE = lazy_re.compile( _SRC_RE = lazy_re.compile(
r'<(?!script)(?:[^>]+?\s)src="(?!\[\[|{{)(?P<filename>[^"\']*)"', r'<(?!script)(?:[^>]+?\s)src="(?!\[\[|{{)(?P<filename>[^"\']*)"',
...@@ -73,7 +73,7 @@ _SRCSET_ENTRY_RE = lazy_re.compile( ...@@ -73,7 +73,7 @@ _SRCSET_ENTRY_RE = lazy_re.compile(
re.MULTILINE) re.MULTILINE)
_ICON_RE = lazy_re.compile( _ICON_RE = lazy_re.compile(
r'<link rel="icon"\s(?:[^>]+?\s)?' r'<link rel="icon"\s(?:[^>]+?\s)?'
'href=(?P<quote>")(?P<filename>[^"\']*)\1', r'href=(?P<quote>")(?P<filename>[^"\']*)\1',
re.MULTILINE) re.MULTILINE)
...@@ -443,17 +443,18 @@ def DoInline( ...@@ -443,17 +443,18 @@ def DoInline(
"""Helper function that returns a string for a regex that matches url('') """Helper function that returns a string for a regex that matches url('')
but not url([[ ]]) or url({{ }}). Appends |postfix| to group names. 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) return url_re % (postfix, postfix, postfix)
def InlineCSSImages(text, filepath=input_filepath): def InlineCSSImages(text, filepath=input_filepath):
"""Helper function that inlines external images in CSS backgrounds.""" """Helper function that inlines external images in CSS backgrounds."""
# Replace contents of url() for css attributes: content, background, # Replace contents of url() for css attributes: content, background,
# or *-image. # 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. # Replace group names to prevent duplicates when forming value_re.
image_set_value_re = 'image-set\(([ ]*' + GetUrlRegexString('2') + \ image_set_value_re = (r'image-set\(([ ]*' + GetUrlRegexString('2') +
'[ ]*[0-9.]*x[ ]*(,[ ]*)?)+\)' r'[ ]*[0-9.]*x[ ]*(,[ ]*)?)+\)')
value_re = '(%s|%s)' % (GetUrlRegexString(), image_set_value_re) value_re = '(%s|%s)' % (GetUrlRegexString(), image_set_value_re)
css_re = property_re + value_re css_re = property_re + value_re
return re.sub(css_re, lambda m: InlineCSSUrls(m, filepath), text) return re.sub(css_re, lambda m: InlineCSSUrls(m, filepath), text)
...@@ -469,7 +470,7 @@ def DoInline( ...@@ -469,7 +470,7 @@ def DoInline(
"""Helper function that inlines CSS files included via the @import """Helper function that inlines CSS files included via the @import
directive. directive.
""" """
return re.sub('@import\s+' + GetUrlRegexString() + ';', return re.sub(r'@import\s+' + GetUrlRegexString() + r';',
lambda m: InlineCSSFile(m, '%s', filepath), lambda m: InlineCSSFile(m, '%s', filepath),
text) text)
...@@ -491,8 +492,8 @@ def DoInline( ...@@ -491,8 +492,8 @@ def DoInline(
if not allow_external_script: if not allow_external_script:
# We need to inline css and js before we inline images so that image # We need to inline css and js before we inline images so that image
# references gets inlined in the css and js # references gets inlined in the css and js
flat_text = re.sub('<script (?P<attrs1>.*?)src="(?P<filename>[^"\']*)"' + flat_text = re.sub(r'<script (?P<attrs1>.*?)src="(?P<filename>[^"\']*)"'
'(?P<attrs2>.*?)></script>', r'(?P<attrs2>.*?)></script>',
InlineScript, InlineScript,
flat_text) flat_text)
......
...@@ -52,14 +52,14 @@ class DummyOutput(object): ...@@ -52,14 +52,14 @@ class DummyOutput(object):
class FormatRcUnittest(unittest.TestCase): class FormatRcUnittest(unittest.TestCase):
def testMessages(self): def testMessages(self):
root = util.ParseGrdForUnittest(''' root = util.ParseGrdForUnittest("""
<messages> <messages>
<message name="IDS_BTN_GO" desc="Button text" meaning="verb">Go!</message> <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"> <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? Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today?
</message> </message>
<message name="BONGO" desc="Flippo nippo"> <message name="BONGO" desc="Flippo nippo">
Howdie "Mr. Elephant", how are you doing? \'\'\' Howdie "Mr. Elephant", how are you doing? '''
</message> </message>
<message name="IDS_WITH_LINEBREAKS"> <message name="IDS_WITH_LINEBREAKS">
Good day sir, Good day sir,
...@@ -67,7 +67,7 @@ I am a bee ...@@ -67,7 +67,7 @@ I am a bee
Sting sting Sting sting
</message> </message>
</messages> </messages>
''') """)
buf = StringIO() buf = StringIO()
build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en'), buf) build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en'), buf)
...@@ -82,11 +82,11 @@ BEGIN ...@@ -82,11 +82,11 @@ BEGIN
END''', output) END''', output)
def testRcSection(self): def testRcSection(self):
root = util.ParseGrdForUnittest(''' root = util.ParseGrdForUnittest(r'''
<structures> <structures>
<structure type="menu" name="IDC_KLONKMENU" 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="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="version" name="VS_VERSION_INFO" file="grit\testdata\klonk.rc" encoding="utf-16" />
</structures>''') </structures>''')
root.SetOutputLanguage('en') root.SetOutputLanguage('en')
root.RunGatherers() root.RunGatherers()
...@@ -177,7 +177,7 @@ END'''.strip() ...@@ -177,7 +177,7 @@ END'''.strip()
% (util.normpath('/temp/bingo.html').replace('\\', '\\\\'), % (util.normpath('/temp/bingo.html').replace('\\', '\\\\'),
util.normpath('/temp/bingo2.html').replace('\\', '\\\\'))) util.normpath('/temp/bingo2.html').replace('\\', '\\\\')))
# hackety hack to work on win32&lin # 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) self.assertEqual(expected, output)
def testRcIncludeFile(self): def testRcIncludeFile(self):
...@@ -196,7 +196,7 @@ END'''.strip() ...@@ -196,7 +196,7 @@ END'''.strip()
% (util.normpath('/temp/bingo.txt').replace('\\', '\\\\'), % (util.normpath('/temp/bingo.txt').replace('\\', '\\\\'),
'bingo2.txt')) 'bingo2.txt'))
# hackety hack to work on win32&lin # 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) self.assertEqual(expected, output)
def testRcIncludeFlattenedHtmlFile(self): def testRcIncludeFlattenedHtmlFile(self):
...@@ -215,7 +215,7 @@ END'''.strip() ...@@ -215,7 +215,7 @@ END'''.strip()
expected = (_PREAMBLE + expected = (_PREAMBLE +
u'HTML_FILE1 BINDATA "HTML_FILE1_include_test.html"') u'HTML_FILE1 BINDATA "HTML_FILE1_include_test.html"')
# hackety hack to work on win32&lin # 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) self.assertEqual(expected, output)
file_contents = util.ReadFile(output_file, util.RAW_TEXT) file_contents = util.ReadFile(output_file, util.RAW_TEXT)
...@@ -238,7 +238,7 @@ END'''.strip() ...@@ -238,7 +238,7 @@ END'''.strip()
def testStructureNodeOutputfile(self): def testStructureNodeOutputfile(self):
input_file = util.PathFromRoot('grit/testdata/simple.html') input_file = util.PathFromRoot('grit/testdata/simple.html')
root = util.ParseGrdForUnittest('''\ root = util.ParseGrdForUnittest('''
<structures> <structures>
<structure type="tr_html" name="IDR_HTML" file="%s" /> <structure type="tr_html" name="IDR_HTML" file="%s" />
</structures>''' % input_file) </structures>''' % input_file)
...@@ -263,7 +263,7 @@ END'''.strip() ...@@ -263,7 +263,7 @@ END'''.strip()
def testChromeHtmlNodeOutputfile(self): def testChromeHtmlNodeOutputfile(self):
input_file = util.PathFromRoot('grit/testdata/chrome_html.html') input_file = util.PathFromRoot('grit/testdata/chrome_html.html')
output_file = '%s/HTML_FILE1_chrome_html.html' % tempfile.gettempdir() output_file = '%s/HTML_FILE1_chrome_html.html' % tempfile.gettempdir()
root = util.ParseGrdForUnittest('''\ root = util.ParseGrdForUnittest('''
<structures> <structures>
<structure type="chrome_html" name="HTML_FILE1" file="%s" flattenhtml="true" /> <structure type="chrome_html" name="HTML_FILE1" file="%s" flattenhtml="true" />
</structures>''' % input_file) </structures>''' % input_file)
...@@ -281,7 +281,7 @@ END'''.strip() ...@@ -281,7 +281,7 @@ END'''.strip()
expected = (_PREAMBLE + expected = (_PREAMBLE +
u'HTML_FILE1 BINDATA "HTML_FILE1_chrome_html.html"') u'HTML_FILE1 BINDATA "HTML_FILE1_chrome_html.html"')
# hackety hack to work on win32&lin # 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) self.assertEqual(expected, output)
file_contents = util.ReadFile(output_file, util.RAW_TEXT) file_contents = util.ReadFile(output_file, util.RAW_TEXT)
...@@ -320,9 +320,9 @@ END'''.strip() ...@@ -320,9 +320,9 @@ END'''.strip()
os.remove(ar_file) os.remove(ar_file)
def testFallbackToEnglish(self): def testFallbackToEnglish(self):
root = util.ParseGrdForUnittest('''\ root = util.ParseGrdForUnittest(r'''
<structures fallback_to_english="True"> <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('.')) </structures>''', base_dir=util.PathFromRoot('.'))
root.SetOutputLanguage('en') root.SetOutputLanguage('en')
root.RunGatherers() root.RunGatherers()
...@@ -348,16 +348,16 @@ END''', output) ...@@ -348,16 +348,16 @@ END''', output)
def testSubstitutionRc(self): 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" <grit latest_public_release="2" source_lang_id="en-US" current_release="3"
base_dir="."> base_dir=".">
<outputs> <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> </outputs>
<release seq="1" allow_pseudo="False"> <release seq="1" allow_pseudo="False">
<structures> <structures>
<structure type="menu" name="IDC_KLONKMENU" <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" /> expand_variables="true" />
</structures> </structures>
<messages> <messages>
......
...@@ -30,12 +30,12 @@ class AdmGatherer(regexp.RegexpGatherer): ...@@ -30,12 +30,12 @@ class AdmGatherer(regexp.RegexpGatherer):
# Finds the strings section as the group named 'strings' # Finds the strings section as the group named 'strings'
_STRINGS_SECTION = lazy_re.compile( _STRINGS_SECTION = lazy_re.compile(
'(?P<first_part>.+^\[strings\])(?P<strings>.+)\Z', r'(?P<first_part>.+^\[strings\])(?P<strings>.+)\Z',
re.MULTILINE | re.DOTALL) re.MULTILINE | re.DOTALL)
# Finds the translateable sections from within the [strings] section. # Finds the translateable sections from within the [strings] section.
_TRANSLATEABLES = lazy_re.compile( _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) re.MULTILINE)
def Escape(self, text): def Escape(self, text):
......
...@@ -31,27 +31,27 @@ DIST_SUBSTR = '%DISTRIBUTION%' ...@@ -31,27 +31,27 @@ DIST_SUBSTR = '%DISTRIBUTION%'
# Matches a chrome theme source URL. # Matches a chrome theme source URL.
_THEME_SOURCE = lazy_re.compile( _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. # 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'. # Matches CSS url() functions with the capture group 'filename'.
_CSS_URL = lazy_re.compile(_CSS_URL_PATTERN) _CSS_URL = lazy_re.compile(_CSS_URL_PATTERN)
# Matches one or more CSS image urls used in given properties. # Matches one or more CSS image urls used in given properties.
_CSS_IMAGE_URLS = lazy_re.compile( _CSS_IMAGE_URLS = lazy_re.compile(
'(?P<attribute>content|background|[\w-]*-image):\s*' + r'(?P<attribute>content|background|[\w-]*-image):\s*'
'(?P<urls>(' + _CSS_URL_PATTERN + '\s*,?\s*)+)') r'(?P<urls>(' + _CSS_URL_PATTERN + r'\s*,?\s*)+)')
# Matches CSS image sets. # Matches CSS image sets.
_CSS_IMAGE_SETS = lazy_re.compile( _CSS_IMAGE_SETS = lazy_re.compile(
'(?P<attribute>content|background|[\w-]*-image):[ ]*' + r'(?P<attribute>content|background|[\w-]*-image):[ ]*'
'-webkit-image-set\((?P<images>' + r'-webkit-image-set\((?P<images>'
'(\s*,?\s*url\((?P<quote>"|\'|)[^"\'()]*(?P=quote)\)[ ]*[0-9.]*x)*)\)', r'(\s*,?\s*url\((?P<quote>"|\'|)[^"\'()]*(?P=quote)\)[ ]*[0-9.]*x)*)\)',
re.MULTILINE) re.MULTILINE)
# Matches a single image in a CSS image set with the capture group scale. # Matches a single image in a CSS image set with the capture group scale.
_CSS_IMAGE_SET_IMAGE = lazy_re.compile('\s*,?\s*' + _CSS_IMAGE_SET_IMAGE = lazy_re.compile(r'\s*,?\s*'
'url\((?P<quote>"|\'|)[^"\'()]*(?P=quote)\)[ ]*(?P<scale>[0-9.]*x)', r'url\((?P<quote>"|\'|)[^"\'()]*(?P=quote)\)[ ]*(?P<scale>[0-9.]*x)',
re.MULTILINE) re.MULTILINE)
_HTML_IMAGE_SRC = lazy_re.compile( _HTML_IMAGE_SRC = lazy_re.compile(
'<img[^>]+src=\"(?P<filename>[^">]*)\"[^>]*>') r'<img[^>]+src=\"(?P<filename>[^">]*)\"[^>]*>')
def GetImageList( def GetImageList(
base_path, filename, scale_factors, distribution, base_path, filename, scale_factors, distribution,
......
...@@ -119,7 +119,7 @@ class Dialog(Section): ...@@ -119,7 +119,7 @@ class Dialog(Section):
# group in alphabetical order. We also assume that there cannot be # group in alphabetical order. We also assume that there cannot be
# more than one description per regular expression match. # more than one description per regular expression match.
# If that's not the case some descriptions will be clobbered. # 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 # The dialog's ID in the first line
(?P<id1>[A-Z0-9_]+)\s+DIALOG(EX)? (?P<id1>[A-Z0-9_]+)\s+DIALOG(EX)?
| |
...@@ -185,7 +185,7 @@ class Menu(Section): ...@@ -185,7 +185,7 @@ class Menu(Section):
# A dandy regexp to suck all the IDs and translateables out of a menu # A dandy regexp to suck all the IDs and translateables out of a menu
# resource # resource
menu_re_ = lazy_re.compile(''' menu_re_ = lazy_re.compile(r'''
# Match the MENU ID on the first line # Match the MENU ID on the first line
^(?P<id1>[A-Z0-9_]+)\s+MENU ^(?P<id1>[A-Z0-9_]+)\s+MENU
| |
...@@ -249,7 +249,7 @@ class Version(Section): ...@@ -249,7 +249,7 @@ class Version(Section):
# In addition to the above fields, VALUE fields named "Comments" and # In addition to the above fields, VALUE fields named "Comments" and
# "LegalTrademarks" may also be translateable. # "LegalTrademarks" may also be translateable.
version_re_ = lazy_re.compile(''' version_re_ = lazy_re.compile(r'''
# Match the ID on the first line # Match the ID on the first line
^(?P<id1>[A-Z0-9_]+)\s+VERSIONINFO ^(?P<id1>[A-Z0-9_]+)\s+VERSIONINFO
| |
...@@ -277,7 +277,7 @@ class RCData(Section): ...@@ -277,7 +277,7 @@ class RCData(Section):
# #
# IDR_BLAH RCDATA { 1, 2, 3, 4 } # 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+\{.*?\} ^(?P<id1>[A-Z0-9_]+)\s+RCDATA\s+(DISCARDABLE)?\s+\{.*?\}
''', re.MULTILINE | re.VERBOSE | re.DOTALL) ''', re.MULTILINE | re.VERBOSE | re.DOTALL)
...@@ -326,7 +326,7 @@ class Accelerators(Section): ...@@ -326,7 +326,7 @@ class Accelerators(Section):
# VK_INSERT, ID_ACCELERATOR32772, VIRTKEY, CONTROL, NOINVERT # VK_INSERT, ID_ACCELERATOR32772, VIRTKEY, CONTROL, NOINVERT
# END # END
accelerators_re_ = lazy_re.compile(''' accelerators_re_ = lazy_re.compile(r'''
# Match the ID on the first line # Match the ID on the first line
^(?P<id1>[A-Z0-9_]+)\s+ACCELERATORS\s+ ^(?P<id1>[A-Z0-9_]+)\s+ACCELERATORS\s+
| |
......
...@@ -15,7 +15,7 @@ class WindowsFilename(clique.CustomType): ...@@ -15,7 +15,7 @@ class WindowsFilename(clique.CustomType):
illegal characters out of translations. illegal characters out of translations.
''' '''
BANNED = lazy_re.compile('\+|:|\/|\\\\|\*|\?|\"|\<|\>|\|') BANNED = lazy_re.compile(r'\+|:|\/|\\\\|\*|\?|\"|\<|\>|\|')
def Validate(self, message): def Validate(self, message):
return not self.BANNED.search(message.GetPresentableContent()) return not self.BANNED.search(message.GetPresentableContent())
......
...@@ -59,7 +59,7 @@ class MessageNode(base.ContentNode): ...@@ -59,7 +59,7 @@ class MessageNode(base.ContentNode):
# For splitting a list of things that can be separated by commas or # For splitting a list of things that can be separated by commas or
# whitespace # whitespace
_SPLIT_RE = lazy_re.compile('\s*,\s*|\s+') _SPLIT_RE = lazy_re.compile(r'\s*,\s*|\s+')
def __init__(self): def __init__(self):
super(MessageNode, self).__init__() super(MessageNode, self).__init__()
...@@ -101,7 +101,7 @@ class MessageNode(base.ContentNode): ...@@ -101,7 +101,7 @@ class MessageNode(base.ContentNode):
return True return True
def SetReplaceEllipsis(self, value): def SetReplaceEllipsis(self, value):
'''Sets whether to replace ... with \u2026. r'''Sets whether to replace ... with \u2026.
''' '''
self._replace_ellipsis = value self._replace_ellipsis = value
......
...@@ -392,7 +392,7 @@ class IfNodeUnittest(unittest.TestCase): ...@@ -392,7 +392,7 @@ class IfNodeUnittest(unittest.TestCase):
self.assertNotEquals(outputs, ['uncond1.rc', 'uncond2.adm', 'iftest.h']) self.assertNotEquals(outputs, ['uncond1.rc', 'uncond2.adm', 'iftest.h'])
def testChildrenAccepted(self): 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="."> <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
<release seq="3"> <release seq="3">
<includes> <includes>
...@@ -407,11 +407,11 @@ class IfNodeUnittest(unittest.TestCase): ...@@ -407,11 +407,11 @@ class IfNodeUnittest(unittest.TestCase):
</includes> </includes>
<structures> <structures>
<if expr="'bingo' in defs"> <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>
<if expr="'bingo' in defs"> <if expr="'bingo' in defs">
<if expr="'hello' 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>
</if> </if>
</structures> </structures>
...@@ -440,24 +440,24 @@ class IfNodeUnittest(unittest.TestCase): ...@@ -440,24 +440,24 @@ class IfNodeUnittest(unittest.TestCase):
def testIfBadChildrenNesting(self): def testIfBadChildrenNesting(self):
# includes # 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="."> <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
<release seq="3"> <release seq="3">
<includes> <includes>
<if expr="'bingo' in defs"> <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>
</includes> </includes>
</release> </release>
</grit>''') </grit>''')
self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml)
# messages # 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="."> <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
<release seq="3"> <release seq="3">
<messages> <messages>
<if expr="'bingo' in defs"> <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>
</messages> </messages>
</release> </release>
...@@ -486,26 +486,26 @@ class IfNodeUnittest(unittest.TestCase): ...@@ -486,26 +486,26 @@ class IfNodeUnittest(unittest.TestCase):
</grit>''') </grit>''')
self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml)
# same with nesting # 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="."> <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
<release seq="3"> <release seq="3">
<includes> <includes>
<if expr="'bingo' in defs"> <if expr="'bingo' in defs">
<if expr="'hello' 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>
</if> </if>
</includes> </includes>
</release> </release>
</grit>''') </grit>''')
self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) 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="."> <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
<release seq="3"> <release seq="3">
<messages> <messages>
<if expr="'bingo' in defs"> <if expr="'bingo' in defs">
<if expr="'hello' 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>
</if> </if>
</messages> </messages>
......
...@@ -54,7 +54,7 @@ class StructureNode(base.Node): ...@@ -54,7 +54,7 @@ class StructureNode(base.Node):
# VALUE must escape all commas: ',' -> ',,'. Each variable definition # VALUE must escape all commas: ',' -> ',,'. Each variable definition
# should be separated by a comma with no extra whitespace. # should be separated by a comma with no extra whitespace.
# Example: THING1=foo,THING2=bar # Example: THING1=foo,THING2=bar
variable_pattern = re.compile('([^,=\s]+)=((?:,,|[^,])*)') variable_pattern = re.compile(r'([^,=\s]+)=((?:,,|[^,])*)')
def __init__(self): def __init__(self):
super(StructureNode, self).__init__() super(StructureNode, self).__init__()
......
...@@ -131,7 +131,7 @@ class TclibUnittest(unittest.TestCase): ...@@ -131,7 +131,7 @@ class TclibUnittest(unittest.TestCase):
'AddinMenus=notegdsplugin.dll\r\n' 'AddinMenus=notegdsplugin.dll\r\n'
'\r\n' '\r\n'
'If the notesgdsplugin.dll file is not in the application directory\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' 'installation, it is likely that Notes was not installed correctly. \r\n'
'\r\n' '\r\n'
'Only local databases can be indexed. If they can be determined, \r\n' 'Only local databases can be indexed. If they can be determined, \r\n'
...@@ -156,7 +156,7 @@ class TclibUnittest(unittest.TestCase): ...@@ -156,7 +156,7 @@ class TclibUnittest(unittest.TestCase):
'you can get to the preferences, add the following line to your \r\n' 'you can get to the preferences, add the following line to your \r\n'
'notes.ini file:\r\n' 'notes.ini file:\r\n'
'GDSNoIndexHistory=1\r\n') 'GDSNoIndexHistory=1\r\n')
self.failUnless(id == '3138901326664699350') self.assertEqual(id, '7660964495923572726')
def testPlaceholderNameChecking(self): def testPlaceholderNameChecking(self):
try: try:
......
...@@ -34,12 +34,12 @@ _CHAR_LIMIT = lazy_re.compile(r'\[CHAR-LIMIT=(\d+)\]') ...@@ -34,12 +34,12 @@ _CHAR_LIMIT = lazy_re.compile(r'\[CHAR-LIMIT=(\d+)\]')
# Finds String.Format() style format specifiers such as "%-5.2f". # Finds String.Format() style format specifiers such as "%-5.2f".
_FORMAT_SPECIFIER = lazy_re.compile( _FORMAT_SPECIFIER = lazy_re.compile(
'%' r'%'
'([1-9][0-9]*\$|<)?' # argument_index r'([1-9][0-9]*\$|<)?' # argument_index
'([-#+ 0,(]*)' # flags r'([-#+ 0,(]*)' # flags
'([0-9]+)?' # width r'([0-9]+)?' # width
'(\.[0-9]+)?' # precision r'(\.[0-9]+)?' # precision
'([bBhHsScCdoxXeEfgGaAtT%n])') # conversion r'([bBhHsScCdoxXeEfgGaAtT%n])') # conversion
class Android2Grd(interface.Tool): class Android2Grd(interface.Tool):
......
...@@ -33,7 +33,7 @@ from grit import util ...@@ -33,7 +33,7 @@ from grit import util
# Matches files referenced from an .rc file # 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<id>[A-Z_0-9.]+)[ \t]+
(?P<type>[A-Z_0-9]+)[ \t]+ (?P<type>[A-Z_0-9]+)[ \t]+
"(?P<file>.*?([^"]|""))"[ \t]*$''', re.VERBOSE | re.MULTILINE) "(?P<file>.*?([^"]|""))"[ \t]*$''', re.VERBOSE | re.MULTILINE)
...@@ -41,31 +41,31 @@ _FILE_REF = lazy_re.compile(''' ...@@ -41,31 +41,31 @@ _FILE_REF = lazy_re.compile('''
# Matches a dialog section # Matches a dialog section
_DIALOG = lazy_re.compile( _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) re.MULTILINE | re.DOTALL)
# Matches a menu section # 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) re.MULTILINE | re.DOTALL)
# Matches a versioninfo section # Matches a versioninfo section
_VERSIONINFO = lazy_re.compile( _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) re.MULTILINE | re.DOTALL)
# Matches a stringtable # Matches a stringtable
_STRING_TABLE = lazy_re.compile( _STRING_TABLE = lazy_re.compile(
('^STRINGTABLE(\s+(PRELOAD|DISCARDABLE|CHARACTERISTICS.+|LANGUAGE.+|' (r'^STRINGTABLE(\s+(PRELOAD|DISCARDABLE|CHARACTERISTICS.+|LANGUAGE.+|'
'VERSION.+))*\s*\nBEGIN\s*$(?P<body>.+?)^END\s*$'), r'VERSION.+))*\s*\nBEGIN\s*$(?P<body>.+?)^END\s*$'),
re.MULTILINE | re.DOTALL) re.MULTILINE | re.DOTALL)
# Matches each message inside a stringtable, breaking it up into comments, # Matches each message inside a stringtable, breaking it up into comments,
# the ID of the message, and the (RC-escaped) message text. # 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 (?P<comment>(^\s+//.+?)*) # 0 or more lines of comments preceding the message
^\s* ^\s*
(?P<id>[A-Za-z0-9_]+) # id (?P<id>[A-Za-z0-9_]+) # id
...@@ -75,11 +75,11 @@ _MESSAGE = lazy_re.compile(''' ...@@ -75,11 +75,11 @@ _MESSAGE = lazy_re.compile('''
# Matches each line of comment text in a multi-line comment. # 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 # 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 # Finds printf and FormatMessage style format specifiers
...@@ -88,9 +88,9 @@ _WHITESPACE_ONLY = lazy_re.compile('\A\s*\Z', re.MULTILINE) ...@@ -88,9 +88,9 @@ _WHITESPACE_ONLY = lazy_re.compile('\A\s*\Z', re.MULTILINE)
# replace with placeholders. # replace with placeholders.
# TODO(joi) Check documentation for printf (and Windows variants) and FormatMessage # TODO(joi) Check documentation for printf (and Windows variants) and FormatMessage
_FORMAT_SPECIFIER = lazy_re.compile( _FORMAT_SPECIFIER = lazy_re.compile(
'(%[-# +]?(?:[0-9]*|\*)(?:\.(?:[0-9]+|\*))?(?:h|l|L)?' # printf up to last char r'(%[-# +]?(?:[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 r'(?: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'|\$[1-9][0-9]*)') # FormatMessage
class Rc2Grd(interface.Tool): class Rc2Grd(interface.Tool):
......
...@@ -50,7 +50,7 @@ PROJECT_TEMPLATE = '''\ ...@@ -50,7 +50,7 @@ PROJECT_TEMPLATE = '''\
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"> UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
<File <File
RelativePath=".\[[DIALOG_NAME]].rc"> RelativePath=".\\[[DIALOG_NAME]].rc">
</File> </File>
</Filter> </Filter>
</Files> </Files>
......
...@@ -324,7 +324,7 @@ def FixupNamedParam(function, param_name, param_value): ...@@ -324,7 +324,7 @@ def FixupNamedParam(function, param_name, param_value):
def PathFromRoot(path): 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 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). current working directory (i.e .a path you can use to open the file).
...@@ -574,8 +574,8 @@ class Substituter(object): ...@@ -574,8 +574,8 @@ class Substituter(object):
A regular expression object. A regular expression object.
''' '''
if self.dirty_: if self.dirty_:
components = ['\[%s\]' % (k,) for k in self.substitutions_] components = [r'\[%s\]' % (k,) for k in self.substitutions_]
self.exp = re.compile("(%s)" % ('|'.join(components),)) self.exp = re.compile(r'(%s)' % ('|'.join(components),))
self.dirty_ = False self.dirty_ = False
return self.exp return self.exp
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment