web/code-webpyorg-lineprof.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 """
hattori@6 2
hattori@6 3 [usage] $ kernprof.py -l TARGET.py
hattori@6 4 $ python -m line_profiler TARGET.py.lprof
hattori@6 5 """
hattori@6 6
hattori@6 7 import web
hattori@6 8 import fapws._evwsgi as evwsgi
hattori@6 9 from fapws import base
hattori@6 10
hattori@6 11
hattori@6 12 DBPATH = '/var/www/app/hello/hello.sqlite'
hattori@6 13 TEMPLATE_PATH = '/var/www/templates/'
hattori@6 14
hattori@6 15 urls = (
hattori@6 16 '/', 'index',
hattori@6 17 '/(.*)', 'hello',
hattori@6 18 )
hattori@6 19
hattori@6 20 render = web.template.render(TEMPLATE_PATH)
hattori@6 21 application = web.application(urls, globals()).wsgifunc()
hattori@6 22 db = web.database(dbn='sqlite', db=DBPATH)
hattori@6 23
hattori@6 24 class hello:
hattori@6 25 @profile
hattori@6 26 def GET(self, username):
hattori@6 27 users = db.select('hellouser', where="name = '%s'" % username)
hattori@6 28 isFound = False
hattori@6 29 for u in users:
hattori@6 30 if u.name == username:
hattori@6 31 isFound = True
hattori@6 32 if not isFound:
hattori@6 33 db.query("INSERT INTO hellouser (name) VALUES ('%s')" % username)
hattori@6 34 return render.hello(username, isFound)
hattori@6 35
hattori@6 36 class index:
hattori@6 37 @profile
hattori@6 38 def GET(self):
hattori@6 39 return "Hello web.py"
hattori@6 40
hattori@6 41 if __name__ == '__main__':
hattori@6 42 application = web.application(urls, globals())
hattori@6 43 application.run()
hattori@6 44

mercurial