pvl/verkko/wsgi.py
author Tero Marttila <terom@paivola.fi>
Wed, 10 Oct 2012 22:45:50 +0300
changeset 3 5990b188c54b
parent 2 b0659c867226
child 4 b09436772d46
permissions -rw-r--r--
web.Handler
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()