Mercurial > hg > bitsyauth
comparison example/example.py @ 16:52713d176ab9
add an example....not done yet
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 14 Dec 2010 09:36:44 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
15:431bd76aabb7 | 16:52713d176ab9 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 def example_app(environ, start_response): | |
4 if environ['PATH_INFO'].strip('/') == 'authorization_required': | |
5 user = environ.get('REMOTE_USER') | |
6 if user: | |
7 start_response("200 OK", [('Content-Type', 'text/plain'), | |
8 ('Content-Length', str(len(user)))]) | |
9 return [user] | |
10 else: | |
11 text = '401 Unauthorized' | |
12 start_response("401 Unauthorized", [('Content-Type', 'text/plain'), | |
13 ('Content-Length', str(len(text)))]) | |
14 return [text] | |
15 text = """<html><body> | |
16 <a href="/authorization_required">bet you can't go here!</a> | |
17 </body></html>""" | |
18 start_response("200 OK", [('Content-Type', 'text/html'), | |
19 ('Content-Length', str(len(text)))]) | |
20 return [text] | |
21 | |
22 if __name__ == '__main__': | |
23 from wsgiref import simple_server | |
24 server = simple_server.make_server('127.0.0.1', 12345, example_app) | |
25 server.serve_forever() |