# Symbol name after escape_chars that are considered a devnode basename
re_symbol_name = re.compile(r"(\w|\\[\.\-\:])+$")
# List of popular group names to be skipped to minimize regex group size # Use AbiDebug.SUBGROUP_SIZE to detect those
skip_names = set(["devices", "hwmon"])
def regex_append(self, what, new): """
Get a search group for a subset of regular expressions.
As ABI may have thousands of symbols, using a for to search all
regular expressions is at least O(n^2). When there are wildcards,
the complexity increases substantially, eventually becoming exponential.
To avoid spending too much time on them, use a logic to split
them into groups. The smaller the group, the better, as it would
mean that searches will be confined to a small number of regular
expressions.
The conversion to a regex subset is tricky, as we need something
that can be easily obtained from the sysfs symbol andfrom the
regular expression. So, we need to discard nodes that have
wildcards.
If it can't obtain a subgroup, place the regular expression inside
a special group (self.leave_others). """
search_group = None
for search_group in reversed(new.split("/")): ifnot search_group or search_group in self.skip_names: continue if self.re_symbol_name.match(search_group): break
if self.debug & AbiDebug.SUBGROUP_MAP:
self.log.debug("%s: mapped as %s", what, search_group)
try: if search_group notin self.regex_group:
self.regex_group[search_group] = []
self.regex_group[search_group].append(re.compile(new)) if self.search_string: if what.find(self.search_string) >= 0:
print(f"What: {what}") except re.PatternError:
self.log.warning("Ignoring '%s' as it produced an invalid regex:\n" " '%s'", what, new)
def get_regexes(self, what): """
Given an ABI devnode, return a list of all regular expressions that
may match it, based on the sub-groups created by regex_append() """
if"search_string"in kwargs:
self.search_string = kwargs.get("search_string") del kwargs["search_string"]
if self.search_string:
try:
self.re_string = re.compile(self.search_string) except re.PatternError as e:
msg = f"{self.search_string} is not a valid regular expression" raise ValueError(msg) from e
super().__init__(*args, **kwargs)
def parse_abi(self, *args, **kwargs):
super().parse_abi(*args, **kwargs)
self.regex_group = {}
print("Converting ABI What fields into regexes...", file=sys.stderr)
for t in sorted(self.data.items(), key=lambda x: x[0]):
v = t[1] if v.get("type") == "File": continue
v["regex"] = []
for what in v.get("what", []): ifnot what.startswith("/sys"): continue
new = what for r, s in self.re_whats: try:
new = r.sub(s, new) except re.PatternError as e: # Help debugging troubles with new regexes raise re.PatternError(f"{e}\nwhile re.sub('{r.pattern}', {s}, str)") from e
v["regex"].append(new)
if self.debug & AbiDebug.REGEX:
self.log.debug("%-90s <== %s", new, what)
# Store regex into a subgroup to speedup searches
self.regex_append(what, new)
if self.debug & AbiDebug.SUBGROUP_DICT:
self.log.debug("%s", pformat(self.regex_group))
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.