I drop the need of inspect by using hasattr(obj ,'__call__'):
### TODO: encapsulate the code below ###
if not request.args(0) in locals():
return locals()
elif* hasattr(locals().get(request.args(0)),'__call__')*:
return locals().get(request.args(0),locals)()
else:
return locals().get(request.args(0),locals)
2011/2/20 Bruno Rocha <[email protected]>
> I am going with this solution for a multicomponent app(working together
> with web2py components), I just do not know if I can rely on this inner
> functions, the return of locals() and the use of inspect. without the chance
> to break the compatibility in the future.
>
> ####################################################
> def wrapper():
> div = DIV('wrapper',BR(),HR())
> otherdiv = DIV('This is another div')
>
> def function1():
> div = DIV('function 1',BR(),HR())
> response.view = 'default/wrapper/function1.html'
> return locals()
>
> def function2():
> div = DIV('function 2',BR(),HR())
> response.view = 'default/wrapper/function2.html'
> return locals()
>
>
> from inspect import isfunction as __isfunction
> if not request.args(0) in locals():
> return locals()
> elif __isfunction(locals().get(request.args(0))):
> return locals().get(request.args(0),locals)()
> else:
> return locals().get(request.args(0),locals)
>
>
> #################################################
>
>
>
> --
> Bruno Rocha
> [ About me: http://zerp.ly/rochacbruno ]
>
>