summaryrefslogtreecommitdiff
path: root/cherrypy/tutorial
diff options
context:
space:
mode:
authorRobert Brewer <fumanchu@aminus.org>2006-05-07 06:35:03 +0000
committerRobert Brewer <fumanchu@aminus.org>2006-05-07 06:35:03 +0000
commit8cc98e6c07a312877a2893e7d9cc7d7923d21227 (patch)
tree15cb1a36113cd0245ee189b09a231fd88fb09d44 /cherrypy/tutorial
parent75d306ecb9f843782254c0250b6afa2df9b4e332 (diff)
downloadcherrypy-git-8cc98e6c07a312877a2893e7d9cc7d7923d21227.tar.gz
Root and config are now isolated per app:
1. object_path is now called path_info, and there's a new request.script_name attribute. This should equal the mount point of the current application. 2. cherrypy.root is gone, use cherrypy.request.app.root for now instead. Perhaps cherrypy.root will reappear and point to that. 3. cherrypy.tree.mount_points has been replaced with cherrypy.tree.apps, a dict of the form {script_name: Application(root, conf)}. 4. The [global] config namespace is now contained in a flat cherrypy.config.globalconf dict. 5. Got rid of handling favicon.ico and the "*" URI (although they may return someday). 6. Upshot is that e.g. test_objectmapping.py takes 1/3 the time as CP 2.2. 7. Moved request body size check into _cprequest from _cpwsgi. 8. Fixed lib/wsgiapp and made a tool for it.
Diffstat (limited to 'cherrypy/tutorial')
-rw-r--r--cherrypy/tutorial/bonus-sqlobject.py2
-rw-r--r--cherrypy/tutorial/tut01_helloworld.py9
-rw-r--r--cherrypy/tutorial/tut02_expose_methods.py4
-rw-r--r--cherrypy/tutorial/tut03_get_and_post.py4
-rw-r--r--cherrypy/tutorial/tut04_complex_site.py9
-rw-r--r--cherrypy/tutorial/tut05_derived_objects.py4
-rw-r--r--cherrypy/tutorial/tut06_default_method.py4
-rw-r--r--cherrypy/tutorial/tut07_sessions.py9
-rw-r--r--cherrypy/tutorial/tut08_generators_and_yield.py4
-rw-r--r--cherrypy/tutorial/tut09_files.py5
-rw-r--r--cherrypy/tutorial/tut10_http_errors.py18
11 files changed, 37 insertions, 35 deletions
diff --git a/cherrypy/tutorial/bonus-sqlobject.py b/cherrypy/tutorial/bonus-sqlobject.py
index 3bf32e2b..fc5e756e 100644
--- a/cherrypy/tutorial/bonus-sqlobject.py
+++ b/cherrypy/tutorial/bonus-sqlobject.py
@@ -165,6 +165,6 @@ class ContactManager:
print "If you're running this application for the first time, please go to http://localhost:8080/reset once in order to create the database!"
-cherrypy.root = ContactManager()
+cherrypy.tree.mount(ContactManager())
cherrypy.server.start()
cherrypy.engine.start()
diff --git a/cherrypy/tutorial/tut01_helloworld.py b/cherrypy/tutorial/tut01_helloworld.py
index 63cdf9dd..ccde9079 100644
--- a/cherrypy/tutorial/tut01_helloworld.py
+++ b/cherrypy/tutorial/tut01_helloworld.py
@@ -21,15 +21,14 @@ class HelloWorld:
# publish methods that don't have the exposed attribute set to True.
index.exposed = True
-# CherryPy always starts with cherrypy.root when trying to map request URIs
+# CherryPy always starts with app.root when trying to map request URIs
# to objects, so we need to mount a request handler object here. A request
-# to '/' will be mapped to cherrypy.root.index().
-cherrypy.root = HelloWorld()
+# to '/' will be mapped to HelloWorld().index().
+cherrypy.tree.mount(HelloWorld())
if __name__ == '__main__':
- # Use the configuration file tutorial.conf.
- cherrypy.config.update(file = 'tutorial.conf')
# Start the CherryPy server.
+ cherrypy.config.update(os.path.join(os.path.dirname(__file__), 'tutorial.conf'))
cherrypy.server.start()
cherrypy.engine.start()
diff --git a/cherrypy/tutorial/tut02_expose_methods.py b/cherrypy/tutorial/tut02_expose_methods.py
index d4418d4f..f6b0f410 100644
--- a/cherrypy/tutorial/tut02_expose_methods.py
+++ b/cherrypy/tutorial/tut02_expose_methods.py
@@ -19,10 +19,10 @@ class HelloWorld:
return "Hello world!"
showMessage.exposed = True
-cherrypy.root = HelloWorld()
+cherrypy.tree.mount(HelloWorld())
if __name__ == '__main__':
- cherrypy.config.update(file = 'tutorial.conf')
+ cherrypy.config.update(os.path.join(os.path.dirname(__file__), 'tutorial.conf'))
cherrypy.server.start()
cherrypy.engine.start()
diff --git a/cherrypy/tutorial/tut03_get_and_post.py b/cherrypy/tutorial/tut03_get_and_post.py
index 699db47f..7fe002e0 100644
--- a/cherrypy/tutorial/tut03_get_and_post.py
+++ b/cherrypy/tutorial/tut03_get_and_post.py
@@ -40,10 +40,10 @@ class WelcomePage:
greetUser.exposed = True
-cherrypy.root = WelcomePage()
+cherrypy.tree.mount(WelcomePage())
if __name__ == '__main__':
- cherrypy.config.update(file = 'tutorial.conf')
+ cherrypy.config.update(os.path.join(os.path.dirname(__file__), 'tutorial.conf'))
cherrypy.server.start()
cherrypy.engine.start()
diff --git a/cherrypy/tutorial/tut04_complex_site.py b/cherrypy/tutorial/tut04_complex_site.py
index 076c484e..dd930c38 100644
--- a/cherrypy/tutorial/tut04_complex_site.py
+++ b/cherrypy/tutorial/tut04_complex_site.py
@@ -74,9 +74,10 @@ class ExtraLinksPage:
# Of course we can also mount request handler objects right here!
-cherrypy.root = HomePage()
-cherrypy.root.joke = JokePage()
-cherrypy.root.links = LinksPage()
+root = HomePage()
+root.joke = JokePage()
+root.links = LinksPage()
+cherrypy.tree.mount(root)
# Remember, we don't need to mount ExtraLinksPage here, because
# LinksPage does that itself on initialization. In fact, there is
@@ -85,7 +86,7 @@ cherrypy.root.links = LinksPage()
if __name__ == '__main__':
- cherrypy.config.update(file = 'tutorial.conf')
+ cherrypy.config.update(os.path.join(os.path.dirname(__file__), 'tutorial.conf'))
cherrypy.server.start()
cherrypy.engine.start()
diff --git a/cherrypy/tutorial/tut05_derived_objects.py b/cherrypy/tutorial/tut05_derived_objects.py
index d7789efd..54684d2b 100644
--- a/cherrypy/tutorial/tut05_derived_objects.py
+++ b/cherrypy/tutorial/tut05_derived_objects.py
@@ -69,11 +69,11 @@ class AnotherPage(Page):
index.exposed = True
-cherrypy.root = HomePage()
+cherrypy.tree.mount(HomePage())
if __name__ == '__main__':
- cherrypy.config.update(file = 'tutorial.conf')
+ cherrypy.config.update(os.path.join(os.path.dirname(__file__), 'tutorial.conf'))
cherrypy.server.start()
cherrypy.engine.start()
diff --git a/cherrypy/tutorial/tut06_default_method.py b/cherrypy/tutorial/tut06_default_method.py
index bf7018a6..2a1fdb22 100644
--- a/cherrypy/tutorial/tut06_default_method.py
+++ b/cherrypy/tutorial/tut06_default_method.py
@@ -50,11 +50,11 @@ class UsersPage:
default.exposed = True
-cherrypy.root = UsersPage()
+cherrypy.tree.mount(UsersPage())
if __name__ == '__main__':
- cherrypy.config.update(file = 'tutorial.conf')
+ cherrypy.config.update(os.path.join(os.path.dirname(__file__), 'tutorial.conf'))
cherrypy.server.start()
cherrypy.engine.start()
diff --git a/cherrypy/tutorial/tut07_sessions.py b/cherrypy/tutorial/tut07_sessions.py
index 1fb73721..07928006 100644
--- a/cherrypy/tutorial/tut07_sessions.py
+++ b/cherrypy/tutorial/tut07_sessions.py
@@ -12,6 +12,9 @@ import cherrypy
class HitCounter:
+
+ _cp_config = {'tools.sessions.on': True}
+
def index(self):
# Increase the silly hit counter
count = cherrypy.session.get('count', 0) + 1
@@ -27,11 +30,11 @@ class HitCounter:
index.exposed = True
-cherrypy.root = HitCounter()
-cherrypy.config.update({'tools.sessions.on': True})
+cherrypy.tree.mount(HitCounter())
+
if __name__ == '__main__':
- cherrypy.config.update(file = 'tutorial.conf')
+ cherrypy.config.update(os.path.join(os.path.dirname(__file__), 'tutorial.conf'))
cherrypy.server.start()
cherrypy.engine.start()
diff --git a/cherrypy/tutorial/tut08_generators_and_yield.py b/cherrypy/tutorial/tut08_generators_and_yield.py
index 6a9f5b46..6d2e1239 100644
--- a/cherrypy/tutorial/tut08_generators_and_yield.py
+++ b/cherrypy/tutorial/tut08_generators_and_yield.py
@@ -32,11 +32,11 @@ class GeneratorDemo:
yield self.footer()
index.exposed = True
-cherrypy.root = GeneratorDemo()
+cherrypy.tree.mount(GeneratorDemo())
if __name__ == '__main__':
- cherrypy.config.update(file = 'tutorial.conf')
+ cherrypy.config.update(os.path.join(os.path.dirname(__file__), 'tutorial.conf'))
cherrypy.server.start()
cherrypy.engine.start()
diff --git a/cherrypy/tutorial/tut09_files.py b/cherrypy/tutorial/tut09_files.py
index 5ecc8839..d6899920 100644
--- a/cherrypy/tutorial/tut09_files.py
+++ b/cherrypy/tutorial/tut09_files.py
@@ -91,11 +91,10 @@ class FileDemo(object):
download.exposed = True
-cherrypy.root = FileDemo()
+cherrypy.tree.mount(FileDemo())
if __name__ == '__main__':
- # Use the configuration file tutorial.conf.
- cherrypy.config.update(file = 'tutorial.conf')
# Start the CherryPy server.
+ cherrypy.config.update(os.path.join(os.path.dirname(__file__), 'tutorial.conf'))
cherrypy.server.start()
cherrypy.engine.start()
diff --git a/cherrypy/tutorial/tut10_http_errors.py b/cherrypy/tutorial/tut10_http_errors.py
index 4fc35d0b..207e8cd0 100644
--- a/cherrypy/tutorial/tut10_http_errors.py
+++ b/cherrypy/tutorial/tut10_http_errors.py
@@ -8,11 +8,18 @@ logged, displayed, and formatted.
"""
+import os
+localDir = os.path.dirname(__file__)
+curpath = os.path.normpath(os.path.join(os.getcwd(), localDir))
+
import cherrypy
class HTTPErrorDemo(object):
+ # Set a custom response for 403 errors.
+ _cp_config = {'error_page.403' : os.path.join(curpath, "custom_error.html")}
+
def index(self):
# display some links that will result in errors
tracebacks = cherrypy.config.get('show_tracebacks')
@@ -61,18 +68,11 @@ class HTTPErrorDemo(object):
messageArg.exposed = True
-cherrypy.root = HTTPErrorDemo()
-
-# Set a custom response for 403 errors.
-import os
-localDir = os.path.dirname(__file__)
-curpath = os.path.normpath(os.path.join(os.getcwd(), localDir))
-cherrypy.config.update({'error_page.403' : os.path.join(curpath, "custom_error.html")})
+cherrypy.tree.mount(HTTPErrorDemo())
if __name__ == '__main__':
- # Use the configuration file tutorial.conf.
- cherrypy.config.update(file = 'tutorial.conf')
# Start the CherryPy server.
+ cherrypy.config.update(os.path.join(os.path.dirname(__file__), 'tutorial.conf'))
cherrypy.server.start()
cherrypy.engine.start()