aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorGravatar jesopo2019-06-20 14:21:11 +0100
committerGravatar jesopo2019-06-20 14:21:11 +0100
commitb6e194a450a99bf4533ec7749bb00bd2c167b02e (patch)
treea5237ec01fe2c3e862e84b42ec9beff9fb6770f4 /src/utils
parentImplement utils.irc.hostmask_match() as regex (diff)
signature
Implement hostmask_match_any, for more efficient matching of multiple hostmasks
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/irc/__init__.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/utils/irc/__init__.py b/src/utils/irc/__init__.py
index 88e47489..dd4fdaff 100644
--- a/src/utils/irc/__init__.py
+++ b/src/utils/irc/__init__.py
@@ -330,12 +330,18 @@ class BatchType(object):
t = list(set([type])&self._names)
return t[0] if t else None
-def hostmask_match(hostmask: str, pattern: str) -> bool:
+def hostmask_match_many(hostmasks: typing.List[str], pattern: str) -> str:
part1_out = []
for part1 in pattern.split("?"):
part2_out = []
for part2 in part1.split("*"):
part2_out.append(re.escape(part2))
part1_out.append(".*".join(part2_out))
- pattern_parsed = ".".join(part1_out)
- return not re.match(pattern_parsed, hostmask) == None
+ pattern_re = re.compile(".".join(part1_out))
+ for hostmask in hostmasks:
+ if pattern_re.match(hostmask):
+ return hostmask
+ return None
+
+def hostmask_match(hostmask: str, pattern: str) -> bool:
+ return not hostmask_match_many([hostmask], pattern) == None