Created
October 17, 2012 16:22
-
-
Save anupamsharma/3906500 to your computer and use it in GitHub Desktop.
Returns list of all the exposed method objects in the current controller for Python Turbogears
This file contains hidden or 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
def _get_exposed_methods(self): | |
""" | |
Returns list of all the exposed method in the current controller. | |
""" | |
# | |
# TG controller class has _is_exposed method with same implementation but | |
# that method is private so we are not using it. One could say why we are | |
# not using the private method inside the class itself. That is because we | |
# are suspecting that it is a private method so can be removed in any future tg release. | |
# | |
def is_exposed(controller, name): | |
if hasattr(controller, name): | |
method = getattr(controller, name) | |
if inspect.ismethod(method) and hasattr(method, 'decoration'): | |
return method.decoration.exposed | |
return False | |
exposed_methods = [] | |
# Going through all the attributes of the method object using dir(method_object). In python methods are objects too. | |
for attr_name in dir(self): | |
if is_exposed(self, attr_name): | |
exposed_methods.append(getattr(self, attr_name)) | |
return exposed_methods |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment