tools: Use raw strings for regexps in python scripts (fixes #3677)
Starting with Python 3.12, use of invalid escape sequences in strings is reported as a SyntaxWarning and will become a SyntaxError at a later point. Regular expressions use the backslash character a lot, which result in warnings of this kind. Python docs recommend to generally use raw strings for this purpose.
This commit is contained in:
parent
c45f88643a
commit
1482ffe749
|
@ -133,11 +133,11 @@ class cef_api_hash:
|
|||
def __parse_objects(self, content):
|
||||
""" Returns array of objects in content file. """
|
||||
objects = []
|
||||
content = re.sub("//.*\n", "", content)
|
||||
content = re.sub(r"//.*\n", "", content)
|
||||
|
||||
# function declarations
|
||||
for m in re.finditer(
|
||||
"\nCEF_EXPORT\s+?.*?\s+?(\w+)\s*?\(.*?\)\s*?;",
|
||||
r"\nCEF_EXPORT\s+?.*?\s+?(\w+)\s*?\(.*?\)\s*?;",
|
||||
content,
|
||||
flags=re.DOTALL):
|
||||
object = {"name": m.group(1), "text": m.group(0).strip()}
|
||||
|
@ -145,7 +145,7 @@ class cef_api_hash:
|
|||
|
||||
# structs
|
||||
for m in re.finditer(
|
||||
"\ntypedef\s+?struct\s+?(\w+)\s+?\{.*?\}\s+?(\w+)\s*?;",
|
||||
r"\ntypedef\s+?struct\s+?(\w+)\s+?\{.*?\}\s+?(\w+)\s*?;",
|
||||
content,
|
||||
flags=re.DOTALL):
|
||||
object = {"name": m.group(2), "text": m.group(0).strip()}
|
||||
|
@ -153,12 +153,12 @@ class cef_api_hash:
|
|||
|
||||
# enums
|
||||
for m in re.finditer(
|
||||
"\ntypedef\s+?enum\s+?\{.*?\}\s+?(\w+)\s*?;", content, flags=re.DOTALL):
|
||||
r"\ntypedef\s+?enum\s+?\{.*?\}\s+?(\w+)\s*?;", content, flags=re.DOTALL):
|
||||
object = {"name": m.group(1), "text": m.group(0).strip()}
|
||||
objects.append(object)
|
||||
|
||||
# typedefs
|
||||
for m in re.finditer("\ntypedef\s+?.*?\s+(\w+);", content, flags=0):
|
||||
for m in re.finditer(r"\ntypedef\s+?.*?\s+(\w+);", content, flags=0):
|
||||
object = {"name": m.group(1), "text": m.group(0).strip()}
|
||||
objects.append(object)
|
||||
|
||||
|
@ -168,7 +168,7 @@ class cef_api_hash:
|
|||
""" Grab defined CEF_STRING_TYPE_xxx """
|
||||
objects = []
|
||||
for m in re.finditer(
|
||||
"\n\s*?#\s*?define\s+?(CEF_STRING_TYPE_\w+)\s+?.*?\n", content,
|
||||
r"\n\s*?#\s*?define\s+?(CEF_STRING_TYPE_\w+)\s+?.*?\n", content,
|
||||
flags=0):
|
||||
object = {
|
||||
"name": m.group(1),
|
||||
|
@ -179,8 +179,8 @@ class cef_api_hash:
|
|||
|
||||
def __prepare_text(self, text):
|
||||
text = text.strip()
|
||||
text = re.sub("\s+", " ", text)
|
||||
text = re.sub("\(\s+", "(", text)
|
||||
text = re.sub(r"\s+", " ", text)
|
||||
text = re.sub(r"\(\s+", "(", text)
|
||||
return text
|
||||
|
||||
def __get_final_sig(self, objects, platform):
|
||||
|
|
|
@ -273,7 +273,7 @@ def format_translation_includes(header, body):
|
|||
result += '#include "libcef_dll/template_util.h"\n'
|
||||
|
||||
# identify what CppToC classes are being used
|
||||
p = re.compile('([A-Za-z0-9_]{1,})CppToC')
|
||||
p = re.compile(r'([A-Za-z0-9_]{1,})CppToC')
|
||||
list = sorted(set(p.findall(body)))
|
||||
for item in list:
|
||||
directory = ''
|
||||
|
@ -286,7 +286,7 @@ def format_translation_includes(header, body):
|
|||
get_capi_name(item[3:], False)+'_cpptoc.h"\n'
|
||||
|
||||
# identify what CToCpp classes are being used
|
||||
p = re.compile('([A-Za-z0-9_]{1,})CToCpp')
|
||||
p = re.compile(r'([A-Za-z0-9_]{1,})CToCpp')
|
||||
list = sorted(set(p.findall(body)))
|
||||
for item in list:
|
||||
directory = ''
|
||||
|
@ -355,21 +355,21 @@ def dict_to_str(dict):
|
|||
|
||||
|
||||
# regex for matching comment-formatted attributes
|
||||
_cre_attrib = '/\*--cef\(([A-Za-z0-9_ ,=:\n]{0,})\)--\*/'
|
||||
_cre_attrib = r'/\*--cef\(([A-Za-z0-9_ ,=:\n]{0,})\)--\*/'
|
||||
# regex for matching class and function names
|
||||
_cre_cfname = '([A-Za-z0-9_]{1,})'
|
||||
_cre_cfname = r'([A-Za-z0-9_]{1,})'
|
||||
# regex for matching class and function names including path separators
|
||||
_cre_cfnameorpath = '([A-Za-z0-9_\/]{1,})'
|
||||
_cre_cfnameorpath = r'([A-Za-z0-9_\/]{1,})'
|
||||
# regex for matching typedef value and name combination
|
||||
_cre_typedef = '([A-Za-z0-9_<>:,\*\&\s]{1,})'
|
||||
_cre_typedef = r'([A-Za-z0-9_<>:,\*\&\s]{1,})'
|
||||
# regex for matching function return value and name combination
|
||||
_cre_func = '([A-Za-z][A-Za-z0-9_<>:,\*\&\s]{1,})'
|
||||
_cre_func = r'([A-Za-z][A-Za-z0-9_<>:,\*\&\s]{1,})'
|
||||
# regex for matching virtual function modifiers + arbitrary whitespace
|
||||
_cre_vfmod = '([\sA-Za-z0-9_]{0,})'
|
||||
_cre_vfmod = r'([\sA-Za-z0-9_]{0,})'
|
||||
# regex for matching arbitrary whitespace
|
||||
_cre_space = '[\s]{1,}'
|
||||
_cre_space = r'[\s]{1,}'
|
||||
# regex for matching optional virtual keyword
|
||||
_cre_virtual = '(?:[\s]{1,}virtual){0,1}'
|
||||
_cre_virtual = r'(?:[\s]{1,}virtual){0,1}'
|
||||
|
||||
# Simple translation types. Format is:
|
||||
# 'cpp_type' : ['capi_type', 'capi_default_value']
|
||||
|
@ -437,11 +437,11 @@ def get_function_impls(content, ident, has_impl=True):
|
|||
content = content.replace('NO_SANITIZE("cfi-icall")\n', '')
|
||||
|
||||
# extract the functions
|
||||
find_regex = '\n' + _cre_func + '\((.*?)\)([A-Za-z0-9_\s]{0,})'
|
||||
find_regex = r'\n' + _cre_func + r'\((.*?)\)([A-Za-z0-9_\s]{0,})'
|
||||
if has_impl:
|
||||
find_regex += '\{(.*?)\n\}'
|
||||
find_regex += r'\{(.*?)\n\}'
|
||||
else:
|
||||
find_regex += '(;)'
|
||||
find_regex += r'(;)'
|
||||
p = re.compile(find_regex, re.MULTILINE | re.DOTALL)
|
||||
list = p.findall(content)
|
||||
|
||||
|
@ -603,7 +603,7 @@ class obj_header:
|
|||
data = data.replace("> >", ">>")
|
||||
|
||||
# extract global typedefs
|
||||
p = re.compile('\ntypedef' + _cre_space + _cre_typedef + ';',
|
||||
p = re.compile(r'\ntypedef' + _cre_space + _cre_typedef + r';',
|
||||
re.MULTILINE | re.DOTALL)
|
||||
list = p.findall(data)
|
||||
if len(list) > 0:
|
||||
|
@ -617,7 +617,7 @@ class obj_header:
|
|||
self.typedefs.append(obj_typedef(self, filename, value, alias))
|
||||
|
||||
# extract global functions
|
||||
p = re.compile('\n' + _cre_attrib + '\n' + _cre_func + '\((.*?)\)',
|
||||
p = re.compile(r'\n' + _cre_attrib + r'\n' + _cre_func + r'\((.*?)\)',
|
||||
re.MULTILINE | re.DOTALL)
|
||||
list = p.findall(data)
|
||||
if len(list) > 0:
|
||||
|
@ -631,17 +631,17 @@ class obj_header:
|
|||
obj_function(self, filename, attrib, retval, argval, comment))
|
||||
|
||||
# extract includes
|
||||
p = re.compile('\n#include \"include/' + _cre_cfnameorpath + '.h')
|
||||
p = re.compile(r'\n#include \"include/' + _cre_cfnameorpath + r'.h')
|
||||
includes = p.findall(data)
|
||||
|
||||
# extract forward declarations
|
||||
p = re.compile('\nclass' + _cre_space + _cre_cfname + ';')
|
||||
p = re.compile(r'\nclass' + _cre_space + _cre_cfname + r';')
|
||||
forward_declares = p.findall(data)
|
||||
|
||||
# extract empty classes
|
||||
p = re.compile('\n' + _cre_attrib + '\nclass' + _cre_space + _cre_cfname +
|
||||
_cre_space + ':' + _cre_space + 'public' + _cre_virtual +
|
||||
_cre_space + _cre_cfname + _cre_space + '{};',
|
||||
p = re.compile(r'\n' + _cre_attrib + r'\nclass' + _cre_space + _cre_cfname +
|
||||
_cre_space + r':' + _cre_space + r'public' + _cre_virtual +
|
||||
_cre_space + _cre_cfname + _cre_space + r'{};',
|
||||
re.MULTILINE | re.DOTALL)
|
||||
list = p.findall(data)
|
||||
if len(list) > 0:
|
||||
|
@ -663,9 +663,9 @@ class obj_header:
|
|||
data = p.sub('', data)
|
||||
|
||||
# extract classes
|
||||
p = re.compile('\n' + _cre_attrib + '\nclass' + _cre_space + _cre_cfname +
|
||||
_cre_space + ':' + _cre_space + 'public' + _cre_virtual +
|
||||
_cre_space + _cre_cfname + _cre_space + '{(.*?)\n};',
|
||||
p = re.compile(r'\n' + _cre_attrib + r'\nclass' + _cre_space + _cre_cfname +
|
||||
_cre_space + r':' + _cre_space + r'public' + _cre_virtual +
|
||||
_cre_space + _cre_cfname + _cre_space + r'{(.*?)\n};',
|
||||
re.MULTILINE | re.DOTALL)
|
||||
list = p.findall(data)
|
||||
if len(list) > 0:
|
||||
|
@ -852,7 +852,7 @@ class obj_class:
|
|||
|
||||
# extract typedefs
|
||||
p = re.compile(
|
||||
'\n' + _cre_space + 'typedef' + _cre_space + _cre_typedef + ';',
|
||||
r'\n' + _cre_space + r'typedef' + _cre_space + _cre_typedef + r';',
|
||||
re.MULTILINE | re.DOTALL)
|
||||
list = p.findall(body)
|
||||
|
||||
|
@ -867,8 +867,8 @@ class obj_class:
|
|||
self.typedefs.append(obj_typedef(self, filename, value, alias))
|
||||
|
||||
# extract static functions
|
||||
p = re.compile('\n' + _cre_space + _cre_attrib + '\n' + _cre_space +
|
||||
'static' + _cre_space + _cre_func + '\((.*?)\)',
|
||||
p = re.compile(r'\n' + _cre_space + _cre_attrib + r'\n' + _cre_space +
|
||||
r'static' + _cre_space + _cre_func + r'\((.*?)\)',
|
||||
re.MULTILINE | re.DOTALL)
|
||||
list = p.findall(body)
|
||||
|
||||
|
@ -882,8 +882,8 @@ class obj_class:
|
|||
|
||||
# extract virtual functions
|
||||
p = re.compile(
|
||||
'\n' + _cre_space + _cre_attrib + '\n' + _cre_space + 'virtual' +
|
||||
_cre_space + _cre_func + '\((.*?)\)' + _cre_vfmod,
|
||||
r'\n' + _cre_space + _cre_attrib + r'\n' + _cre_space + r'virtual' +
|
||||
_cre_space + _cre_func + r'\((.*?)\)' + _cre_vfmod,
|
||||
re.MULTILINE | re.DOTALL)
|
||||
list = p.findall(body)
|
||||
|
||||
|
@ -1766,7 +1766,7 @@ class obj_analysis:
|
|||
return {'result_type': 'structure', 'result_value': value}
|
||||
|
||||
# check for CEF reference pointers
|
||||
p = re.compile('^CefRefPtr<(.*?)>$', re.DOTALL)
|
||||
p = re.compile(r'^CefRefPtr<(.*?)>$', re.DOTALL)
|
||||
list = p.findall(value)
|
||||
if len(list) == 1:
|
||||
return {
|
||||
|
@ -1776,7 +1776,7 @@ class obj_analysis:
|
|||
}
|
||||
|
||||
# check for CEF owned pointers
|
||||
p = re.compile('^CefOwnPtr<(.*?)>$', re.DOTALL)
|
||||
p = re.compile(r'^CefOwnPtr<(.*?)>$', re.DOTALL)
|
||||
list = p.findall(value)
|
||||
if len(list) == 1:
|
||||
return {
|
||||
|
@ -1786,7 +1786,7 @@ class obj_analysis:
|
|||
}
|
||||
|
||||
# check for CEF raw pointers
|
||||
p = re.compile('^CefRawPtr<(.*?)>$', re.DOTALL)
|
||||
p = re.compile(r'^CefRawPtr<(.*?)>$', re.DOTALL)
|
||||
list = p.findall(value)
|
||||
if len(list) == 1:
|
||||
return {
|
||||
|
|
|
@ -34,10 +34,10 @@ def MakeFileSegment(input, all_names):
|
|||
# #define IDR_RESOURCE_NAME 12345
|
||||
# [1] See https://crbug.com/684788#c18
|
||||
|
||||
regex = '#define\s([A-Za-z0-9_]{1,})\s+'
|
||||
regex = r'#define\s([A-Za-z0-9_]{1,})\s+'
|
||||
if contents.find('ui::WhitelistedResource') > 0:
|
||||
regex += '.*<'
|
||||
regex += '([0-9]{1,})'
|
||||
regex += r'.*<'
|
||||
regex += r'([0-9]{1,})'
|
||||
|
||||
# identify the defines in the file
|
||||
p = re.compile(regex)
|
||||
|
|
Loading…
Reference in New Issue