# HG changeset patch # User Jeff Hammel # Date 1388203320 28800 # Node ID 8255e769828bf9ba38b42115862fde54d0a42172 # Parent 4dfffa966edd26facb8316e0db030d5ff1460fa7 example/wsgibrowserid_example.py example/wsgibrowserid.py diff -r 4dfffa966edd -r 8255e769828b example/wsgibrowserid.py --- a/example/wsgibrowserid.py Fri Dec 27 19:47:46 2013 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -#!/usr/bin/env python - -""" -test Mozilla persona auth via wsgibrowserid - -https://github.com/ianb/wsgibrowserid -""" - -import optparse -import os -import sys -from webob import Request, Response, exc -from wsgiref import simple_server - -here = os.path.dirname(os.path.realpath(__file__)) -page = os.path.join(here, 'wsgibrowserid.html') - -class PersonaTest(object): - def __init__(self, page=page): - self.page = page - assert os.path.exists(self.page), "File '%s' not found" % self.page - self.page = open(self.page, 'r').read() - def __call__(self, environ, start_response): - request = Request(environ) - method = request.method - if method == 'GET': - content_type = 'text/html' - body = self.page - elif method == 'POST': - content_type = 'text/plain' - assertion = request.POST.get('assertion') - print ("Assertion: %s" % assertion) - body = '\n'.join(['%s: %s' % (key, environ[key]) - for key in sorted(environ.keys())]) - else: - content_type = 'text/plain' - body = 'Try GET or POST to do something interesting (How did you get here?)' - start_response("200 OK", [('Content-Type', content_type), - ('Content-Length', str(len(body)))]) - return [body] - -def main(args=sys.argv[1:]): - - usage = '%prog [options]' - parser = optparse.OptionParser(usage=usage, description=__doc__) - parser.add_option('-p', '--port', dest='port', - type='int', default=8123, - help="port to serve on") - options, args = parser.parse_args(args) - - app = PersonaTest() - - server = simple_server.make_server('127.0.0.1', options.port, app) - print 'server on\nhttp://localhost:%d/' % options.port - try: - server.serve_forever() - except KeyboardInterrupt: - pass - -if __name__ == '__main__': - main() diff -r 4dfffa966edd -r 8255e769828b example/wsgibrowserid_example.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/wsgibrowserid_example.py Fri Dec 27 20:02:00 2013 -0800 @@ -0,0 +1,61 @@ +#!/usr/bin/env python + +""" +test Mozilla persona auth via wsgibrowserid + +https://github.com/ianb/wsgibrowserid +""" + +import optparse +import os +import sys +from webob import Request, Response, exc +from wsgiref import simple_server + +here = os.path.dirname(os.path.realpath(__file__)) +page = os.path.join(here, 'wsgibrowserid.html') + +class PersonaTest(object): + def __init__(self, page=page): + self.page = page + assert os.path.exists(self.page), "File '%s' not found" % self.page + self.page = open(self.page, 'r').read() + def __call__(self, environ, start_response): + request = Request(environ) + method = request.method + if method == 'GET': + content_type = 'text/html' + body = self.page + elif method == 'POST': + content_type = 'text/plain' + assertion = request.POST.get('assertion') + print ("Assertion: %s" % assertion) + body = '\n'.join(['%s: %s' % (key, environ[key]) + for key in sorted(environ.keys())]) + else: + content_type = 'text/plain' + body = 'Try GET or POST to do something interesting (How did you get here?)' + start_response("200 OK", [('Content-Type', content_type), + ('Content-Length', str(len(body)))]) + return [body] + +def main(args=sys.argv[1:]): + + usage = '%prog [options]' + parser = optparse.OptionParser(usage=usage, description=__doc__) + parser.add_option('-p', '--port', dest='port', + type='int', default=8123, + help="port to serve on") + options, args = parser.parse_args(args) + + app = PersonaTest() + + server = simple_server.make_server('127.0.0.1', options.port, app) + print 'server on\nhttp://localhost:%d/' % options.port + try: + server.serve_forever() + except KeyboardInterrupt: + pass + +if __name__ == '__main__': + main()