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

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

mercurial