Skip to content
Snippets Groups Projects
Commit fbcce35b authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Improve event filter

Allow comparing attributes with different names

Example:
```
@event_filter(['account', 'jid=own_jid'])
def _on_event(self):
    pass
```

_on_event() is only executed if the event attribute `jid` matches the
`own_jid` attribute on self
parent 36ecf673
No related branches found
No related tags found
No related merge requests found
......@@ -1453,12 +1453,17 @@ def event_filter_decorator(func):
@wraps(func)
def func_wrapper(self, event, *args, **kwargs):
for attr in filter_:
if '=' in attr:
attr1, attr2 = attr.split('=')
else:
attr1, attr2 = attr, attr
try:
if getattr(event, attr) != getattr(self, attr):
return
if getattr(event, attr1) != getattr(self, attr2):
return None
except AttributeError:
if getattr(event, attr) != getattr(self, '_%s' % attr):
return
if getattr(event, attr1) != getattr(self, '_%s' % attr2):
return None
return func(self, event, *args, **kwargs)
return func_wrapper
return event_filter_decorator
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment