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

Module compileapp

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)

Functions required to execute app components

FOR INTERNAL USE ONLY

Classes [hide private]
  mybuiltin
NOTE could simple use a dict and populate it, NOTE not sure if this changes things though if monkey patching import.....
  LoadFactory
Attention: this helper is new and experimental
Functions [hide private]
 
LOAD(c=global_settings.applications_parent, f='index', args=global_settings.applications_parent, vars=global_settings.applications_parent, extension=global_settings.applications_parent, target=global_settings.applications_parent, ajax=True, ajax_trap=True, url=global_settings.applications_parent, user_signature=True, content='loading...', **attr) source code
 
local_import_aux(name, reload_force=True, app='welcome')
In apps, instead of importing a local module (in applications/app/modules) with:: import a.b.c as d you should do:: d = local_import('a.b.c') or (to force a reload): d = local_import('a.b.c', reload=True) This prevents conflict between applications and un-necessary execs.
source code
 
build_environment(request, response, session, store_current=True)
Build the environment dictionary into which web2py files are executed.
source code
 
save_pyc(filename)
Bytecode compiles the file `filename`
source code
 
read_pyc(filename)
Read the code inside a bytecode compiled file if the MAGIC number is compatible
source code
 
compile_views(folder)
Compiles all the views in the application specified by `folder`
source code
 
compile_models(folder)
Compiles all the models in the application specified by `folder`
source code
 
compile_controllers(folder)
Compiles all the controllers in the application specified by `folder`
source code
 
run_models_in(environment)
Runs all models (in the app specified by the current folder) It tries pre-compiled models first before compiling them.
source code
 
run_controller_in(controller, function, environment)
Runs the controller.function() (for the app specified by the current folder).
source code
 
run_view_in(environment)
Executes the view for the requested action.
source code
 
remove_compiled_application(folder)
Deletes the folder `compiled` containing the compiled application.
source code
 
compile_application(folder)
Compiles all models, views, controller for the application in `folder`.
source code
 
test()
Example:
source code
Variables [hide private]
  logger = logging.getLogger("web2py")
  is_pypy = True
  is_gae = <web2py.gluon.custom_import._Web2pyImporter object at...
PyMySQL: A pure-Python drop-in replacement for MySQLdb.
  is_jython = True
  TEST_CODE = '\ndef _TEST():\n import doctest, sys, cStringI...
Function Details [hide private]

local_import_aux(name, reload_force=True, app='welcome')

source code 

In apps, instead of importing a local module
(in applications/app/modules) with::

   import a.b.c as d

you should do::

   d = local_import('a.b.c')

or (to force a reload):

   d = local_import('a.b.c', reload=True)

This prevents conflict between applications and un-necessary execs.
It can be used to import any module, including regular Python modules.

read_pyc(filename)

source code 

Read the code inside a bytecode compiled file if the MAGIC number is compatible

:returns: a code object

run_controller_in(controller, function, environment)

source code 
Runs the controller.function() (for the app specified by the current folder). It tries pre-compiled controller_function.pyc first before compiling it.

run_view_in(environment)

source code 
Executes the view for the requested action. The view is the one specified in `response.view` or determined by the url or `view/generic.extension` It tries the pre-compiled views_controller_function.pyc before compiling it.

test()

source code 
Example:
   >>> import traceback, types
   >>> environment={'x':1}
   >>> open('a.py', 'w').write('print 1/x')
   >>> save_pyc('a.py')
   >>> os.unlink('a.py')
   >>> if type(read_pyc('a.pyc'))==types.CodeType: print 'code'
   code
   >>> exec read_pyc('a.pyc') in environment
   1

Variables Details [hide private]

is_gae

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

TEST_CODE

Value:
'''
def _TEST():
    import doctest, sys, cStringIO, types, cgi, gluon.fileutils
    if not gluon.fileutils.check_credentials(request):
        raise HTTP(401, web2py_error=\'invalid credentials\')
    stdout = sys.stdout
    html = \'<h2>Testing controller "%s.py" ... done.</h2><br/>\\n\' \\
\
...