summaryrefslogtreecommitdiff
path: root/cherrypy/tutorial
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2016-06-05 15:53:11 -0400
committerJason R. Coombs <jaraco@jaraco.com>2016-06-05 15:53:11 -0400
commit5e1a48fdbfc528f1db95ae38bef145801654124f (patch)
tree34936e842d8b5165444e03a3594e9a9f0ef0afa6 /cherrypy/tutorial
parentf77bef63b18748e2bbbd66543f8fc06fa6d1c7b3 (diff)
downloadcherrypy-git-5e1a48fdbfc528f1db95ae38bef145801654124f.tar.gz
Use expose decorator throughout the codebase.
Diffstat (limited to 'cherrypy/tutorial')
-rw-r--r--cherrypy/tutorial/tut01_helloworld.py7
-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.py8
-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.py2
-rw-r--r--cherrypy/tutorial/tut08_generators_and_yield.py2
-rw-r--r--cherrypy/tutorial/tut09_files.py6
-rw-r--r--cherrypy/tutorial/tut10_http_errors.py8
10 files changed, 24 insertions, 25 deletions
diff --git a/cherrypy/tutorial/tut01_helloworld.py b/cherrypy/tutorial/tut01_helloworld.py
index 2fa61afa..05035f1d 100644
--- a/cherrypy/tutorial/tut01_helloworld.py
+++ b/cherrypy/tutorial/tut01_helloworld.py
@@ -12,6 +12,9 @@ class HelloWorld:
""" Sample request handler class. """
+ # Expose the index method through the web. CherryPy will never
+ # publish methods that don't have the exposed attribute set to True.
+ @cherrypy.expose
def index(self):
# CherryPy will call this method for the root URI ("/") and send
# its return value to the client. Because this is tutorial
@@ -19,10 +22,6 @@ class HelloWorld:
# How about...
return "Hello world!"
- # Expose the index method through the web. CherryPy will never
- # publish methods that don't have the exposed attribute set to True.
- index.exposed = True
-
import os.path
tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf')
diff --git a/cherrypy/tutorial/tut02_expose_methods.py b/cherrypy/tutorial/tut02_expose_methods.py
index 64a10f26..d11b7571 100644
--- a/cherrypy/tutorial/tut02_expose_methods.py
+++ b/cherrypy/tutorial/tut02_expose_methods.py
@@ -10,15 +10,15 @@ import cherrypy
class HelloWorld:
+ @cherrypy.expose
def index(self):
# Let's link to another method here.
return 'We have an <a href="show_msg">important message</a> for you!'
- index.exposed = True
+ @cherrypy.expose
def show_msg(self):
# Here's the important message!
return "Hello world!"
- show_msg.exposed = True
import os.path
tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf')
diff --git a/cherrypy/tutorial/tut03_get_and_post.py b/cherrypy/tutorial/tut03_get_and_post.py
index a487a909..c363c123 100644
--- a/cherrypy/tutorial/tut03_get_and_post.py
+++ b/cherrypy/tutorial/tut03_get_and_post.py
@@ -9,6 +9,7 @@ import cherrypy
class WelcomePage:
+ @cherrypy.expose
def index(self):
# Ask for the user's name.
return '''
@@ -17,8 +18,8 @@ class WelcomePage:
<input type="text" name="name" />
<input type="submit" />
</form>'''
- index.exposed = True
+ @cherrypy.expose
def greetUser(self, name=None):
# CherryPy passes all GET and POST variables as method parameters.
# It doesn't make a difference where the variables come from, how
@@ -37,7 +38,6 @@ class WelcomePage:
return 'Please enter your name <a href="./">here</a>.'
else:
return 'No, really, enter your name <a href="./">here</a>.'
- greetUser.exposed = True
import os.path
diff --git a/cherrypy/tutorial/tut04_complex_site.py b/cherrypy/tutorial/tut04_complex_site.py
index e0660024..73528cd7 100644
--- a/cherrypy/tutorial/tut04_complex_site.py
+++ b/cherrypy/tutorial/tut04_complex_site.py
@@ -10,6 +10,7 @@ import cherrypy
class HomePage:
+ @cherrypy.expose
def index(self):
return '''
<p>Hi, this is the home page! Check out the other
@@ -19,17 +20,16 @@ class HomePage:
<li><a href="/joke/">A silly joke</a></li>
<li><a href="/links/">Useful links</a></li>
</ul>'''
- index.exposed = True
class JokePage:
+ @cherrypy.expose
def index(self):
return '''
<p>"In Python, how do you create a string of random
characters?" -- "Read a Perl file!"</p>
<p>[<a href="../">Return</a>]</p>'''
- index.exposed = True
class LinksPage:
@@ -40,6 +40,7 @@ class LinksPage:
# methods!
self.extra = ExtraLinksPage()
+ @cherrypy.expose
def index(self):
# Note the way we link to the extra links page (and back).
# As you can see, this object doesn't really care about its
@@ -62,11 +63,11 @@ class LinksPage:
<p>[<a href="../">Return</a>]</p>
'''
- index.exposed = True
class ExtraLinksPage:
+ @cherrypy.expose
def index(self):
# Note the relative link back to the Links page!
return '''
@@ -78,7 +79,6 @@ class ExtraLinksPage:
</ul>
<p>[<a href="../">Return to links page</a>]</p>'''
- index.exposed = True
# Of course we can also mount request handler objects right here!
diff --git a/cherrypy/tutorial/tut05_derived_objects.py b/cherrypy/tutorial/tut05_derived_objects.py
index 9f4f2c32..3e845308 100644
--- a/cherrypy/tutorial/tut05_derived_objects.py
+++ b/cherrypy/tutorial/tut05_derived_objects.py
@@ -45,6 +45,7 @@ class HomePage(Page):
# create a subpage
self.another = AnotherPage()
+ @cherrypy.expose
def index(self):
# Note that we call the header and footer methods inherited
# from the Page class!
@@ -54,19 +55,18 @@ class HomePage(Page):
<a href="./another/">another page</a>, too!
</p>
''' + self.footer()
- index.exposed = True
class AnotherPage(Page):
title = 'Another Page'
+ @cherrypy.expose
def index(self):
return self.header() + '''
<p>
And this is the amazing second page!
</p>
''' + self.footer()
- index.exposed = True
import os.path
diff --git a/cherrypy/tutorial/tut06_default_method.py b/cherrypy/tutorial/tut06_default_method.py
index f71c315a..8e2c8e31 100644
--- a/cherrypy/tutorial/tut06_default_method.py
+++ b/cherrypy/tutorial/tut06_default_method.py
@@ -21,6 +21,7 @@ import cherrypy
class UsersPage:
+ @cherrypy.expose
def index(self):
# Since this is just a stupid little example, we'll simply
# display a list of links to random, made-up users. In a real
@@ -30,8 +31,8 @@ class UsersPage:
<a href="./hendrik">Hendrik Mans</a><br/>
<a href="./lorenzo">Lorenzo Lamas</a><br/>
'''
- index.exposed = True
+ @cherrypy.expose
def default(self, user):
# Here we react depending on the virtualPath -- the part of the
# path that could not be mapped to an object method. In a real
@@ -47,7 +48,6 @@ class UsersPage:
out = "Unknown user. :-("
return '%s (<a href="./">back</a>)' % out
- default.exposed = True
import os.path
diff --git a/cherrypy/tutorial/tut07_sessions.py b/cherrypy/tutorial/tut07_sessions.py
index 62efa440..1dae7138 100644
--- a/cherrypy/tutorial/tut07_sessions.py
+++ b/cherrypy/tutorial/tut07_sessions.py
@@ -15,6 +15,7 @@ class HitCounter:
_cp_config = {'tools.sessions.on': True}
+ @cherrypy.expose
def index(self):
# Increase the silly hit counter
count = cherrypy.session.get('count', 0) + 1
@@ -27,7 +28,6 @@ class HitCounter:
During your current session, you've viewed this
page %s times! Your life is a patio of fun!
''' % count
- index.exposed = True
import os.path
diff --git a/cherrypy/tutorial/tut08_generators_and_yield.py b/cherrypy/tutorial/tut08_generators_and_yield.py
index 40566e32..48c4e079 100644
--- a/cherrypy/tutorial/tut08_generators_and_yield.py
+++ b/cherrypy/tutorial/tut08_generators_and_yield.py
@@ -18,6 +18,7 @@ class GeneratorDemo:
def footer(self):
return "</body></html>"
+ @cherrypy.expose
def index(self):
# Let's make up a list of users for presentation purposes
users = ['Remi', 'Carlos', 'Hendrik', 'Lorenzo Lamas']
@@ -30,7 +31,6 @@ class GeneratorDemo:
yield "%s<br/>" % user
yield self.footer()
- index.exposed = True
import os.path
diff --git a/cherrypy/tutorial/tut09_files.py b/cherrypy/tutorial/tut09_files.py
index 6a7b4a34..a0693487 100644
--- a/cherrypy/tutorial/tut09_files.py
+++ b/cherrypy/tutorial/tut09_files.py
@@ -50,6 +50,7 @@ from cherrypy.lib import static
class FileDemo(object):
+ @cherrypy.expose
def index(self):
return """
<html><body>
@@ -62,8 +63,8 @@ class FileDemo(object):
<a href='download'>This one</a>
</body></html>
"""
- index.exposed = True
+ @cherrypy.expose
def upload(self, myFile):
out = """<html>
<body>
@@ -85,13 +86,12 @@ class FileDemo(object):
size += len(data)
return out % (size, myFile.filename, myFile.content_type)
- upload.exposed = True
+ @cherrypy.expose
def download(self):
path = os.path.join(absDir, "pdf_file.pdf")
return static.serve_file(path, "application/x-download",
"attachment", os.path.basename(path))
- download.exposed = True
import os.path
diff --git a/cherrypy/tutorial/tut10_http_errors.py b/cherrypy/tutorial/tut10_http_errors.py
index c0e9893b..4bd3b241 100644
--- a/cherrypy/tutorial/tut10_http_errors.py
+++ b/cherrypy/tutorial/tut10_http_errors.py
@@ -21,6 +21,7 @@ class HTTPErrorDemo(object):
_cp_config = {'error_page.403':
os.path.join(curpath, "custom_error.html")}
+ @cherrypy.expose
def index(self):
# display some links that will result in errors
tracebacks = cherrypy.request.show_tracebacks
@@ -49,8 +50,8 @@ class HTTPErrorDemo(object):
when you raise an error.</a></p>
</body></html>
""" % trace
- index.exposed = True
+ @cherrypy.expose
def toggleTracebacks(self):
# simple function to toggle tracebacks on and off
tracebacks = cherrypy.request.show_tracebacks
@@ -58,19 +59,18 @@ class HTTPErrorDemo(object):
# redirect back to the index
raise cherrypy.HTTPRedirect('/')
- toggleTracebacks.exposed = True
+ @cherrypy.expose
def error(self, code):
# raise an error based on the get query
raise cherrypy.HTTPError(status=code)
- error.exposed = True
+ @cherrypy.expose
def messageArg(self):
message = ("If you construct an HTTPError with a 'message' "
"argument, it wil be placed on the error page "
"(underneath the status line by default).")
raise cherrypy.HTTPError(500, message=message)
- messageArg.exposed = True
import os.path