forked from fgmacedo/python-statemachine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents.py
More file actions
31 lines (22 loc) · 731 Bytes
/
Copy pathevents.py
File metadata and controls
31 lines (22 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from .utils import ensure_iterable
class Events:
"""A collection of event names."""
def __init__(self):
self.items = []
def __repr__(self):
sep = " " if len(self.items) > 1 else ""
return sep.join(item for item in self.items)
def __iter__(self):
return iter(self.items)
def add(self, events):
if events is None:
return self
unprepared = ensure_iterable(events)
for events in unprepared:
for event in events.split(" "):
if event in self.items:
continue
self.items.append(event)
return self
def match(self, event):
return any(t == event for t in self)