Mercurial > hg > bitsyauth
comparison example/persona.py @ 31:6af220013aa1
example/persona.py setup.py
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Fri, 27 Dec 2013 12:13:18 -0800 |
| parents | 0bf52646061b |
| children | 119cf9c81d3d |
comparison
equal
deleted
inserted
replaced
| 30:0bf52646061b | 31:6af220013aa1 |
|---|---|
| 20 assert os.path.exists(self.page), "File '%s' not found" % self.page | 20 assert os.path.exists(self.page), "File '%s' not found" % self.page |
| 21 self.page = open(self.page, 'r').read() | 21 self.page = open(self.page, 'r').read() |
| 22 def __call__(self, environ, start_response): | 22 def __call__(self, environ, start_response): |
| 23 method = environ['REQUEST_METHOD'] | 23 method = environ['REQUEST_METHOD'] |
| 24 if method == 'GET': | 24 if method == 'GET': |
| 25 start_response("200 OK", [('Content-Type', 'text/html'), | 25 content_type = 'text/html' |
| 26 ('Content-Length', str(len(self.page)))]) | |
| 27 body = self.page | 26 body = self.page |
| 28 elif method == 'POST': | 27 elif method == 'POST': |
| 29 body = '\n'.join([]) | 28 content_type = 'text/plain' |
| 29 body = '\n'.join(['%s: %s' % (key, environ[key]) | |
| 30 for key in sorted(environ.keys())]) | |
| 31 print body | |
| 32 else: | |
| 33 content_type = 'text/plain' | |
| 34 body = 'Try GET or POST to do something interesting (How did you get here?)' | |
| 35 start_response("200 OK", [('Content-Type', content_type), | |
| 36 ('Content-Length', str(len(body)))]) | |
| 30 return [body] | 37 return [body] |
| 31 | 38 |
| 32 def main(args=sys.argv[1:]): | 39 def main(args=sys.argv[1:]): |
| 33 | 40 |
| 34 usage = '%prog [options]' | 41 usage = '%prog [options]' |
