/opt/imh-python/lib/python3.9/site-packages/cherrypy/tutorial
NameSizeModeActions
__pycache__/-0755rm
custom_error.html4040644editdlrm
pdf_file.pdf856980644editdlrm
README.rst6170644editdlrm
tut01_helloworld.py10150644editdlrm
tut02_expose_methods.py8010644editdlrm
tut03_get_and_post.py15870644editdlrm
tut04_complex_site.py29480644editdlrm
tut05_derived_objects.py21410644editdlrm
tut06_default_method.py22640644editdlrm
tut07_sessions.py12280644editdlrm
tut08_generators_and_yield.py12880644editdlrm
tut09_files.py34630644editdlrm
tut10_http_errors.py27060644editdlrm
tutorial.conf960644editdlrm
__init__.py850644editdlrm
Edit: /opt/imh-python/lib/python3.9/site-packages/cherrypy/tutorial/tut06_default_method.py (2264B)
""" Tutorial - The default method Request handler objects can implement a method called "default" that is called when no other suitable method/object could be found. Essentially, if CherryPy2 can't find a matching request handler object for the given request URI, it will use the default method of the object located deepest on the URI path. Using this mechanism you can easily simulate virtual URI structures by parsing the extra URI string, which you can access through cherrypy.request.virtualPath. The application in this tutorial simulates an URI structure looking like /users/. Since the bit will not be found (as there are no matching methods), it is handled by the default method. """ import os.path 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 # application, this could be generated from a database result set. return ''' Remi Delon
Hendrik Mans
Lorenzo Lamas
''' @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 # application, we would probably do some database lookups here # instead of the silly if/elif/else construct. if user == 'remi': out = 'Remi Delon, CherryPy lead developer' elif user == 'hendrik': out = 'Hendrik Mans, CherryPy co-developer & crazy German' elif user == 'lorenzo': out = 'Lorenzo Lamas, famous actor and singer!' else: out = 'Unknown user. :-(' return '%s (back)' % out tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf') if __name__ == '__main__': # 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)