/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/tut08_generators_and_yield.py (1288B)
""" Bonus Tutorial: Using generators to return result bodies Instead of returning a complete result string, you can use the yield statement to return one result part after another. This may be convenient in situations where using a template package like CherryPy or Cheetah would be overkill, and messy string concatenation too uncool. ;-) """ import os.path import cherrypy class GeneratorDemo: def header(self): return '

Generators rule!

' def footer(self): return '' @cherrypy.expose def index(self): # Let's make up a list of users for presentation purposes users = ['Remi', 'Carlos', 'Hendrik', 'Lorenzo Lamas'] # Every yield line adds one part to the total result body. yield self.header() yield '

List of users:

' for user in users: yield '%s
' % user yield self.footer() 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(GeneratorDemo(), config=tutconf)