view taginthemiddle/example.py @ 19:57ca873ed9bf default tip

make this a pluggable system and start reorging infrastructure for that
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 25 May 2010 07:48:53 -0700
parents 3bf478cb3166
children
line wrap: on
line source

from middleware import Tagger
from paste.httpexceptions import HTTPExceptionHandler
from paste.urlparser import StaticURLParser
from pkg_resources import resource_filename

class BogusAuth(object):
  """
  a bogus authenticator class
  """

  def __init__(self, app, user):
    self.app = app
    self.user = user

  def call(self, environ, start_response):
    environ['REMOTE_USER'] = self.user
    return self.app(environ, start_response)

def factory(global_conf, **app_conf):
  """create an example view and wrap it in tagging middleware"""

  keystr = 'tags.'
  args = dict([(key.split(keystr, 1)[-1], value)
               for key, value in app_conf.items()
               if key.startswith(keystr) ])
  app = StaticURLParser(app_conf['directory'])
  tagger = Tagger(app, **args)
  return HTTPExceptionHandler(BogusAuth(tagger, 'foo'))