Permalink
Browse files

Do not iterate with dir when we only need to check for the existance …

…of a member
  • Loading branch information...
1 parent fda3e0e commit 02f01dafab7e1e0db53e11bc632dcc12bef24bca @spanezz spanezz committed Dec 6, 2013
Showing with 5 additions and 5 deletions.
  1. +5 −5 tornadorpc/base.py
View
@@ -110,7 +110,7 @@ def dispatch(self, method_name, params):
Handler class. Currently supports only positional
or keyword arguments, not mixed.
"""
- if method_name in dir(RequestHandler):
+ if hasattr(RequestHandler, method_name):
# Pre-existing, not an implemented attribute
return self.handler.result(self.faults.method_not_found())
method = self.handler
@@ -126,7 +126,7 @@ def dispatch(self, method_name, params):
# Not callable, so not a method
return self.handler.result(self.faults.method_not_found())
if method_name.startswith('_') or \
- ('private' in dir(method) and method.private is True):
+ getattr(method, 'private', False) is True:
# No, no. That's private.
return self.handler.result(self.faults.method_not_found())
args = []
@@ -150,8 +150,8 @@ def dispatch(self, method_name, params):
except Exception:
self.traceback(method_name, params)
return self.handler.result(self.faults.internal_error())
-
- if 'async' in dir(method) and method.async:
+
+ if getattr(method, 'async', False):
# Asynchronous response -- the method should have called
# self.result(RESULT_VALUE)
if response != None:
@@ -236,7 +236,7 @@ def check_method(self, attr_name, obj):
if attr_name.startswith('_'):
raise AttributeError('Private object or method.')
attr = getattr(obj, attr_name)
- if 'private' in dir(attr) and attr.private == True:
+ if getattr(attr, 'private', False):
raise AttributeError('Private object or method.')
return attr

0 comments on commit 02f01da

Please sign in to comment.