Implement utils.irc.hostmask_match for glob-like hostmask matching

This commit is contained in:
jesopo 2019-05-19 16:24:38 +01:00
parent 4806e9c81e
commit c607a0e67c
2 changed files with 8 additions and 1 deletions

View file

@ -203,6 +203,10 @@ class Server(IRCObject.Object):
def irc_equals(self, s1: str, s2: str) -> bool:
return utils.irc.equals(self.case_mapping, s1, s2)
def hostmask_match(self, hostmask: str, pattern: str) -> bool:
return utils.irc.hostmask_match(self.irc_lower(hostmask),
self.irc_lower(pattern))
def parse_data(self, line: str):
if not line:
return

View file

@ -1,4 +1,4 @@
import json, string, re, typing
import fnmatch, json, string, re, typing
from src import IRCLine, utils
from . import protocol
@ -303,3 +303,6 @@ class MessageTag(object):
def get_value(self, tags: typing.Dict[str, str]) -> typing.Optional[str]:
key = list(set(tags.keys())&self._names)
return tags[key[0]] if key else None
def hostmask_match(hostmask: str, pattern: str) -> bool:
return fnmatch.fnmatch(hostmask, pattern)