diff options
| author | 2019-06-20 14:10:10 +0100 | |
|---|---|---|
| committer | 2019-06-20 14:10:10 +0100 | |
| commit | 792a42be6edc79801a2bc04ec58170766848e7df (patch) | |
| tree | 99d64b8bbf5b8803fd31475edc6a73a1a4a4f0f3 /src/utils/irc/__init__.py | |
| parent | add channel-access key for starting and ending votes (diff) | |
| signature | ||
Implement utils.irc.hostmask_match() as regex
Diffstat (limited to 'src/utils/irc/__init__.py')
| -rw-r--r-- | src/utils/irc/__init__.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/utils/irc/__init__.py b/src/utils/irc/__init__.py index 7f500b5d..88e47489 100644 --- a/src/utils/irc/__init__.py +++ b/src/utils/irc/__init__.py @@ -1,4 +1,4 @@ -import fnmatch, json, string, re, typing, uuid +import json, string, re, typing, uuid from src import IRCLine, utils from . import protocol @@ -331,4 +331,11 @@ class BatchType(object): return t[0] if t else None def hostmask_match(hostmask: str, pattern: str) -> bool: - return fnmatch.fnmatchcase(hostmask, pattern) + 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 |
