From 792a42be6edc79801a2bc04ec58170766848e7df Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 20 Jun 2019 14:10:10 +0100 Subject: Implement utils.irc.hostmask_match() as regex --- src/utils/irc/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/utils/irc/__init__.py') 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 -- cgit v1.3.1-10-gc9f91