<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>web2py.gluon.main</title>
<link rel="stylesheet" href="epydoc.css" type="text/css" />
<script type="text/javascript" src="epydoc.js"></script>
</head>
<body bgcolor="white" text="black" link="blue" vlink="#204080"
alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
bgcolor="#a0c0ff" cellspacing="0">
<tr valign="middle">
<!-- Home link -->
<th> <a
href="web2py.gluon-module.html">Home</a> </th>
<!-- Tree link -->
<th> <a
href="module-tree.html">Trees</a> </th>
<!-- Index link -->
<th> <a
href="identifier-index.html">Indices</a> </th>
<!-- Help link -->
<th> <a
href="help.html">Help</a> </th>
<!-- Project homepage -->
<th class="navbar" align="right" width="100%">
<table border="0" cellpadding="0" cellspacing="0">
<tr><th class="navbar" align="center"
><a class="navbar" target="_top" href="http://www.web2py.com">web2py Web Framework</a></th>
</tr></table></th>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
<tr valign="top">
<td width="100%">
<span class="breadcrumbs">
Package web2py ::
<a href="web2py.gluon-module.html">Package gluon</a> ::
Module main
</span>
</td>
<td>
<table cellpadding="0" cellspacing="0">
<!-- hide/show private -->
<tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
onclick="toggle_private();">hide private</a>]</span></td></tr>
<tr><td align="right"><span class="options"
>[<a href="frames.html" target="_top">frames</a
>] | <a href="web2py.gluon.main-module.html"
target="_top">no frames</a>]</span></td></tr>
</table>
</td>
</tr>
</table>
<!-- ==================== MODULE DESCRIPTION ==================== -->
<h1 class="epydoc">Module main</h1><span class="codelink"><a href="web2py.gluon.main-pysrc.html">source code</a></span><br /><br />
<pre class="literalblock">
This file is part of the web2py Web Framework
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
Contains:
- wsgibase: the gluon wsgi application
</pre><br /><br />
<!-- ==================== CLASSES ==================== -->
<a name="section-Classes"></a>
<table class="summary" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
<td colspan="2" class="table-header">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td align="left"><span class="table-header">Classes</span></td>
<td align="right" valign="top"
><span class="options">[<a href="#section-Classes"
class="privatelink" onclick="toggle_private();"
>hide private</a>]</span></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<a href="web2py.gluon.main.HttpServer-class.html" class="summary-name">HttpServer</a><br />
the web2py web server (Rocket)
</td>
</tr>
</table>
<!-- ==================== FUNCTIONS ==================== -->
<a name="section-Functions"></a>
<table class="summary" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
<td colspan="2" class="table-header">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td align="left"><span class="table-header">Functions</span></td>
<td align="right" valign="top"
><span class="options">[<a href="#section-Functions"
class="privatelink" onclick="toggle_private();"
>hide private</a>]</span></td>
</tr>
</table>
</td>
</tr>
<tr class="private">
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a href="web2py.gluon.main-module.html#get_client" class="summary-sig-name">get_client</a>(<span class="summary-sig-arg">env</span>)</span><br />
guess the client address from the environment variables</td>
<td align="right" valign="top">
<span class="codelink"><a href="web2py.gluon.main-pysrc.html#get_client">source code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr class="private">
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a name="copystream_progress"></a><span class="summary-sig-name">copystream_progress</span>(<span class="summary-sig-arg">request</span>,
<span class="summary-sig-arg">chunk_size</span>=<span class="summary-sig-default">100000</span>)</span><br />
copies request.env.wsgi_input into request.body and stores
progress upload status in cache.ram X-Progress-ID:length and
X-Progress-ID:uploaded</td>
<td align="right" valign="top">
<span class="codelink"><a href="web2py.gluon.main-pysrc.html#copystream_progress">source code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr class="private">
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a href="web2py.gluon.main-module.html#serve_controller" class="summary-sig-name">serve_controller</a>(<span class="summary-sig-arg">request</span>,
<span class="summary-sig-arg">response</span>,
<span class="summary-sig-arg">session</span>)</span><br />
this function is used to generate a dynamic page.</td>
<td align="right" valign="top">
<span class="codelink"><a href="web2py.gluon.main-pysrc.html#serve_controller">source code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr class="private">
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a href="web2py.gluon.main-module.html#start_response_aux" class="summary-sig-name">start_response_aux</a>(<span class="summary-sig-arg">status</span>,
<span class="summary-sig-arg">headers</span>,
<span class="summary-sig-arg">exc_info</span>,
<span class="summary-sig-arg">response</span>=<span class="summary-sig-default">1</span>)</span><br />
in controller you can use::...</td>
<td align="right" valign="top">
<span class="codelink"><a href="web2py.gluon.main-pysrc.html#start_response_aux">source code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr class="private">
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a href="web2py.gluon.main-module.html#middleware_aux" class="summary-sig-name">middleware_aux</a>(<span class="summary-sig-arg">request</span>,
<span class="summary-sig-arg">response</span>,
<span class="summary-sig-arg">*middleware_apps</span>)</span><br />
In you controller use:</td>
<td align="right" valign="top">
<span class="codelink"><a href="web2py.gluon.main-pysrc.html#middleware_aux">source code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr class="private">
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a name="environ_aux"></a><span class="summary-sig-name">environ_aux</span>(<span class="summary-sig-arg">environ</span>,
<span class="summary-sig-arg">request</span>)</span></td>
<td align="right" valign="top">
<span class="codelink"><a href="web2py.gluon.main-pysrc.html#environ_aux">source code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr class="private">
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a name="parse_get_post_vars"></a><span class="summary-sig-name">parse_get_post_vars</span>(<span class="summary-sig-arg">request</span>,
<span class="summary-sig-arg">environ</span>)</span></td>
<td align="right" valign="top">
<span class="codelink"><a href="web2py.gluon.main-pysrc.html#parse_get_post_vars">source code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a href="web2py.gluon.main-module.html#wsgibase" class="summary-sig-name">wsgibase</a>(<span class="summary-sig-arg">environ</span>,
<span class="summary-sig-arg">responder</span>)</span><br />
this is the gluon wsgi application.</td>
<td align="right" valign="top">
<span class="codelink"><a href="web2py.gluon.main-pysrc.html#wsgibase">source code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a name="save_password"></a><span class="summary-sig-name">save_password</span>(<span class="summary-sig-arg">password</span>,
<span class="summary-sig-arg">port</span>)</span><br />
used by main() to save the password in the parameters_port.py
file.</td>
<td align="right" valign="top">
<span class="codelink"><a href="web2py.gluon.main-pysrc.html#save_password">source code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a href="web2py.gluon.main-module.html#appfactory" class="summary-sig-name">appfactory</a>(<span class="summary-sig-arg">wsgiapp</span>=<span class="summary-sig-default"><function wsgibase at 0x13d0410></span>,
<span class="summary-sig-arg">logfilename</span>=<span class="summary-sig-default"><code class="variable-quote">'</code><code class="variable-string">httpserver.log</code><code class="variable-quote">'</code></span>,
<span class="summary-sig-arg">profilerfilename</span>=<span class="summary-sig-default"><code class="variable-quote">'</code><code class="variable-string">profiler.log</code><code class="variable-quote">'</code></span>)</span><br />
generates a wsgi application that does logging and profiling and calls
wsgibase
..</td>
<td align="right" valign="top">
<span class="codelink"><a href="web2py.gluon.main-pysrc.html#appfactory">source code</a></span>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- ==================== VARIABLES ==================== -->
<a name="section-Variables"></a>
<table class="summary" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
<td colspan="2" class="table-header">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td align="left"><span class="table-header">Variables</span></td>
<td align="right" valign="top"
><span class="options">[<a href="#section-Variables"
class="privatelink" onclick="toggle_private();"
>hide private</a>]</span></td>
</tr>
</table>
</td>
</tr>
<tr class="private">
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<a name="web2py_path"></a><span class="summary-name">web2py_path</span> = <code title="1">1</code><br />
PyMySQL: A pure-Python drop-in replacement for MySQLdb.
</td>
</tr>
<tr class="private">
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<a name="logpath"></a><span class="summary-name">logpath</span> = <code title="'/home/mdipierro/web2py/logging.conf'"><code class="variable-quote">'</code><code class="variable-string">/home/mdipierro/web2py/logging.conf</code><code class="variable-quote">'</code></code>
</td>
</tr>
<tr class="private">
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<a name="logger"></a><span class="summary-name">logger</span> = <code title="logging.getLogger("web2py")">logging.getLogger("web2py")</code>
</td>
</tr>
<tr class="private">
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<a name="requests"></a><span class="summary-name">requests</span> = <code title="0">0</code>
</td>
</tr>
<tr class="private">
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<a name="regex_client"></a><span class="summary-name">regex_client</span> = <code title="re.compile(r'[\w-:]+(\.[\w-]+)*\.?')">re.compile(r'<code class="re-group">[</code>\w-:<code class="re-group">]</code><code class="re-op">+</code><code class="re-group">(</code>\.<code class="re-group">[</code>\w-<code class="re-group">]</code><code class="re-op">+</code><code class="re-group">)</code><code class="re-op">*</code>\.<code class="re-op">?</code>')</code>
</td>
</tr>
<tr class="private">
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<a href="web2py.gluon.main-module.html#version_info" class="summary-name">version_info</a> = <code title="open(abspath('VERSION', gluon= True), 'r')"><closed file '/home/mdipierro/web2py/VERSION', <code class="variable-ellipsis">...</code></code>
</td>
</tr>
<tr class="private">
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type"> </span>
</td><td class="summary">
<a name="web2py_version"></a><span class="summary-name">web2py_version</span> = <code title="'''Version 1.98.2 (2011-08-03 18:44:38)
'''"><code class="variable-quote">'</code><code class="variable-string">Version 1.98.2 (2011-08-03 18:44:38)\n</code><code class="variable-quote">'</code></code>
</td>
</tr>
</table>
<!-- ==================== FUNCTION DETAILS ==================== -->
<a name="section-FunctionDetails"></a>
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
<td colspan="2" class="table-header">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td align="left"><span class="table-header">Function Details</span></td>
<td align="right" valign="top"
><span class="options">[<a href="#section-FunctionDetails"
class="privatelink" onclick="toggle_private();"
>hide private</a>]</span></td>
</tr>
</table>
</td>
</tr>
</table>
<a name="get_client"></a>
<div class="private">
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr><td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top"><td>
<h3 class="epydoc"><span class="sig"><span class="sig-name">get_client</span>(<span class="sig-arg">env</span>)</span>
</h3>
</td><td align="right" valign="top"
><span class="codelink"><a href="web2py.gluon.main-pysrc.html#get_client">source code</a></span>
</td>
</table>
<p>guess the client address from the environment variables</p>
first tries 'http_x_forwarded_for', secondly 'remote_addr' if all
fails assume '127.0.0.1' (running locally)
<dl class="fields">
</dl>
</td></tr></table>
</div>
<a name="serve_controller"></a>
<div class="private">
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr><td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top"><td>
<h3 class="epydoc"><span class="sig"><span class="sig-name">serve_controller</span>(<span class="sig-arg">request</span>,
<span class="sig-arg">response</span>,
<span class="sig-arg">session</span>)</span>
</h3>
</td><td align="right" valign="top"
><span class="codelink"><a href="web2py.gluon.main-pysrc.html#serve_controller">source code</a></span>
</td>
</table>
this function is used to generate a dynamic page. It first runs all
models, then runs the function in the controller, and then tries to
render the output using a view/template. this function must run from the
[application] folder. A typical example would be the call to the url
/[application]/[controller]/[function] that would result in a call to
[function]() in applications/[application]/[controller].py rendered by
applications/[application]/views/[controller]/[function].html
<dl class="fields">
</dl>
</td></tr></table>
</div>
<a name="start_response_aux"></a>
<div class="private">
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr><td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top"><td>
<h3 class="epydoc"><span class="sig"><span class="sig-name">start_response_aux</span>(<span class="sig-arg">status</span>,
<span class="sig-arg">headers</span>,
<span class="sig-arg">exc_info</span>,
<span class="sig-arg">response</span>=<span class="sig-default">1</span>)</span>
</h3>
</td><td align="right" valign="top"
><span class="codelink"><a href="web2py.gluon.main-pysrc.html#start_response_aux">source code</a></span>
</td>
</table>
<pre class="literalblock">
in controller you can use::
- request.wsgi.environ
- request.wsgi.start_response
to call third party WSGI applications
</pre>
<dl class="fields">
</dl>
</td></tr></table>
</div>
<a name="middleware_aux"></a>
<div class="private">
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr><td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top"><td>
<h3 class="epydoc"><span class="sig"><span class="sig-name">middleware_aux</span>(<span class="sig-arg">request</span>,
<span class="sig-arg">response</span>,
<span class="sig-arg">*middleware_apps</span>)</span>
</h3>
</td><td align="right" valign="top"
><span class="codelink"><a href="web2py.gluon.main-pysrc.html#middleware_aux">source code</a></span>
</td>
</table>
In you controller use:
<pre class="literalblock">
@request.wsgi.middleware(middleware1, middleware2, ...)
</pre>
to decorate actions with WSGI middleware. actions must return strings.
uses a simulated environment so it may have weird behavior in some
cases
<dl class="fields">
</dl>
</td></tr></table>
</div>
<a name="wsgibase"></a>
<div>
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr><td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top"><td>
<h3 class="epydoc"><span class="sig"><span class="sig-name">wsgibase</span>(<span class="sig-arg">environ</span>,
<span class="sig-arg">responder</span>)</span>
</h3>
</td><td align="right" valign="top"
><span class="codelink"><a href="web2py.gluon.main-pysrc.html#wsgibase">source code</a></span>
</td>
</table>
<pre class="literalblock">
this is the gluon wsgi application. the first function called when a page
is requested (static or dynamic). it can be called by paste.httpserver
or by apache mod_wsgi.
- fills request with info
- the environment variables, replacing '.' with '_'
- adds web2py path and version info
- compensates for fcgi missing path_info and query_string
- validates the path in url
The url path must be either:
1. for static pages:
- /<application>/static/<file>
2. for dynamic pages:
- /<application>[/<controller>[/<function>[/<sub>]]][.<extension>]
- (sub may go several levels deep, currently 3 levels are supported:
sub1/sub2/sub3)
The naming conventions are:
- application, controller, function and extension may only contain
[a-zA-Z0-9_]
- file and sub may also contain '-', '=', '.' and '/'
</pre>
<dl class="fields">
</dl>
</td></tr></table>
</div>
<a name="appfactory"></a>
<div>
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr><td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top"><td>
<h3 class="epydoc"><span class="sig"><span class="sig-name">appfactory</span>(<span class="sig-arg">wsgiapp</span>=<span class="sig-default"><function wsgibase at 0x13d0410></span>,
<span class="sig-arg">logfilename</span>=<span class="sig-default"><code class="variable-quote">'</code><code class="variable-string">httpserver.log</code><code class="variable-quote">'</code></span>,
<span class="sig-arg">profilerfilename</span>=<span class="sig-default"><code class="variable-quote">'</code><code class="variable-string">profiler.log</code><code class="variable-quote">'</code></span>)</span>
</h3>
</td><td align="right" valign="top"
><span class="codelink"><a href="web2py.gluon.main-pysrc.html#appfactory">source code</a></span>
</td>
</table>
<pre class="literalblock">
generates a wsgi application that does logging and profiling and calls
wsgibase
.. function:: gluon.main.appfactory(
[wsgiapp=wsgibase
[, logfilename='httpserver.log'
[, profilerfilename='profiler.log']]])
</pre>
<dl class="fields">
</dl>
</td></tr></table>
</div>
<br />
<!-- ==================== VARIABLES DETAILS ==================== -->
<a name="section-VariablesDetails"></a>
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
<td colspan="2" class="table-header">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td align="left"><span class="table-header">Variables Details</span></td>
<td align="right" valign="top"
><span class="options">[<a href="#section-VariablesDetails"
class="privatelink" onclick="toggle_private();"
>hide private</a>]</span></td>
</tr>
</table>
</td>
</tr>
</table>
<a name="version_info"></a>
<div class="private">
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr><td>
<h3 class="epydoc">version_info</h3>
<dl class="fields">
</dl>
<dl class="fields">
<dt>Value:</dt>
<dd><table><tr><td><pre class="variable">
open(abspath('VERSION', gluon= True), 'r')
</pre></td></tr></table>
</dd>
</dl>
</td></tr></table>
</div>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
bgcolor="#a0c0ff" cellspacing="0">
<tr valign="middle">
<!-- Home link -->
<th> <a
href="web2py.gluon-module.html">Home</a> </th>
<!-- Tree link -->
<th> <a
href="module-tree.html">Trees</a> </th>
<!-- Index link -->
<th> <a
href="identifier-index.html">Indices</a> </th>
<!-- Help link -->
<th> <a
href="help.html">Help</a> </th>
<!-- Project homepage -->
<th class="navbar" align="right" width="100%">
<table border="0" cellpadding="0" cellspacing="0">
<tr><th class="navbar" align="center"
><a class="navbar" target="_top" href="http://www.web2py.com">web2py Web Framework</a></th>
</tr></table></th>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0beta1 on Thu Aug 4 00:46:59 2011
</td>
<td align="right" class="footer">
<a href="http://epydoc.sourceforge.net">http://epydoc.sourceforge.net</a>
</td>
</tr>
</table>
<script type="text/javascript">
<!--
// Private objects are initially displayed (because if
// javascript is turned off then we want them to be
// visible); but by default, we want to hide them. So hide
// them unless we have a cookie that says to show them.
checkCookie()
// -->
</script>
</body>
</html>