Package web2py :: Package gluon :: Module main
[hide private]
[frames] | no frames]

Module main

source code


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



Classes [hide private]
  HttpServer
the web2py web server (Rocket)
Functions [hide private]
 
get_client(env)
guess the client address from the environment variables
source code
 
copystream_progress(request, chunk_size=100000)
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
source code
 
serve_controller(request, response, session)
this function is used to generate a dynamic page.
source code
 
start_response_aux(status, headers, exc_info, response=global_settings.applications_parent)
in controller you can use::...
source code
 
middleware_aux(request, response, *middleware_apps)
In you controller use:
source code
 
environ_aux(environ, request) source code
 
parse_get_post_vars(request, environ) source code
 
wsgibase(environ, responder)
this is the gluon wsgi application.
source code
 
save_password(password, port)
used by main() to save the password in the parameters_port.py file.
source code
 
appfactory(wsgiapp=<function wsgibase at 0x15a8668>, logfilename='httpserver.log', profilerfilename='profiler.log')
generates a wsgi application that does logging and profiling and calls wsgibase ..
source code
Variables [hide private]
  web2py_path = <web2py.gluon.custom_import._Web2pyImporter obje...
PyMySQL: A pure-Python drop-in replacement for MySQLdb.
  logpath = '/home/mdipierro/web2py/logging.conf'
  logger = logging.getLogger("web2py")
  requests = 0
  regex_client = re.compile(r'[\w-:]+(\.[\w-]+)*\.?')
  version_info = <closed file '/home/mdipierro/web2py/VERSION', ...
  web2py_version = (1, 99, 4, datetime.datetime(2011, 12, 14, 8,...
Function Details [hide private]

get_client(env)

source code 

guess the client address from the environment variables

first tries 'http_x_forwarded_for', secondly 'remote_addr' if all fails assume '127.0.0.1' (running locally)

serve_controller(request, response, session)

source code 
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

start_response_aux(status, headers, exc_info, response=global_settings.applications_parent)

source code 

in controller you can use::

- request.wsgi.environ
- request.wsgi.start_response

to call third party WSGI applications

middleware_aux(request, response, *middleware_apps)

source code 
In you controller use:
   @request.wsgi.middleware(middleware1, middleware2, ...)
to decorate actions with WSGI middleware. actions must return strings. uses a simulated environment so it may have weird behavior in some cases

wsgibase(environ, responder)

source code 

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 '/'

appfactory(wsgiapp=<function wsgibase at 0x15a8668>, logfilename='httpserver.log', profilerfilename='profiler.log')

source code 

generates a wsgi application that does logging and profiling and calls
wsgibase

.. function:: gluon.main.appfactory(
        [wsgiapp=wsgibase
        [, logfilename='httpserver.log'
        [, profilerfilename='profiler.log']]])


Variables Details [hide private]

web2py_path

PyMySQL: A pure-Python drop-in replacement for MySQLdb.

Copyright (c) 2010 PyMySQL contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Value:
global_settings.applications_parent

version_info

Value:
open(abspath('VERSION', gluon= True), 'r')

web2py_version

Value:
(1, 99, 4, datetime.datetime(2011, 12, 14, 8, 42, 17), 'stable')