Skip to content
Browse files

Merge pull request #37 from specialunderwear/master

EventMagicMeta will now also discover events defined in base classes of cls.
  • Loading branch information...
2 parents 5f3423e + ec0b4d5 commit c5584e9fb74f76f8977acb61233579011bebaf2a @mrjoes committed
Showing with 5 additions and 11 deletions.
  1. +5 −11 tornadio2/conn.py
View
16 tornadio2/conn.py
@@ -22,6 +22,7 @@
"""
import time
import logging
+from inspect import ismethod, getmembers
from tornadio2 import proto
@@ -57,17 +58,10 @@ def handler(f):
class EventMagicMeta(type):
"""Event handler metaclass"""
def __init__(cls, name, bases, attrs):
- # Manage events
- events = {}
-
- for a in attrs:
- attr = getattr(cls, a)
- name = getattr(attr, '_event_name', None)
-
- if name:
- events[name] = attr
-
- setattr(cls, '_events', events)
+ # find events, also in bases
+ is_event = lambda x: ismethod(x) and hasattr(x, '_event_name')
+ events = [(e._event_name, e) for _, e in getmembers(cls, is_event)]
+ setattr(cls, '_events', dict(events))
# Call base
super(EventMagicMeta, cls).__init__(name, bases, attrs)

0 comments on commit c5584e9

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