Skip to content

Commit

Permalink
add function to return filter pattern for a component
Browse files Browse the repository at this point in the history
  • Loading branch information
truib committed Sep 10, 2024
1 parent d17c46a commit cef70a7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tools/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
COMPONENT_UNKNOWN = "unknown component={component} in {component}:{pattern}"
FILTER_EMPTY_PATTERN = "pattern in filter string '{filter_string}' is empty"
FILTER_FORMAT_ERROR = "filter string '{filter_string}' does not conform to format 'component:pattern'"
UNKNOWN_COMPONENT_CONST = "unknown component constant {component}"

Filter = namedtuple('Filter', ('component', 'pattern'))

Expand Down Expand Up @@ -175,6 +176,26 @@ def add_filter_from_string(self, filter_string):
raise EESSIBotActionFilterError(msg)
self.add_filter(_filter_split[0], _filter_split[1])

def get_filter_by_component(self, component):
"""
Returns filter pattern for component.
Args:
component (string): one of FILTER_COMPONENTS
Returns:
(list): list of pattern for filters whose component matches argument
"""
if component not in FILTER_COMPONENTS:
msg = UNKNOWN_COMPONENT_CONST.format(component=component)
raise EESSIBotActionFilterError(msg)

pattern = []
for _filter in self.action_filters:
if component == _filter.component:
pattern.append(_filter.pattern)
return pattern

def remove_filter(self, component, pattern):
"""
Removes all elements matching the filter given by (component, pattern)
Expand Down

0 comments on commit cef70a7

Please sign in to comment.