web/code-webpyorg.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@4 1 import os
hattori@4 2 import sqlite3
hattori@4 3 import web
hattori@4 4 import fapws._evwsgi as evwsgi
hattori@4 5 from fapws import base
hattori@4 6
hattori@4 7
hattori@4 8 DBPATH = '/var/www/app/hello/hello.sqlite'
hattori@4 9 TEMPLATE_PATH = '/var/www/templates/'
hattori@4 10
hattori@4 11 urls = (
hattori@4 12 '/', 'index',
hattori@4 13 '/(.*)', 'hello',
hattori@4 14 )
hattori@4 15
hattori@4 16 render = web.template.render(TEMPLATE_PATH)
hattori@4 17 application = web.application(urls, globals()).wsgifunc()
hattori@4 18 db = web.database(dbn='sqlite', db=DBPATH)
hattori@4 19
hattori@4 20 class hello:
hattori@4 21 def GET(self, username):
hattori@4 22 users = db.select('hellouser', where="name = '%s'" % username)
hattori@4 23 isFound = False
hattori@4 24 for u in users:
hattori@4 25 if u.name == username:
hattori@4 26 isFound = True
hattori@4 27 if not isFound:
hattori@4 28 db.query("INSERT INTO hellouser (name) VALUES ('%s')" % username)
hattori@4 29 return render.hello(username, isFound)
hattori@4 30
hattori@4 31 class index:
hattori@4 32 def GET(self):
hattori@4 33 return "Hello web.py"
hattori@4 34
hattori@4 35 if __name__ == '__main__':
hattori@4 36 if not os.path.exists(DBPATH):
hattori@4 37 d = sqlite3.connect(DBPATH)
hattori@4 38 c = d.cursor()
hattori@4 39 c.execute("create table hellouser (userid integer primary key autoincrement, \
hattori@4 40 name text)")
hattori@4 41 application = web.application(urls, globals())
hattori@4 42 application.run()
hattori@4 43

mercurial