comparison libervia/backend/plugins/plugin_misc_uri_finder.py @ 4331:e0ae6ca806ba

plugin URI finder: make the regex ignore case.
author Goffi <goffi@goffi.org>
date Wed, 20 Nov 2024 15:29:47 +0100
parents 0d7bb4df2343
children 111dce64dcb5
comparison
equal deleted inserted replaced
4330:cb32d8c6a040 4331:e0ae6ca806ba
72 @param keys(list[unicode]): keys lookeds after 72 @param keys(list[unicode]): keys lookeds after
73 e.g.: "tickets", "merge-requests" 73 e.g.: "tickets", "merge-requests"
74 @return (dict[unicode, unicode]): map from key to found uri 74 @return (dict[unicode, unicode]): map from key to found uri
75 """ 75 """
76 keys_re = "|".join(keys) 76 keys_re = "|".join(keys)
77 label_re = r'"(?P<label>[^"]+)"' 77 label_re = r'\"(?P<label>[^\"]+)\"'
78 uri_re = re.compile( 78 uri_re = re.compile(
79 r"(?P<key>{keys_re})[ :]? +(?P<uri>xmpp:\S+)(?:.*use {label_re} label)?".format( 79 r"(?P<key>{keys_re})[ :]? +(?P<uri>xmpp:\S+)(?:.*use {label_re} label)?".format(
80 keys_re=keys_re, label_re=label_re 80 keys_re=keys_re, label_re=label_re
81 ) 81 ),
82 re.IGNORECASE
82 ) 83 )
83 path = os.path.normpath(path) 84 path = os.path.normpath(path)
84 if not os.path.isdir(path) or not os.path.isabs(path): 85 if not os.path.isdir(path) or not os.path.isabs(path):
85 raise ValueError("path must be an absolute path to a directory") 86 raise ValueError("path must be an absolute path to a directory")
86 87
90 name, __ = os.path.splitext(filename) 91 name, __ = os.path.splitext(filename)
91 if name.lower() in SEARCH_FILES: 92 if name.lower() in SEARCH_FILES:
92 file_path = os.path.join(path, filename) 93 file_path = os.path.join(path, filename)
93 with open(file_path) as f: 94 with open(file_path) as f:
94 for m in uri_re.finditer(f.read()): 95 for m in uri_re.finditer(f.read()):
95 key = m.group("key") 96 key = m.group("key").lower()
96 uri = m.group("uri") 97 uri = m.group("uri")
97 label = m.group("label") 98 label = m.group("label")
98 if key in found_uris: 99 if key in found_uris:
99 log.warning( 100 log.warning(
100 _( 101 _(