From f8b83f69f2127a710c927beae36634c62d219e8c Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Fri, 9 Apr 2004 15:30:09 +0000 Subject: [PATCH] Slight optimization, not that it matters, but it makes the code easier to read, too. --- src/ircutils.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ircutils.py b/src/ircutils.py index 2a595db12..28c8c9323 100644 --- a/src/ircutils.py +++ b/src/ircutils.py @@ -124,26 +124,27 @@ def isCtcp(msg): msg.args[1].startswith('\x01') and \ msg.args[1].endswith('\x01') -_match = fnmatch.fnmatchcase _patternCache = {} def _hostmaskPatternEqual(pattern, hostmask): """Returns True if hostmask matches the hostmask pattern pattern.""" try: return _patternCache[pattern](hostmask) is not None except KeyError: + # We make our own regexps, rather than use fnmatch, because fnmatch's + # case-insensitivity is not IRC's case-insensitity. fd = sio() for c in pattern: if c == '*': fd.write('.*') elif c == '?': fd.write('.') - elif c == '[' or c == '{': + elif c in '[{': fd.write('[[{]') - elif c == '}' or c == ']': + elif c in '}]': fd.write(r'[}\]]') - elif c == '|' or c == '\\': + elif c in '|\\': fd.write(r'[|\\]') - elif c == '^' or c == '~': + elif c in '^~': fd.write('[~^]') else: fd.write(re.escape(c))