view examples/webpy/hello.py @ 634:2910e2532a60 trunk

Performance optimization for the `genshi.core._ensure` function: instead of checking whether we're dealing with a markup event stream for every item in the iterable, we now check only the first item, and treat the rest of the iterable depending on whether the first one looks like an event.
author cmlenz
date Wed, 05 Sep 2007 12:45:04 +0000
parents e72bd8515dd2
children
line wrap: on
line source
import os
from genshi.template import TemplateLoader
import web

loader = TemplateLoader([os.path.dirname(os.path.abspath(__file__))],
                        auto_reload=True)
urls = ('/(.*)', 'hello')


class hello(object):

    def GET(self, name):
        i = web.input(times=1)
        if not name:
            name = 'world'
        name = name.decode('utf-8')

        tmpl = loader.load('hello.html')
        stream = tmpl.generate(name=name, times=int(i.times))

        web.header('Content-Type', 'text/html; charset=utf-8', unique=True)
        print stream.render('html')


if __name__ == '__main__':
    web.webapi.internalerror = web.debugerror
    web.run(urls, globals())
Copyright (C) 2012-2017 Edgewall Software