Mercurial > hg > bitsyauth
annotate example/persona.py @ 27:b411066b4929
example/persona.py
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 26 Dec 2013 22:43:24 -0800 |
parents | feeb97e8c23c |
children | 0bf52646061b |
rev | line source |
---|---|
23
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 """ |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 test Mozilla persona auth |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 https://login.persona.org/about |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 """ |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 |
25 | 9 import optparse |
10 import os | |
11 import sys | |
12 from wsgiref import simple_server | |
13 | |
23
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
14 here = os.path.dirname(os.path.realpath(__file__)) |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 page = os.path.join(here, 'persona.html') |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
16 |
25 | 17 class PersonaTest(object): |
27 | 18 def __init__(self, page=page): |
19 self.page = page | |
26 | 20 assert os.path.exists(self.page), "File '%s' not found" % self.page |
21 self.page = open(self.page, 'r').read() | |
22 def __call__(self, environ, start_response): | |
27 | 23 start_response("200 OK", [('Content-Type', 'text/html'), |
24 ('Content-Length', str(len(self.page)))]) | |
25 return [self.page] | |
25 | 26 |
23
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
27 def main(args=sys.argv[1:]): |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
28 |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
29 usage = '%prog [options]' |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
30 parser = optparse.OptionParser(usage=usage, description=__doc__) |
24 | 31 parser.add_option('-p', '--port', dest='port', |
32 type='int', default=8123, | |
33 help="port to serve on") | |
23
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
34 options, args = parser.parse_args(args) |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
35 |
27 | 36 app = PersonaTest() |
37 | |
25 | 38 server = simple_server.make_server('127.0.0.1', options.port, app) |
27 | 39 print 'server on\nhttp://localhost:%d/' % options.port |
25 | 40 try: |
41 server.serve_forever() | |
42 except KeyboardInterrupt: | |
43 pass | |
24 | 44 |
23
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
45 if __name__ == '__main__': |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
46 main() |