Dispatch an event to the proper handler method. In the most common usage, this method is not overloaded by subclasses, as it performs the routing of events to methods. However, this method can be overridden if special dispatching rules are needed, or if having a sing
(self, event, *args)
| 14 | omitted, the default namespace is used. |
| 15 | """ |
| 16 | def trigger_event(self, event, *args): |
| 17 | """Dispatch an event to the proper handler method. |
| 18 | |
| 19 | In the most common usage, this method is not overloaded by subclasses, |
| 20 | as it performs the routing of events to methods. However, this |
| 21 | method can be overridden if special dispatching rules are needed, or if |
| 22 | having a single method that catches all events is desired. |
| 23 | """ |
| 24 | handler_name = 'on_' + (event or '') |
| 25 | if hasattr(self, handler_name): |
| 26 | try: |
| 27 | return getattr(self, handler_name)(*args) |
| 28 | except TypeError: |
| 29 | # legacy disconnect events do not have a reason argument |
| 30 | if event == 'disconnect': |
| 31 | return getattr(self, handler_name)(*args[:-1]) |
| 32 | else: # pragma: no cover |
| 33 | raise |
| 34 | |
| 35 | def emit(self, event, data=None, to=None, room=None, skip_sid=None, |
| 36 | namespace=None, callback=None, ignore_queue=False): |
no outgoing calls