3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-27 21:19:31 +01:00

classes: split match_host() into match_host() and match_text()

This commit is contained in:
James Lu 2018-06-08 18:21:37 -07:00
parent 6085b21e48
commit f4de604b7d

View File

@ -1363,6 +1363,9 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
hosts.add(self.get_hostmask(target, realhost=True))
else: # We were given a host, use that.
if '@' not in text:
log.warning('(%s) Using match_host() on non-hostlike globs is deprecated as of 2.0-alpha4 - '
'use match_text() instead', self.name)
hosts = [target]
# Iterate over the hosts to match using ircmatch.
@ -1377,6 +1380,19 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
result = not result
return result
def match_text(self, glob, text):
"""
Returns whether the given glob matches the given text under the network's
current case mapping.
"""
# Get the corresponding casemapping value used by ircmatch.
if self.casemapping == 'rfc1459':
casemapping = 0
else:
casemapping = 1
return ircmatch.match(casemapping, glob, text)
def match_all(self, banmask, channel=None):
"""
Returns all users matching the target hostmask/exttarget. Users can also be filtered by channel.