Could you also use
 
elif callable(locals().get(request.args(0)))
 
Or maybe:
 
try:
    return locals().get(request.args(0), locals)()
except TypeError:
    return locals().get(request.args(0), locals)
 
Anthony

On Sunday, February 20, 2011 10:02:24 PM UTC-5, rochacbruno wrote:

> 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 ]
>>
>>
>

Reply via email to