WSGIマイクロフレームワーク
WSGI!

from wsgiref.simple_server import make_server, demo_app

httpd = make_server('', 8000, demo_app)
print "Serving HTTP on port 8000..."

httpd.serve_forever()
WebOb

@wsgify
def application(request):
  return Response('Hello')




http://docs.webob.org
Mako

import os
from mako.lookup import TemplateLookup

here = os.path.dirname(__file__)
templates = TemplateLookup(directories=[os.path.join(here,
'templates')])

tmpl = templates.get_template('index.mak')
tmpl.render(request=request)


http://www.makotemplates.org/
Routes

class Dispatcher(object):
   def __init__(self):
     self.mapper = Mapper()
     self.controllers = {}

  def add_route(self, route_name, pattern, controller):
    self.mapper.connect(route_name, pattern)
    self.controllers[route_name] = controller
Routes


  @wsgify
  def __call__(self, request):
    matched = self.mapper.routematch(request.path_info,
request.method)
    if not matched:
        raise HTTPNotFound
    matchdict, route = matched
    if route.name not in self.controllers:
        raise HTTPNotFound
    request.routes = self.mapper._routenames
    return self.controllers[route.name](request)
Routes

application = Dispatcher()
application.add_route('index', '/', index)
application.add_route('hello', '/hello', hello)




http://routes.groovie.org/
FormEncode Schema

class HelloSchema(formencode.Schema):
   name = validators.UnicodeString(not_empty=True)
FormEncode htmlfill

def hello(request):
   try:
      params = HelloSchema.to_python(request.params)
   except formencode.Invalid, e:
      res = index(request)
      res.text = htmlfill.render(res.body, request.params,
errors=e.error_dict)
      return res



http://formencode.org/
putting all together

https://gist.github.com/1175051

フレームワークなしでWSGIプログラミング