mirror of https://github.com/fail2ban/fail2ban
performance: set fetch handler getGroups depending on presence of alternate tags in RE (simplest variant or merged with alt-tags) in regex constructor
parent
9137c7bb23
commit
14e68eed72
|
@ -138,6 +138,8 @@ class Regex:
|
||||||
except sre_constants.error:
|
except sre_constants.error:
|
||||||
raise RegexException("Unable to compile regular expression '%s'" %
|
raise RegexException("Unable to compile regular expression '%s'" %
|
||||||
regex)
|
regex)
|
||||||
|
# set fetch handler depending on presence of alternate tags:
|
||||||
|
self.getGroups = self._getGroupsWithAlt if self._altValues else self._getGroups
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s(%r)" % (self.__class__.__name__, self._regex)
|
return "%s(%r)" % (self.__class__.__name__, self._regex)
|
||||||
|
@ -277,11 +279,12 @@ class Regex:
|
||||||
# Returns all matched groups.
|
# Returns all matched groups.
|
||||||
#
|
#
|
||||||
|
|
||||||
def getGroups(self):
|
def _getGroups(self):
|
||||||
if not self._altValues:
|
|
||||||
return self._matchCache.groupdict()
|
return self._matchCache.groupdict()
|
||||||
# merge alternate values (e. g. 'alt_user_1' -> 'user' or 'alt_host' -> 'host'):
|
|
||||||
|
def _getGroupsWithAlt(self):
|
||||||
fail = self._matchCache.groupdict()
|
fail = self._matchCache.groupdict()
|
||||||
|
# merge alternate values (e. g. 'alt_user_1' -> 'user' or 'alt_host' -> 'host'):
|
||||||
#fail = fail.copy()
|
#fail = fail.copy()
|
||||||
for k,n in self._altValues:
|
for k,n in self._altValues:
|
||||||
v = fail.get(k)
|
v = fail.get(k)
|
||||||
|
@ -289,6 +292,9 @@ class Regex:
|
||||||
fail[n] = v
|
fail[n] = v
|
||||||
return fail
|
return fail
|
||||||
|
|
||||||
|
def getGroups(self): # pragma: no cover - abstract function (replaced in __init__)
|
||||||
|
pass
|
||||||
|
|
||||||
##
|
##
|
||||||
# Returns skipped lines.
|
# Returns skipped lines.
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue