mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-05 18:49:23 +01:00
irclib: Refactor hostmaskPatternEqual to expose compileHostmaskPattern.
This clarifies the code a bit. And I want to store compiled patterns in ircdb.User in a future commit, so they can outlive the LRU cache.
This commit is contained in:
parent
711db72ad0
commit
a5cd870bd2
@ -169,9 +169,9 @@ def areReceivers(s, strictRfc=True, nicklen=None, chantypes='#&!',
|
||||
return all([nick(x) or chan(x) for x in s.split(',')])
|
||||
|
||||
_patternCache = utils.structures.CacheDict(1000)
|
||||
def _hostmaskPatternEqual(pattern, hostmask):
|
||||
def compileHostmaskPattern(pattern):
|
||||
try:
|
||||
return _patternCache[pattern](hostmask) is not None
|
||||
return _patternCache[pattern]
|
||||
except KeyError:
|
||||
# We make our own regexps, rather than use fnmatch, because fnmatch's
|
||||
# case-insensitivity is not IRC's case-insensitity.
|
||||
@ -194,7 +194,7 @@ def _hostmaskPatternEqual(pattern, hostmask):
|
||||
fd.write('$')
|
||||
f = re.compile(fd.getvalue(), re.I).match
|
||||
_patternCache[pattern] = f
|
||||
return f(hostmask) is not None
|
||||
return f
|
||||
|
||||
_hostmaskPatternEqualCache = utils.structures.CacheDict(1000)
|
||||
def hostmaskPatternEqual(pattern, hostmask):
|
||||
@ -203,9 +203,9 @@ def hostmaskPatternEqual(pattern, hostmask):
|
||||
try:
|
||||
return _hostmaskPatternEqualCache[(pattern, hostmask)]
|
||||
except KeyError:
|
||||
b = _hostmaskPatternEqual(pattern, hostmask)
|
||||
_hostmaskPatternEqualCache[(pattern, hostmask)] = b
|
||||
return b
|
||||
matched = compileHostmaskPattern(pattern)(hostmask) is not None
|
||||
_hostmaskPatternEqualCache[(pattern, hostmask)] = matched
|
||||
return matched
|
||||
|
||||
def banmask(hostmask):
|
||||
"""Returns a properly generic banning hostmask for a hostmask.
|
||||
|
Loading…
Reference in New Issue
Block a user