diff options
author | YAMAMOTO Takashi <yamamoto@valinux.co.jp> | 2014-03-26 13:04:13 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-04-10 07:09:56 +0900 |
commit | d27deb34bea9e774d4b4439e060950db27a55de1 (patch) | |
tree | c684a7532955fe0251fb5e4c42d1dac1844c3996 | |
parent | 97bf63e7c7ea21ace3fa3c50a8da78f0adc0e58a (diff) |
controller.handler: use normal classes rather than a namedtuple
and add some comments. no functional changes.
Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/controller/handler.py | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/ryu/controller/handler.py b/ryu/controller/handler.py index 96ab13e5..24e5bb65 100644 --- a/ryu/controller/handler.py +++ b/ryu/controller/handler.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011, 2012 Nippon Telegraph and Telephone Corporation. +# Copyright (C) 2011-2014 Nippon Telegraph and Telephone Corporation. # Copyright (C) 2011, 2012 Isaku Yamahata <yamahata at valinux co jp> # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,6 @@ import inspect import logging import sys -from collections import namedtuple LOG = logging.getLogger('ryu.controller.handler') @@ -27,7 +26,25 @@ CONFIG_DISPATCHER = "config" MAIN_DISPATCHER = "main" DEAD_DISPATCHER = "dead" -caller = namedtuple('caller', 'ev_cls dispatchers ev_source') + +class _Caller(object): + """Describe how to handle an event class. + """ + + def __init__(self, ev_cls, dispatchers, ev_source): + """Initialize _Caller. + + :param ev_cls: The event class to accept. + :param dispatchers: A list of states or a state, in which this + is in effect. + None and [] mean all states. + :param ev_source: The module which generates the event. + ev_cls.__module__ for set_ev_cls. + None for set_ev_handler. + """ + self.ev_cls = ev_cls + self.dispatchers = dispatchers + self.ev_source = ev_source # should be named something like 'observe_event' @@ -36,7 +53,7 @@ def set_ev_cls(ev_cls, dispatchers=None): if 'callers' not in dir(handler): handler.callers = {} for e in _listify(ev_cls): - c = caller(e, _listify(dispatchers), e.__module__) + c = _Caller(e, _listify(dispatchers), e.__module__) handler.callers[e] = c return handler return _set_ev_cls_dec @@ -47,7 +64,7 @@ def set_ev_handler(ev_cls, dispatchers=None): if 'callers' not in dir(handler): handler.callers = {} for e in _listify(ev_cls): - c = caller(e, _listify(dispatchers), None) + c = _Caller(e, _listify(dispatchers), None) handler.callers[e] = c return handler return _set_ev_cls_dec |