Created
July 20, 2016 10:25
-
-
Save Tattoo/62f246988df68650ccd19f4f298c9ecb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from inspect import getargspec | |
from types import FunctionType | |
from your_module import (a_method | |
another_method, | |
and_so_on) | |
class ExampleDynamicLibrary(object): | |
def __init__(self): | |
self.keywords = {} | |
for name, method in globals().items(): | |
if (isinstance(method, FunctionType) and | |
method.__module__ == 'your_module'): | |
self.keywords[name] = method | |
def get_keyword_names(self): | |
return self.keywords.keys() | |
def run_keyword(self, name, arguments, kwargs): | |
return self.keywords[name](arguments, kwargs) | |
def get_keyword_arguments(self, name): | |
argspec = getargspec(self.keywords[name]) | |
args = argspec.args | |
if argspec.varargs: | |
args = args.append('*' + argspec.varargs) | |
if argspec.keywords: | |
args = args.append('**' + argspec.keywords) | |
return args | |
def get_keyword_documentation(self, name): | |
if '__intro__': | |
return self.__doc__ | |
return self.keywords[name].__doc__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment