diff --git a/fail2ban/server/failregex.py b/fail2ban/server/failregex.py index f7dafbef..0ae9acc5 100644 --- a/fail2ban/server/failregex.py +++ b/fail2ban/server/failregex.py @@ -138,6 +138,8 @@ class Regex: except sre_constants.error: raise RegexException("Unable to compile regular expression '%s'" % regex) + # set fetch handler depending on presence of alternate tags: + self.getGroups = self._getGroupsWithAlt if self._altValues else self._getGroups def __str__(self): return "%s(%r)" % (self.__class__.__name__, self._regex) @@ -277,11 +279,12 @@ class Regex: # Returns all matched groups. # - def getGroups(self): - if not self._altValues: - return self._matchCache.groupdict() - # merge alternate values (e. g. 'alt_user_1' -> 'user' or 'alt_host' -> 'host'): + def _getGroups(self): + return self._matchCache.groupdict() + + def _getGroupsWithAlt(self): fail = self._matchCache.groupdict() + # merge alternate values (e. g. 'alt_user_1' -> 'user' or 'alt_host' -> 'host'): #fail = fail.copy() for k,n in self._altValues: v = fail.get(k) @@ -289,6 +292,9 @@ class Regex: fail[n] = v return fail + def getGroups(self): # pragma: no cover - abstract function (replaced in __init__) + pass + ## # Returns skipped lines. #