Refactor match_filter to treat property and dictionary same way
@@ -37,20 +37,23 @@ def dispatch(self, event):
listener["listener"](event)
@staticmethod
- def match_filter(event, name, value):
+ def match_filter(event, key, match):
+ if hasattr(event, key):
# test event property
- if hasattr(event, name) and getattr(event, name) == value:
- return True
+ value = getattr(event, key)
+ elif key in event:
# test event dictionary items
- if name not in event:
- return False
- # accept only arrays
- if not isinstance(value, list):
- return False
- if event[name] not in value:
+ value = event[key]
+ else:
return False
+
+ # check for arrays
+ if isinstance(match, list) and value in match:
return True
+ # check for scalars
+ return value == match
+
def match_event(self, listener, event):
if not isinstance(event, listener["event_type"]):
return False
