import werkzeug
from werkzeug.wrappers import Request, Response
from werkzeug.utils import redirect
import logging; log = logging.getLogger('pvl.verkko.wsgi')
from pvl.verkko import db as database, web, hosts
class Application (object) :
def __init__ (self, db) :
"""
Initialize app with db.
"""
self.db = database.Database(db)
@Request.application
def __call__ (self, request) :
"""
WSGI entry point, werkzeug Request -> Response
"""
# path?
path = request.path.strip('/')
if path :
path = path.split('/')
else :
path = []
log.debug("path: %s", path)
# lookup handler/respond
if not path :
handler = web.Index
elif path[0] == 'hosts' :
handler = hosts.Handler
path.pop(0)
else :
return Response("Not Found", status=404)
return handler(self, request, path).respond()