def add_handlers(self, namespace):
"""
Add handler functions from the given `namespace`, for instance a module.
The namespace may be a string, in which case it is expected to be a name of a module.
It may also be a dictionary mapping names to functions.
Only non-underscore-prefixed functions and methods are imported.
:param namespace: Namespace object.
:type namespace: str|module|dict[str, function]
"""
if isinstance(namespace, str):
namespace = import_module(namespace)
if isinstance(namespace, dict):
namespace = namespace.items()
else:
namespace = vars(namespace).items()
for name, value in namespace:
if name.startswith('_'):
continue
if isfunction(value) or ismethod(value):
self.handlers[name] = value
评论列表
文章目录