Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1939

Show
Ignore:
Timestamp:
04/05/08 15:07:05
Author:
fumanchu
Message:

mod_python: send bus messages to the apache log, plus cherrypy.setup arg now can take a bare module to import (without having to call a ::function).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/_cpmodpy.py

    r1830 r1939  
    6565""" 
    6666 
     67import logging 
    6768import StringIO 
    6869 
     
    7677 
    7778 
     79 
    7880def setup(req): 
     81    from mod_python import apache 
     82     
    7983    # Run any setup function defined by a "PythonOption cherrypy.setup" directive. 
    8084    options = req.get_options() 
    8185    if 'cherrypy.setup' in options: 
    82         modname, fname = options['cherrypy.setup'].split('::') 
    83         mod = __import__(modname, globals(), locals(), [fname]) 
    84         func = getattr(mod, fname) 
    85         func() 
     86        atoms = options['cherrypy.setup'].split('::', 1) 
     87        if len(atoms) == 1: 
     88            mod = __import__(atoms[0], globals(), locals()) 
     89        else: 
     90            modname, fname = atoms 
     91            mod = __import__(modname, globals(), locals(), [fname]) 
     92            func = getattr(mod, fname) 
     93            func() 
    8694     
    8795    cherrypy.config.update({'log.screen': False, 
     
    9098                            }) 
    9199     
     100    cherrypy._console_control_handler.unsubscribe() 
     101    cherrypy.engine.autoreload.unsubscribe() 
    92102    cherrypy.server.unsubscribe() 
     103     
     104    def _log(msg, level): 
     105        newlevel = apache.APLOG_ERR 
     106        if logging.DEBUG >= level: 
     107            newlevel = apache.APLOG_DEBUG 
     108        elif logging.INFO >= level: 
     109            newlevel = apache.APLOG_INFO 
     110        elif logging.WARNING >= level: 
     111            newlevel = apache.APLOG_WARNING 
     112        # On Windows, req.server is required or the msg will vanish. See 
     113        # http://www.modpython.org/pipermail/mod_python/2003-October/014291.html. 
     114        # Also, "When server is not specified...LogLevel does not apply..." 
     115        apache.log_error(msg, newlevel, req.server) 
     116    cherrypy.engine.subscribe('log', _log) 
     117     
    93118    cherrypy.engine.start() 
    94119     
     
    96121        cherrypy.engine.exit() 
    97122    try: 
    98         from mod_python import apache 
    99123        # apache.register_cleanup wasn't available until 3.1.4. 
    100124        apache.register_cleanup(cherrypy_cleanup) 
     
    210234    except: 
    211235        tb = format_exc() 
    212         cherrypy.log(tb
     236        cherrypy.log(tb, 'MOD_PYTHON', severity=logging.ERROR
    213237        s, h, b = bare_error() 
    214238        send_response(req, s, h, b) 

Hosted by WebFaction

Log in as guest/cpguest to create tickets