Skip to content
This repository
Browse code

EventMagicMeta will now also discover events defined in base classes …

…of cls.
  • Loading branch information...
commit 97b9438e1f4e0c174a2a9edce4732644572f93a3 1 parent 5f3423e
Lars van de Kerkhof specialunderwear authored

Showing 1 changed file with 5 additions and 11 deletions. Show diff stats Hide diff stats

  1. +5 11 tornadio2/conn.py
16 tornadio2/conn.py
@@ -22,6 +22,7 @@
22 22 """
23 23 import time
24 24 import logging
  25 +from inspect import ismethod, getmembers
25 26
26 27 from tornadio2 import proto
27 28
@@ -57,17 +58,10 @@ def handler(f):
57 58 class EventMagicMeta(type):
58 59 """Event handler metaclass"""
59 60 def __init__(cls, name, bases, attrs):
60   - # Manage events
61   - events = {}
62   -
63   - for a in attrs:
64   - attr = getattr(cls, a)
65   - name = getattr(attr, '_event_name', None)
66   -
67   - if name:
68   - events[name] = attr
69   -
70   - setattr(cls, '_events', events)
  61 + # find events, also in bases
  62 + is_event = lambda x: ismethod(x) and hasattr(x, '_event_name')
  63 + events = getmembers(cls, is_event)
  64 + setattr(cls, '_events', dict(events))
71 65
72 66 # Call base
73 67 super(EventMagicMeta, cls).__init__(name, bases, attrs)

0 comments on commit 97b9438

Please sign in to comment.
Something went wrong with that request. Please try again.