From d27deb34bea9e774d4b4439e060950db27a55de1 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 26 Mar 2014 13:04:13 +0900 Subject: controller.handler: use normal classes rather than a namedtuple and add some comments. no functional changes. Signed-off-by: YAMAMOTO Takashi Signed-off-by: FUJITA Tomonori --- ryu/controller/handler.py | 27 ++++++++++++++++++++++----- 1 file 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 # # 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 -- cgit v1.2.3