comparison taginthemiddle/example.py @ 18:3bf478cb3166

make a BogusAuth class for testing purposes
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 24 May 2010 07:48:48 -0700
parents bf4c763b0313
children
comparison
equal deleted inserted replaced
17:c85d42296c06 18:3bf478cb3166
1 from middleware import Tagger 1 from middleware import Tagger
2 from paste.httpexceptions import HTTPExceptionHandler 2 from paste.httpexceptions import HTTPExceptionHandler
3 from paste.urlparser import StaticURLParser 3 from paste.urlparser import StaticURLParser
4 from pkg_resources import resource_filename 4 from pkg_resources import resource_filename
5 5
6 class BogusAuth(object):
7 """
8 a bogus authenticator class
9 """
10
11 def __init__(self, app, user):
12 self.app = app
13 self.user = user
14
15 def call(self, environ, start_response):
16 environ['REMOTE_USER'] = self.user
17 return self.app(environ, start_response)
18
6 def factory(global_conf, **app_conf): 19 def factory(global_conf, **app_conf):
7 """create an example view and wrap it in tagging middleware""" 20 """create an example view and wrap it in tagging middleware"""
8 21
9 keystr = 'TagInTheMiddle.' 22 keystr = 'tags.'
10 args = dict([(key.split(keystr, 1)[-1], value) 23 args = dict([(key.split(keystr, 1)[-1], value)
11 for key, value in app_conf.items() 24 for key, value in app_conf.items()
12 if key.startswith(keystr) ]) 25 if key.startswith(keystr) ])
13 app = StaticURLParser(app_conf['directory']) 26 app = StaticURLParser(app_conf['directory'])
14 tagger = Tagger(app, **args) 27 tagger = Tagger(app, **args)
15 return HTTPExceptionHandler(tagger) 28 return HTTPExceptionHandler(BogusAuth(tagger, 'foo'))
16 29