mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-25 04:02:46 +01:00
Slight optimization, not that it matters, but it makes the code easier to read, too.
This commit is contained in:
parent
4354a79f9f
commit
f8b83f69f2
@ -124,26 +124,27 @@ def isCtcp(msg):
|
|||||||
msg.args[1].startswith('\x01') and \
|
msg.args[1].startswith('\x01') and \
|
||||||
msg.args[1].endswith('\x01')
|
msg.args[1].endswith('\x01')
|
||||||
|
|
||||||
_match = fnmatch.fnmatchcase
|
|
||||||
_patternCache = {}
|
_patternCache = {}
|
||||||
def _hostmaskPatternEqual(pattern, hostmask):
|
def _hostmaskPatternEqual(pattern, hostmask):
|
||||||
"""Returns True if hostmask matches the hostmask pattern pattern."""
|
"""Returns True if hostmask matches the hostmask pattern pattern."""
|
||||||
try:
|
try:
|
||||||
return _patternCache[pattern](hostmask) is not None
|
return _patternCache[pattern](hostmask) is not None
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
# We make our own regexps, rather than use fnmatch, because fnmatch's
|
||||||
|
# case-insensitivity is not IRC's case-insensitity.
|
||||||
fd = sio()
|
fd = sio()
|
||||||
for c in pattern:
|
for c in pattern:
|
||||||
if c == '*':
|
if c == '*':
|
||||||
fd.write('.*')
|
fd.write('.*')
|
||||||
elif c == '?':
|
elif c == '?':
|
||||||
fd.write('.')
|
fd.write('.')
|
||||||
elif c == '[' or c == '{':
|
elif c in '[{':
|
||||||
fd.write('[[{]')
|
fd.write('[[{]')
|
||||||
elif c == '}' or c == ']':
|
elif c in '}]':
|
||||||
fd.write(r'[}\]]')
|
fd.write(r'[}\]]')
|
||||||
elif c == '|' or c == '\\':
|
elif c in '|\\':
|
||||||
fd.write(r'[|\\]')
|
fd.write(r'[|\\]')
|
||||||
elif c == '^' or c == '~':
|
elif c in '^~':
|
||||||
fd.write('[~^]')
|
fd.write('[~^]')
|
||||||
else:
|
else:
|
||||||
fd.write(re.escape(c))
|
fd.write(re.escape(c))
|
||||||
|
Loading…
Reference in New Issue
Block a user