cherrypy._cptree module

CherryPy Application and Tree objects.

class cherrypy._cptree.Application(root, script_name='', config=None)[source]

Bases: object

A CherryPy Application.

Servers and gateways should not instantiate Request objects directly. Instead, they should ask an Application object for a request object.

An instance of this class may also be used as a WSGI callable (WSGI application object) for itself.

config = {}

pathconf} pairs, where ‘pathconf’ is itself a dict of {key: value} pairs.

Type:

A dict of {path

find_config(path, key, default=None)[source]

Return the most-specific value for key along path, or default.

get_serving(local, remote, scheme, sproto)[source]

Create and return a Request and Response object.

log = None

A LogManager instance.

See _cplogging.

merge(config)[source]

Merge the given config into self.config.

namespaces = {}
relative_urls = False
release_serving()[source]

Release the current serving (request and response).

request_class

alias of Request

response_class

alias of Response

root = None

The top-most container of page handlers for this app.

Handlers should be arranged in a hierarchy of attributes, matching the expected URI hierarchy; the default dispatcher then searches this hierarchy for a matching handler. When using a dispatcher other than the default, this value may be None.

property script_name

The URI “mount point” for this app.

A mount point is that portion of the URI which is constant for all URIs that are serviced by this application; it does not include scheme, host, or proxy (“virtual host”) portions of the URI.

For example, if script_name is “/my/cool/app”, then the URL “

http://www.example.com/my/cool/app/page1” might be handled by a “page1” method on the root object.

The value of script_name MUST NOT end in a slash. If the script_name refers to the root of the URI, it MUST be an empty string (not “/”).

If script_name is explicitly set to None, then the script_name will be provided for each call from request.wsgi_environ[‘SCRIPT_NAME’].

script_name_doc = 'The URI "mount point" for this app. A mount point\n    is that portion of the URI which is constant for all URIs that are\n    serviced by this application; it does not include scheme, host, or proxy\n    ("virtual host") portions of the URI.\n\n    For example, if script_name is "/my/cool/app", then the URL\n    "http://www.example.com/my/cool/app/page1" might be handled by a\n    "page1" method on the root object.\n\n    The value of script_name MUST NOT end in a slash. If the script_name\n    refers to the root of the URI, it MUST be an empty string (not "/").\n\n    If script_name is explicitly set to None, then the script_name will be\n    provided for each call from request.wsgi_environ[\'SCRIPT_NAME\'].\n    '
toolboxes = {'tools': <cherrypy._cptools.Toolbox object>}
wsgiapp = None

A CPWSGIApp instance.

See _cpwsgi.

class cherrypy._cptree.Tree[source]

Bases: object

A registry of CherryPy applications, mounted at diverse points.

An instance of this class may also be used as a WSGI callable (WSGI application object), in which case it dispatches to all mounted apps.

apps = {}

application}, where “script name” is a string declaring the URI mount point (no trailing slash), and “application” is an instance of cherrypy.Application (or an arbitrary WSGI callable if you happen to be using a WSGI server).

Type:

A dict of the form {script name

graft(wsgi_callable, script_name='')[source]

Mount a wsgi callable at the given script_name.

mount(root, script_name='', config=None)[source]

Mount a new app from a root object, script_name, and config.

root

An instance of a “controller class” (a collection of page handler methods) which represents the root of the application. This may also be an Application instance, or None if using a dispatcher other than the default.

script_name

A string containing the “mount point” of the application. This should start with a slash, and be the path portion of the URL at which to mount the given root. For example, if root.index() will handle requests to “http://www.example.com:8080/dept/app1/”, then the script_name argument would be “/dept/app1”.

It MUST NOT end in a slash. If the script_name refers to the root of the URI, it MUST be an empty string (not “/”).

config

A file or dict containing application config.

script_name(path=None)[source]

Return the script_name of the app at the given path, or None.

If path is None, cherrypy.request is used.