diff --git a/pootle/apps/pootle_misc/checks.py b/pootle/apps/pootle_misc/checks.py index b93c0ae729..8ed61f0f46 100644 --- a/pootle/apps/pootle_misc/checks.py +++ b/pootle/apps/pootle_misc/checks.py @@ -125,58 +125,58 @@ # pre-compile all regexps -fmt = u"\{\d+(?:,(?:number|date|time|choice))\}" -fmt_esc = u"\\\{\d+\\\}" +fmt = r"{\d+(?:,(?:number|date|time|choice))}" +fmt_esc = r"\\{\d+\\}" java_format_regex = re.compile(u"(%s|%s)" % (fmt, fmt_esc)) -fmt = u"\$\{[a-zA-Z_\d\.\:]+\}" +fmt = r"\${[a-zA-Z_\d\.\:]+}" template_format_regex = re.compile(u"(%s)" % fmt) -fmt = u"%\d+\$[a-z]+" +fmt = r"%\d+\$[a-z]+" android_format_regex = re.compile(u"(%s)" % fmt) -fmt = u"%@|%\d+\$@" +fmt = r"%@|%\d+\$@" objective_c_format_regex = re.compile(u"(%s)" % fmt) -fmt = u"\\\\u[a-fA-F0-9]{4}" +fmt = r"\\\\u[a-fA-F0-9]{4}" javaencoded_unicode_regex = re.compile(u"(%s)" % fmt) -fmt = u"\$[a-zA-Z_\d]+?(?![\$\%])" +fmt = r"\$[a-zA-Z_\d]+?(?![$%])" dollar_sign_placeholders_regex = re.compile(u"(%s)" % fmt) -fmt = u"\$[a-zA-Z_\d]+?\$" +fmt = r"\$[a-zA-Z_\d]+?\$" dollar_sign_closure_placeholders_regex = re.compile(u"(%s)" % fmt) -fmt = u"\%\%[a-zA-Z_\d]+?\%\%" +fmt = r"%%[a-zA-Z_\d]+?%%" percent_sign_closure_placeholders_regex = re.compile(u"(%s)" % fmt) -fmt = u"\%[a-zA-Z_]+?(?![\$\%])" +fmt = r"%[a-zA-Z_]+?(?![$%])" percent_sign_placeholders_regex = re.compile(u"(%s)" % fmt) -fmt = u"[A-Z_][A-Z0-9]*_[A-Z0-9_]*(?![a-z])" +fmt = r"[A-Z_][A-Z0-9]*_[A-Z0-9_]*(?![a-z])" uppercase_placeholders_regex = re.compile(u"(%s)" % fmt) -fmt4 = u"\{{1}\d+,[^\}]+\}{1}" -fmt3 = u"\{{3}\S+?\}{3}" -fmt2 = u"\{{2}\S+?\}{2}" -fmt1 = u"\{{1}\S+?\}{1}" +fmt4 = r"{{1}\d+,[^}]+}{1}" +fmt3 = r"{{3}\S+?}{3}" +fmt2 = r"{{2}\S+?}{2}" +fmt1 = r"{{1}\S+?}{1}" mustache_placeholders_regex = re.compile( u"(%s|%s|%s|%s)" % (fmt4, fmt3, fmt2, fmt1)) mustache_placeholder_pairs_open_tag_regex = re.compile( - u"\{{2}[#\^][^\}]+\}{2}") -fmt = u"\{{2}[#\^\/][^\}]+\}{2}" + r"{{2}[#^][^}]+}{2}") +fmt = r"{{2}[#^/][^}]+}{2}" mustache_placeholder_pairs_regex = re.compile(u"(%s)" % fmt) -fmt = u"\{{2}[\/]?[^\}]+\}{2}" +fmt = r"{{2}/?[^}]+}{2}" mustache_like_placeholder_pairs_regex = re.compile(u"(%s)" % fmt) # date_format -df_blocks = u"|".join( - map(lambda x: '%s+' % x, 'GyYMwWDdFEuaHkKhmsSzZX')) + u"|\'[\w]+\'" -df_glued_blocks = u"X+|Z+|\'[\w]*\'" -df_delimiter = u"[^\w']+|\'[\w]*\'" +df_blocks = "|".join( + map(lambda x: '%s+' % x, 'GyYMwWDdFEuaHkKhmsSzZX')) + r"|'[\w]+'" +df_glued_blocks = r"X+|Z+|'[\w]*'" +df_delimiter = r"[^\w']+|'[\w]*'" date_format_regex = re.compile( u"^(%(blocks)s)(%(glued_blocks)s)?((%(delimiter)s)+(%(blocks)s))*$" % { 'blocks': df_blocks, @@ -185,63 +185,63 @@ }) date_format_exception_regex = re.compile(u"^(M|S|W|F)$", re.I) -fmt = u"^\s+|\s+$" +fmt = r"^\s+|\s+$" whitespace_regex = re.compile(u"(%s)" % fmt) -fmt = u"&#\d+;|&[a-zA-Z]+;|&#x[0-9a-fA-F]+;" +fmt = r"&#\d+;|&[a-zA-Z]+;|&#x[0-9a-fA-F]+;" escaped_entities_regex = re.compile(u"(%s)" % fmt) broken_ampersand_regex = re.compile(u"(&[^#a-zA-Z]+)") -img_banner_regex = re.compile(u'^\]" +fmt = r"[<>]" unbalanced_tag_braces_regex = re.compile(u"(%s)" % fmt) -fmt = u"[\{\}]" +fmt = r"[{}]" unbalanced_curly_braces_regex = re.compile(u"(%s)" % fmt) fmt = u'^<(Sync Required|None|no attributes|no tags|' + \ u'no saved|searches|notebook|not available)>$' no_tags_regex = re.compile(fmt) -fmt = u"<\/?[a-zA-Z_]+.*?>" -cdata_fmt = u'))*\]\]>' +fmt = r"" +cdata_fmt = r'))*\]\]>' tags_differ_regex_0 = re.compile(u"(%s|%s)" % (fmt, cdata_fmt)) -tags_differ_regex_1 = re.compile(u"<(\/?[a-zA-Z_]+).*?>") +tags_differ_regex_1 = re.compile(r"<(/?[a-zA-Z_]+).*?>") -accelerators_regex_0 = re.compile(u"&(\w+);") -fmt = u"[&_\^]" -accelerators_regex_1 = re.compile(u"(%s)(?=\w)" % fmt) +accelerators_regex_0 = re.compile(r"&(\w+);") +fmt = r"[&_^]" +accelerators_regex_1 = re.compile(r"(%s)(?=\w)" % fmt) -fmt = u"&#?[0-9a-zA-Z]+;?" +fmt = r"&#?[0-9a-zA-Z]+;?" broken_entities_regex_0 = re.compile(u"(%s)" % fmt) entities = [ 'amp', 'deg', 'frac14', 'frac12', 'frac34', 'lt', 'gt', 'nbsp', 'mdash', 'ndash', 'hellip', 'laquo', 'raquo', 'ldquo', 'rdquo', 'lsquo', 'rsquo', 'larr', 'rarr' ] -broken_entities_regex_1 = re.compile(u"^&(%s)$" % '|'.join(entities)) -broken_entities_regex_2 = re.compile(u"^&#x?[0-9a-fA-F]+$") -broken_entities_regex_3 = re.compile(u"&\d+;") -broken_entities_regex_4 = re.compile(u"&x[0-9a-fA-F]+;") -broken_entities_regex_5 = re.compile(u"&#([^x\d])([0-9a-fA-F]+);") -broken_entities_regex_6 = re.compile(u"&#(\d+);") -broken_entities_regex_7 = re.compile(u"&#x([a-zA-Z_]+);") +broken_entities_regex_1 = re.compile(r"^&(%s)$" % '|'.join(entities)) +broken_entities_regex_2 = re.compile(r"^&#x?[0-9a-fA-F]+$") +broken_entities_regex_3 = re.compile(r"&\d+;") +broken_entities_regex_4 = re.compile(r"&x[0-9a-fA-F]+;") +broken_entities_regex_5 = re.compile(r"&#([^x\d])([0-9a-fA-F]+);") +broken_entities_regex_6 = re.compile(r"&#(\d+);") +broken_entities_regex_7 = re.compile(r"&#x([a-zA-Z_]+);") fmt = u"[$%_@]" potential_placeholders_regex = re.compile(u"(%s)" % fmt) -fmt = u"\%\{{1}[^\}]+\}{1}" +fmt = r"%{{1}[^}]+}{1}" percent_brace_placeholders_regex = re.compile(u"(%s)" % fmt) plurr_format_regex = re.compile(u'{[^{}]*:.*?}')