Contact: fumanchu@aminus.org

Log in as guest/misc to create tickets

Changeset 41

Show
Ignore:
Timestamp:
02/11/06 00:05:14
Author:
fumanchu
Message:

Backward-incompatible changes from modpython ML discussion:

  1. The "import" PythonOption? is removed in favor of PythonFixupHandler? declarations.
  2. The "application" PythonOption? has been renamed "wsgi.application", to help with PythonOption? namespace issues.
  3. The "profile" function has been removed.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modpython_gateway.py

    r39 r41  
    77<Location /mcontrol> 
    88    SetHandler python-program 
     9    PythonFixupHandler mcontrol.cherry::startup 
    910    PythonHandler modpython_gateway::handler 
    10     PythonOption application cherrypy._cpwsgi::wsgiApp 
    11     PythonOption import mcontrol.cherry::startup 
     11    PythonOption wsgi.application cherrypy._cpwsgi::wsgiApp 
    1212</Location> 
    1313 
     
    164164 
    165165 
    166 _counter = 0 
    167  
    168 def profile(req): 
    169     # Call this function instead of "handler" 
    170     # to get profiling data for each call. 
    171     import hotshot, os.path 
    172     global _counter 
    173     _counter += 1 
    174     ppath = os.path.join(os.path.dirname(__file__), "cp_%s.prof" % _counter) 
    175     prof = hotshot.Profile(ppath) 
    176     prof.runcall(handler, req) 
    177     prof.close() 
    178     return apache.OK 
    179  
    180166def handler(req): 
    181     # If you use a PythonImport directive as recommended, its interpreter_name 
    182     # value must EXACTLY match the value of req.interpreter (case-sensitive). 
    183     # You can un-comment the next line to get the value of req.interpreter. 
    184 ##  raise StandardError(repr(req.interpreter)) 
    185      
    186     config = req.get_config() 
    187     debug = int(config.get("PythonDebug", 0)) 
    188      
    189     options = req.get_options() 
    190      
    191     # Because PythonImport cannot be specified per Directory or Location, 
    192     # take any 'import' PythonOption's and import them. If a function name 
    193     # in that module is provided (after the "::"), it will be called with 
    194     # the request as an argument. The module and function, if any, should 
    195     # be re-entrant (i.e., handle multiple threads), and, since they will 
    196     # be called per request, must be designed to run setup code only on the 
    197     # first request (a global 'first_request' flag is usually enough). 
    198     import_opt = options.get('import') 
    199     if import_opt: 
    200         atoms = import_opt.split('::', 1) 
    201         modname = atoms.pop(0) 
    202         module = __import__(modname, globals(), locals(), ['']) 
    203         if atoms: 
    204             func = getattr(module, atoms[0]) 
    205             func(req) 
    206      
    207167    # Import the wsgi 'application' callable and pass it to Handler.run 
    208     modname, objname = options['application'].split('::', 1) 
     168    modname, objname = req.get_options()['wsgi.application'].split('::', 1) 
    209169    module = __import__(modname, globals(), locals(), ['']) 
    210170    app = getattr(module, objname)