1 """CherryPy Application and Tree objects."""
2
3 import os
4 import cherrypy
5 from cherrypy import _cpconfig, _cplogging, _cpwsgi, tools
6
7
9 """A CherryPy Application.
10
11 An instance of this class may also be used as a WSGI callable
12 (WSGI application object) for itself.
13 """
14
15 __metaclass__ = cherrypy._AttributeDocstrings
16
17 root = None
18 root__doc = """
19 The top-most container of page handlers for this app. Handlers should
20 be arranged in a hierarchy of attributes, matching the expected URI
21 hierarchy; the default dispatcher then searches this hierarchy for a
22 matching handler. When using a dispatcher other than the default,
23 this value may be None."""
24
25 config = {}
26 config__doc = """
27 A dict of {path: pathconf} pairs, where 'pathconf' is itself a dict
28 of {key: value} pairs."""
29
30 namespaces = _cpconfig.NamespaceSet()
31
32 log = None
33 log__doc = """A LogManager instance. See _cplogging."""
34
35 wsgiapp = None
36 wsgiapp__doc = """A CPWSGIApp instance. See _cpwsgi."""
37
38 - def __init__(self, root, script_name=""):
49
50 script_name__doc = """
51 The URI "mount point" for this app; for example, if script_name is
52 "/my/cool/app", then the URL "http://my.domain.tld/my/cool/app/page1"
53 might be handled by a "page1" method on the root object. If script_name
54 is explicitly set to None, then the script_name will be provided
55 for each call from request.wsgi_environ['SCRIPT_NAME']."""
57 if self._script_name is None:
58
59 return cherrypy.request.wsgi_environ['SCRIPT_NAME']
60 return self._script_name
62 self._script_name = value
63 script_name = property(fget=_get_script_name, fset=_set_script_name,
64 doc=script_name__doc)
65
72
73 - def __call__(self, environ, start_response):
75
76
78 """A registry of CherryPy applications, mounted at diverse points.
79
80 An instance of this class may also be used as a WSGI callable
81 (WSGI application object), in which case it dispatches to all
82 mounted apps.
83 """
84
85 apps = {}
86 apps__doc = """
87 A dict of the form {script name: application}, where "script name"
88 is a string declaring the URI mount point (no trailing slash), and
89 "application" is an instance of cherrypy.Application (or an arbitrary
90 WSGI callable if you happen to be using a WSGI server)."""
91
94
95 - def mount(self, root, script_name="", config=None):
117
118 - def graft(self, wsgi_callable, script_name=""):
123
125 """The script_name of the app at the given path, or None.
126
127 If path is None, cherrypy.request is used.
128 """
129
130 if path is None:
131 try:
132 path = cherrypy.request.script_name + cherrypy.request.path_info
133 except AttributeError:
134 return None
135
136 while True:
137 if path in self.apps:
138 return path
139
140 if path == "":
141 return None
142
143
144 path = path[:path.rfind("/")]
145
146 - def __call__(self, environ, start_response):
163