diff options
Diffstat (limited to 'cherrypy/tutorial/tut09_files.py')
| -rw-r--r-- | cherrypy/tutorial/tut09_files.py | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/cherrypy/tutorial/tut09_files.py b/cherrypy/tutorial/tut09_files.py index 6a7b4a34..48585cbe 100644 --- a/cherrypy/tutorial/tut09_files.py +++ b/cherrypy/tutorial/tut09_files.py @@ -41,15 +41,18 @@ popular browsers. """ import os -localDir = os.path.dirname(__file__) -absDir = os.path.join(os.getcwd(), localDir) +import os.path import cherrypy from cherrypy.lib import static +localDir = os.path.dirname(__file__) +absDir = os.path.join(os.getcwd(), localDir) + class FileDemo(object): + @cherrypy.expose def index(self): return """ <html><body> @@ -62,8 +65,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,16 +88,14 @@ 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 + path = os.path.join(absDir, 'pdf_file.pdf') + return static.serve_file(path, 'application/x-download', + 'attachment', os.path.basename(path)) -import os.path tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf') if __name__ == '__main__': @@ -102,6 +103,3 @@ if __name__ == '__main__': # 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) |
