web/code-webpyorg-hotshotline.wsgi

Sat Jun 20 20:44:03 2009 +0900

author
hattori@www.hexacosa.net
date
Sat Jun 20 20:44:03 2009 +0900
changeset 6
c6da061b21c4
permissions
-rwxr-xr-x

profiling for web application

hattori@6 1 import os
hattori@6 2 import sqlite3
hattori@6 3 import web
hattori@6 4 import fapws._evwsgi as evwsgi
hattori@6 5 from fapws import base
hattori@6 6
hattori@6 7
hattori@6 8 DBPATH = '/var/www/app/hello/hello.sqlite'
hattori@6 9 TEMPLATE_PATH = '/var/www/templates/'
hattori@6 10
hattori@6 11 urls = (
hattori@6 12 '/', 'index',
hattori@6 13 '/(.*)', 'hello',
hattori@6 14 )
hattori@6 15
hattori@6 16 render = web.template.render(TEMPLATE_PATH)
hattori@6 17 application = web.application(urls, globals()).wsgifunc()
hattori@6 18 db = web.database(dbn='sqlite', db=DBPATH)
hattori@6 19
hattori@6 20 class hello:
hattori@6 21 def GET(self, username):
hattori@6 22 users = db.select('hellouser', where="name = '%s'" % username)
hattori@6 23 isFound = False
hattori@6 24 for u in users:
hattori@6 25 if u.name == username:
hattori@6 26 isFound = True
hattori@6 27 if not isFound:
hattori@6 28 db.query("INSERT INTO hellouser (name) VALUES ('%s')" % username)
hattori@6 29 return render.hello(username, isFound)
hattori@6 30
hattori@6 31 class index:
hattori@6 32 def GET(self):
hattori@6 33 return "Hello web.py"
hattori@6 34
hattori@6 35 if __name__ == '__main__':
hattori@6 36 import hotshot
hattori@6 37 application = web.application(urls, globals())
hattori@6 38 prof = hotshot.Profile('hotshot.prof', True)
hattori@6 39 prof.runcall(application.run)
hattori@6 40 prof.close()
hattori@6 41

mercurial