annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
bf4c763b0313 correct import
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
1 from middleware import Tagger
0
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 from paste.httpexceptions import HTTPExceptionHandler
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 from paste.urlparser import StaticURLParser
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 from pkg_resources import resource_filename
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5
18
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
6 class BogusAuth(object):
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
7 """
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
8 a bogus authenticator class
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
9 """
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
10
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
11 def __init__(self, app, user):
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
12 self.app = app
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
13 self.user = user
0
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14
18
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
15 def call(self, environ, start_response):
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
16 environ['REMOTE_USER'] = self.user
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
17 return self.app(environ, start_response)
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
18
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
19 def factory(global_conf, **app_conf):
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
20 """create an example view and wrap it in tagging middleware"""
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
21
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
22 keystr = 'tags.'
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
23 args = dict([(key.split(keystr, 1)[-1], value)
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
24 for key, value in app_conf.items()
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
25 if key.startswith(keystr) ])
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
26 app = StaticURLParser(app_conf['directory'])
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
27 tagger = Tagger(app, **args)
3bf478cb3166 make a BogusAuth class for testing purposes
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
28 return HTTPExceptionHandler(BogusAuth(tagger, 'foo'))
0
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29