In Python application, can't find where a item comes from
<p>I'm trying to understand how web the framework <strong>web2py</strong> works, and there is this item called <code>request.client</code> in <code>access.py</code> that I can't figure out where it comes from. I retrieved the code from <a href="https://github.com/web2py/web2py/blob/0d646fa5e7c731cb5c392adf6a885351e77e4903/applications/admin/models/access.py" rel="nofollow">here</a> and it begins as follows:</p>

<pre><code>import base64
import os
import time
from gluon.admin import apath
from gluon.fileutils import read_file
from gluon.utils import web2py_uuid
from pydal.contrib import portalocker
# ###########################################################
# ## make sure administrator is on localhost or https
# ###########################################################


http_host = request.env.http_host.split(':')[0]
</code></pre>

<p>My question is: when we don't know from where an item comes in a code, what is the method to find it out ? </p>

<p>As explained <a href="http://web2py.com/books/default/chapter/29/04/the-core#API" rel="nofollow">here</a>, web2py model, controller, and view files are executed by the framework in an environment that has already been populated with the core API objects, include <code>request</code>, <code>response</code>, <code>session</code>, <code>cache</code>, <code>DAL</code>, <code>Field</code>, HTML helpers, and form validators (other parts of the API, such Auth, Mail, Services, Scheduler, and many additional tools and contributed libraries, are contained in modules and imported as usual).</p>

<p>Specifically, the <code>request</code> object is created (upon each request) inside the main WSGI application (<a href="https://github.com/web2py/web2py/blob/e6a3081b42ecd58441419930266baf286561c4c7/gluon/main.py#L263" rel="nofollow">gluon.main.wsgibase</a>) at <a href="https://github.com/web2py/web2py/blob/e6a3081b42ecd58441419930266baf286561c4c7/gluon/main.py#L293" rel="nofollow">this line</a>, and it is subsequently passed to <a href="https://github.com/web2py/web2py/blob/e6a3081b42ecd58441419930266baf286561c4c7/gluon/main.py#L148" rel="nofollow">gluon.main.serve_controller</a> at <a href="https://github.com/web2py/web2py/blob/e6a3081b42ecd58441419930266baf286561c4c7/gluon/main.py#L442" rel="nofollow">this line</a>. The <code>serve_controller</code> function adds the <code>request</code> object to the execution environment and then executes model, controller, and view files in that environment.</p>

<p>In addition to model, controller, and view files, your application can include its own modules. Modules in applications are not executed by the framework (they must be imported) -- therefore, those modules must access the web2py core API objects via imports from <code>gluon</code> (the request-dependent objects, such as <code>request</code> and <code>response</code>, are accessed via the <code>current</code> thread-local object, as explained <a href="http://web2py.com/books/default/chapter/29/04/the-core#Sharing-the-global-scope-with-modules-using-the-current-object" rel="nofollow">here</a>).</p>

<p>It may also be helpful to review the <a href="http://web2py.com/books/default/chapter/29/04/the-core#Workflow" rel="nofollow">Workflow</a>, <a href="http://web2py.com/books/default/chapter/29/04/the-core#Libraries" rel="nofollow">Libraries</a>, and <a href="http://web2py.com/books/default/chapter/29/04/the-core#Execution-environment" rel="nofollow">Execution environment</a> sections of the documentation.</p>

python web2py