summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIsaku Yamahata <yamahata@valinux.co.jp>2012-12-17 18:07:04 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2012-12-19 20:31:09 +0900
commit76c9a16d23a007bb7c91bb8cb07844e6b717ac10 (patch)
tree1daf4a226ba313d44c09c2737993d9863a98594f
parent7e56bfb527863d2a2b763fa5e8451a4c744c9dd3 (diff)
don't abuse __dict__ attribute
There are built-in functions to handle attribute like hasattr. Use standard functions instead of abusing __dict__. Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/base/app_manager.py13
-rw-r--r--ryu/controller/handler.py2
-rw-r--r--ryu/controller/ofp_event.py6
3 files changed, 9 insertions, 12 deletions
diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py
index 5a35a6e6..4a29c95d 100644
--- a/ryu/base/app_manager.py
+++ b/ryu/base/app_manager.py
@@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import inspect
import itertools
import logging
@@ -72,12 +73,10 @@ class AppManager(object):
def load_app(self, name):
mod = utils.import_module(name)
- for k, v in mod.__dict__.items():
- try:
- if issubclass(v, RyuApp):
- return getattr(mod, k)
- except TypeError:
- pass
+ clses = inspect.getmembers(mod, lambda cls: (inspect.isclass(cls) and
+ issubclass(cls, RyuApp)))
+ if clses:
+ return clses[0][1]
return None
def load_apps(self, app_lists):
@@ -113,7 +112,7 @@ class AppManager(object):
# Yes, maybe for slicing.
LOG.info('instantiating app %s', app_name)
- if 'OFP_VERSIONS' in cls.__dict__:
+ if hasattr(cls, 'OFP_VERSIONS'):
for k in Datapath.supported_ofp_version.keys():
if not k in cls.OFP_VERSIONS:
del Datapath.supported_ofp_version[k]
diff --git a/ryu/controller/handler.py b/ryu/controller/handler.py
index 4566cd5a..ede27df0 100644
--- a/ryu/controller/handler.py
+++ b/ryu/controller/handler.py
@@ -44,7 +44,7 @@ def set_ev_cls(ev_cls, dispatchers):
def _is_ev_handler(meth):
- return 'ev_cls' in meth.__dict__
+ return hasattr(meth, 'ev_cls')
def _listify(may_list):
diff --git a/ryu/controller/ofp_event.py b/ryu/controller/ofp_event.py
index ed9f1b38..e5becac0 100644
--- a/ryu/controller/ofp_event.py
+++ b/ryu/controller/ofp_event.py
@@ -59,10 +59,8 @@ def _create_ofp_msg_ev_class(msg_cls):
def _create_ofp_msg_ev_from_module(modname):
mod = utils.import_module(modname)
# print mod
- for _k, cls in mod.__dict__.items():
- if not inspect.isclass(cls):
- continue
- if 'cls_msg_type' not in cls.__dict__:
+ for _k, cls in inspect.getmembers(mod, inspect.isclass):
+ if not hasattr(cls, 'cls_msg_type'):
continue
_create_ofp_msg_ev_class(cls)