A web2py controller is not like a Python module. It is meant to be executed 
in a prepared environment to generate the response to an HTTP request. 
Because the top level of the controller may include code you wouldn't want 
executed unless proceeding with an HTTP request, it must first be 
determined whether the requested function actually exists in the file 
*before* executing it (in order to allow execution to be aborted in case 
the function is not present). Also, when web2py compiles applications, it 
creates a separate bytecode compiled file for each function in each 
controller -- in order to do this, it must know the function names, again, 
without executing the file (as the compilation process takes place outside 
the environment of an HTTP request, and we don't want any side effects).

Anthony

On Wednesday, January 18, 2017 at 3:55:55 PM UTC-5, Brendan Barnwell wrote:
>
> I recently dug into web2py and discovered how it decides which controller 
> functions are exposed as endpoints.  I found that it does this with the 
> find_exposed_functions function in compileapp, which uses a regex to 
> textually search the source code of the controller file for lines of the 
> form "def somefunc():" (at the beginning of the line).  I'm curious about 
> the history and reasoning behind this decision.
>
> To be frank, I was quite shocked to discover this.  It means that the 
> determination of which functions are exposed is not programmatically 
> manipulable -- that is, there is no way to use Python logic to expose 
> things based on attributes, or to expose other callable objects, etc.
>
> So I assume there must be some reason why things were done this way.  What 
> are the advantages of determining function exposure textually, rather than 
> executing the controller file in a namespace and then inspecting its live 
> Python objects to determine which ones to expose?
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to