Sat Jun 20 20:44:03 2009 +0900
profiling for web application
1 import web
2 import fapws._evwsgi as evwsgi
3 from fapws import base
6 DBPATH = '/var/www/app/hello/hello.sqlite'
7 TEMPLATE_PATH = '/var/www/templates/'
9 urls = (
10 '/', 'index',
11 '/(.*)', 'hello',
12 )
14 render = web.template.render(TEMPLATE_PATH)
15 application = web.application(urls, globals()).wsgifunc()
16 db = web.database(dbn='sqlite', db=DBPATH)
18 class hello:
19 def GET(self, username):
20 users = db.select('hellouser', where="name = '%s'" % username)
21 isFound = False
22 for u in users:
23 if u.name == username:
24 isFound = True
25 if not isFound:
26 db.query("INSERT INTO hellouser (name) VALUES ('%s')" % username)
27 return render.hello(username, isFound)
29 class index:
30 def GET(self):
31 return "Hello web.py"
33 class HelloDebugMiddleware:
34 def __init__(self, application):
35 self.application = application
36 def __call__(self, env, start_response):
37 web.debug("Hello Debug!")
38 return self.application(env, start_response)
40 if __name__ == '__main__':
41 application = web.application(urls, globals()).wsgifunc()
42 application = HelloDebugMiddleware(application)
43 evwsgi.start("0.0.0.0", 8080)
44 evwsgi.set_base_module(base)
45 evwsgi.wsgi_cb(("", application))
46 evwsgi.run()