cherrypy._cpmodpy module

Native adapter for serving CherryPy via mod_python.

Basic usage:

# Application in a module called myapp.py

import cherrypy

class Root:

@cherrypy.expose def index(self):

return ‘Hi there, Ho there, Hey there’

# We will use this method from the mod_python configuration # as the entry point to our application def setup_server():

cherrypy.tree.mount(Root()) cherrypy.config.update({‘environment’: ‘production’,

‘log.screen’: False, ‘show_tracebacks’: False})

# or a file that will be loaded at # apache startup ##########################################

# Start DocumentRoot “/” Listen 8080 LoadModule python_module /usr/lib/apache2/modules/mod_python.so

<Location “/”>

PythonPath “sys.path+[‘/path/to/my/application’]” SetHandler python-program PythonHandler cherrypy._cpmodpy::handler PythonOption cherrypy.setup myapp::setup_server PythonDebug On

</Location> # End

The actual path to your mod_python.so is dependent on your environment. In this case we suppose a global mod_python installation on a Linux distribution such as Ubuntu.

We do set the PythonPath configuration setting so that your application can be found by from the user running the apache2 instance. Of course if your application resides in the global site-package this won’t be needed.

Then restart apache2 and access http://127.0.0.1:8080

class cherrypy._cpmodpy.ModPythonServer(loc='/', port=80, opts=None, apache_path='apache', handler='cherrypy._cpmodpy::handler')[source]

Bases: object

A server wrapper for mod_python.

start()[source]

Start an Apache2/httpd server.

stop()[source]

Stop an Apache2/httpd server.

template = '\n# Apache2 server configuration file for running CherryPy with mod_python.\n\nDocumentRoot "/"\nListen %(port)s\nLoadModule python_module modules/mod_python.so\n\n<Location %(loc)s>\n    SetHandler python-program\n    PythonHandler %(handler)s\n    PythonDebug On\n%(opts)s\n</Location>\n'
class cherrypy._cpmodpy._ReadOnlyRequest(req)[source]

Bases: object

expose = ('read', 'readline', 'readlines')
cherrypy._cpmodpy.handler(req)[source]

Invoke the HTTP handler.

cherrypy._cpmodpy.popen(fullcmd)[source]

Invoke a subprocess via subprocess.

cherrypy._cpmodpy.read_process(cmd, args='')[source]

Return a subprocess standard output.

cherrypy._cpmodpy.send_response(req, status, headers, body, stream=False)[source]

Send the HTTP response to the client.

cherrypy._cpmodpy.setup(req)[source]

Execute pre-initialization functions.