diff options
| author | Robert Brewer <fumanchu@aminus.org> | 2010-01-01 18:28:10 +0000 |
|---|---|---|
| committer | Robert Brewer <fumanchu@aminus.org> | 2010-01-01 18:28:10 +0000 |
| commit | ad0349fa34c32e9a0f9963c095c0844f2304354b (patch) | |
| tree | e22368d11685f04021b1b568dc9038eab5609c01 /cherrypy/tutorial | |
| parent | b6bd707e74eb30c7f0153c1b503555d66b76454f (diff) | |
| download | cherrypy-git-ad0349fa34c32e9a0f9963c095c0844f2304354b.tar.gz | |
Fixing tutorials which did not run on command-line.
Diffstat (limited to 'cherrypy/tutorial')
| -rw-r--r-- | cherrypy/tutorial/custom_error.html | 4 | ||||
| -rw-r--r-- | cherrypy/tutorial/tut02_expose_methods.py | 14 | ||||
| -rw-r--r-- | cherrypy/tutorial/tut03_get_and_post.py | 14 | ||||
| -rw-r--r-- | cherrypy/tutorial/tut04_complex_site.py | 14 | ||||
| -rw-r--r-- | cherrypy/tutorial/tut05_derived_objects.py | 15 | ||||
| -rw-r--r-- | cherrypy/tutorial/tut06_default_method.py | 15 | ||||
| -rw-r--r-- | cherrypy/tutorial/tut07_sessions.py | 15 | ||||
| -rw-r--r-- | cherrypy/tutorial/tut08_generators_and_yield.py | 14 | ||||
| -rw-r--r-- | cherrypy/tutorial/tut09_files.py | 17 | ||||
| -rw-r--r-- | cherrypy/tutorial/tut10_http_errors.py | 18 |
10 files changed, 94 insertions, 46 deletions
diff --git a/cherrypy/tutorial/custom_error.html b/cherrypy/tutorial/custom_error.html index 22ac603b..682ec0c0 100644 --- a/cherrypy/tutorial/custom_error.html +++ b/cherrypy/tutorial/custom_error.html @@ -9,6 +9,6 @@ <h2>You can't do that!</h2>
<p>%(message)s</p> <p>This is a custom error page that is read from a file.<p>
- <p>%(traceback)s</p> + <pre>%(traceback)s</pre> </body> -</html>
\ No newline at end of file +</html> diff --git a/cherrypy/tutorial/tut02_expose_methods.py b/cherrypy/tutorial/tut02_expose_methods.py index 6df2cd3f..600fca34 100644 --- a/cherrypy/tutorial/tut02_expose_methods.py +++ b/cherrypy/tutorial/tut02_expose_methods.py @@ -19,10 +19,14 @@ class HelloWorld: return "Hello world!" showMessage.exposed = True -cherrypy.tree.mount(HelloWorld()) +import os.path +tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf') if __name__ == '__main__': - import os.path - thisdir = os.path.dirname(__file__) - cherrypy.quickstart(config=os.path.join(thisdir, 'tutorial.conf')) - + # CherryPy always starts with app.root when trying to map request URIs + # to objects, so we need to mount a request handler root. A request + # to '/' will be mapped to HelloWorld().index(). + cherrypy.quickstart(HelloWorld(), config=tutconf) +else: + # This branch is for the test suite; you can ignore it. + cherrypy.tree.mount(HelloWorld(), config=tutconf) diff --git a/cherrypy/tutorial/tut03_get_and_post.py b/cherrypy/tutorial/tut03_get_and_post.py index e30f44e4..283477d5 100644 --- a/cherrypy/tutorial/tut03_get_and_post.py +++ b/cherrypy/tutorial/tut03_get_and_post.py @@ -40,10 +40,14 @@ class WelcomePage: greetUser.exposed = True -cherrypy.tree.mount(WelcomePage()) - +import os.path +tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf') if __name__ == '__main__': - import os.path - thisdir = os.path.dirname(__file__) - cherrypy.quickstart(config=os.path.join(thisdir, 'tutorial.conf')) + # CherryPy always starts with app.root when trying to map request URIs + # to objects, so we need to mount a request handler root. A request + # to '/' will be mapped to HelloWorld().index(). + cherrypy.quickstart(WelcomePage(), config=tutconf) +else: + # This branch is for the test suite; you can ignore it. + cherrypy.tree.mount(WelcomePage(), config=tutconf) diff --git a/cherrypy/tutorial/tut04_complex_site.py b/cherrypy/tutorial/tut04_complex_site.py index 63e581b0..b4d820ed 100644 --- a/cherrypy/tutorial/tut04_complex_site.py +++ b/cherrypy/tutorial/tut04_complex_site.py @@ -77,7 +77,6 @@ class ExtraLinksPage: 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,8 +84,15 @@ cherrypy.tree.mount(root) # creating all contained request handler objects. +import os.path +tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf') + if __name__ == '__main__': - import os.path - thisdir = os.path.dirname(__file__) - cherrypy.quickstart(config=os.path.join(thisdir, 'tutorial.conf')) + # CherryPy always starts with app.root when trying to map request URIs + # to objects, so we need to mount a request handler root. A request + # to '/' will be mapped to HelloWorld().index(). + cherrypy.quickstart(root, config=tutconf) +else: + # This branch is for the test suite; you can ignore it. + cherrypy.tree.mount(root, config=tutconf) diff --git a/cherrypy/tutorial/tut05_derived_objects.py b/cherrypy/tutorial/tut05_derived_objects.py index 9656ffe4..3d4ec9b1 100644 --- a/cherrypy/tutorial/tut05_derived_objects.py +++ b/cherrypy/tutorial/tut05_derived_objects.py @@ -69,10 +69,15 @@ class AnotherPage(Page): index.exposed = True -cherrypy.tree.mount(HomePage()) - +import os.path +tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf') if __name__ == '__main__': - import os.path - thisdir = os.path.dirname(__file__) - cherrypy.quickstart(config=os.path.join(thisdir, 'tutorial.conf')) + # CherryPy always starts with app.root when trying to map request URIs + # to objects, so we need to mount a request handler root. A request + # to '/' will be mapped to HelloWorld().index(). + cherrypy.quickstart(HomePage(), config=tutconf) +else: + # This branch is for the test suite; you can ignore it. + cherrypy.tree.mount(HomePage(), config=tutconf) + diff --git a/cherrypy/tutorial/tut06_default_method.py b/cherrypy/tutorial/tut06_default_method.py index 4ccc7330..fe24f380 100644 --- a/cherrypy/tutorial/tut06_default_method.py +++ b/cherrypy/tutorial/tut06_default_method.py @@ -50,10 +50,15 @@ class UsersPage: default.exposed = True -cherrypy.tree.mount(UsersPage()) - +import os.path +tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf') if __name__ == '__main__': - import os.path - thisdir = os.path.dirname(__file__) - cherrypy.quickstart(config=os.path.join(thisdir, 'tutorial.conf')) + # CherryPy always starts with app.root when trying to map request URIs + # to objects, so we need to mount a request handler root. A request + # to '/' will be mapped to HelloWorld().index(). + cherrypy.quickstart(UsersPage(), config=tutconf) +else: + # This branch is for the test suite; you can ignore it. + cherrypy.tree.mount(UsersPage(), config=tutconf) + diff --git a/cherrypy/tutorial/tut07_sessions.py b/cherrypy/tutorial/tut07_sessions.py index 0c1e167c..4b1386b4 100644 --- a/cherrypy/tutorial/tut07_sessions.py +++ b/cherrypy/tutorial/tut07_sessions.py @@ -30,10 +30,15 @@ class HitCounter: index.exposed = True -cherrypy.tree.mount(HitCounter()) - +import os.path +tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf') if __name__ == '__main__': - import os.path - thisdir = os.path.dirname(__file__) - cherrypy.quickstart(config=os.path.join(thisdir, 'tutorial.conf')) + # CherryPy always starts with app.root when trying to map request URIs + # to objects, so we need to mount a request handler root. A request + # to '/' will be mapped to HelloWorld().index(). + cherrypy.quickstart(HitCounter(), config=tutconf) +else: + # This branch is for the test suite; you can ignore it. + cherrypy.tree.mount(HitCounter(), config=tutconf) + diff --git a/cherrypy/tutorial/tut08_generators_and_yield.py b/cherrypy/tutorial/tut08_generators_and_yield.py index c5be531f..a6fbdc24 100644 --- a/cherrypy/tutorial/tut08_generators_and_yield.py +++ b/cherrypy/tutorial/tut08_generators_and_yield.py @@ -32,10 +32,16 @@ class GeneratorDemo: yield self.footer() index.exposed = True -cherrypy.tree.mount(GeneratorDemo()) +import os.path +tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf') if __name__ == '__main__': - import os.path - thisdir = os.path.dirname(__file__) - cherrypy.quickstart(config=os.path.join(thisdir, 'tutorial.conf')) + # CherryPy always starts with app.root when trying to map request URIs + # to objects, so we need to mount a request handler root. A request + # to '/' will be mapped to HelloWorld().index(). + cherrypy.quickstart(GeneratorDemo(), config=tutconf) +else: + # This branch is for the test suite; you can ignore it. + cherrypy.tree.mount(GeneratorDemo(), config=tutconf) + diff --git a/cherrypy/tutorial/tut09_files.py b/cherrypy/tutorial/tut09_files.py index e5107a19..6243d650 100644 --- a/cherrypy/tutorial/tut09_files.py +++ b/cherrypy/tutorial/tut09_files.py @@ -53,10 +53,13 @@ class FileDemo(object): def index(self): return """ <html><body> + <h2>Upload a file</h2> <form action="upload" method="post" enctype="multipart/form-data"> filename: <input type="file" name="myFile" /><br /> <input type="submit" /> </form> + <h2>Download a file</h2> + <a href='download'>This one</a> </body></html> """ index.exposed = True @@ -91,9 +94,15 @@ class FileDemo(object): download.exposed = True -cherrypy.tree.mount(FileDemo()) +import os.path +tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf') if __name__ == '__main__': - import os.path - thisdir = os.path.dirname(__file__) - cherrypy.quickstart(config=os.path.join(thisdir, 'tutorial.conf')) + # CherryPy always starts with app.root when trying to map request URIs + # to objects, so we need to mount a request handler root. A request + # to '/' will be mapped to HelloWorld().index(). + cherrypy.quickstart(FileDemo(), config=tutconf) +else: + # This branch is for the test suite; you can ignore it. + cherrypy.tree.mount(FileDemo(), config=tutconf) + diff --git a/cherrypy/tutorial/tut10_http_errors.py b/cherrypy/tutorial/tut10_http_errors.py index 9d1e2008..dfa57331 100644 --- a/cherrypy/tutorial/tut10_http_errors.py +++ b/cherrypy/tutorial/tut10_http_errors.py @@ -30,9 +30,9 @@ class HTTPErrorDemo(object): return """ <html><body> - <h2><a href="toggleTracebacks">Toggle tracebacks %s</a></h2> + <p>Toggle tracebacks <a href="toggleTracebacks">%s</a></p> <p><a href="/doesNotExist">Click me; I'm a broken link!</a></p> - <p><a href="/error?code=403">Use a custom an error page from a file.</a></p> + <p><a href="/error?code=403">Use a custom error page from a file.</a></p> <p>These errors are explicitly raised by the application:</p> <ul> <li><a href="/error?code=400">400</a></li> @@ -68,10 +68,14 @@ class HTTPErrorDemo(object): messageArg.exposed = True -cherrypy.tree.mount(HTTPErrorDemo()) - +import os.path +tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf') if __name__ == '__main__': - import os.path - thisdir = os.path.dirname(__file__) - cherrypy.quickstart(config=os.path.join(thisdir, 'tutorial.conf')) + # CherryPy always starts with app.root when trying to map request URIs + # to objects, so we need to mount a request handler root. A request + # to '/' will be mapped to HelloWorld().index(). + cherrypy.quickstart(HTTPErrorDemo(), config=tutconf) +else: + # This branch is for the test suite; you can ignore it. + cherrypy.tree.mount(HTTPErrorDemo(), config=tutconf) |
