comparison example/persona.py @ 35:d95ac066cb62

example/persona.py
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 27 Dec 2013 13:45:10 -0800
parents 119cf9c81d3d
children afeb01315ab6
comparison
equal deleted inserted replaced
34:119cf9c81d3d 35:d95ac066cb62
19 def __init__(self, page=page): 19 def __init__(self, page=page):
20 self.page = page 20 self.page = page
21 assert os.path.exists(self.page), "File '%s' not found" % self.page 21 assert os.path.exists(self.page), "File '%s' not found" % self.page
22 self.page = open(self.page, 'r').read() 22 self.page = open(self.page, 'r').read()
23 def __call__(self, environ, start_response): 23 def __call__(self, environ, start_response):
24 method = environ['REQUEST_METHOD'] 24 request = Request(environ)
25 method = request.method
25 if method == 'GET': 26 if method == 'GET':
26 content_type = 'text/html' 27 content_type = 'text/html'
27 body = self.page 28 body = self.page
28 elif method == 'POST': 29 elif method == 'POST':
29 content_type = 'text/plain' 30 content_type = 'text/plain'
30 body = '\n'.join(['%s: %s' % (key, environ[key]) 31 body = '\n'.join(['%s: %s' % (key, environ[key])
31 for key in sorted(environ.keys())]) 32 for key in sorted(environ.keys())])
32 print body
33 else: 33 else:
34 content_type = 'text/plain' 34 content_type = 'text/plain'
35 body = 'Try GET or POST to do something interesting (How did you get here?)' 35 body = 'Try GET or POST to do something interesting (How did you get here?)'
36 start_response("200 OK", [('Content-Type', content_type), 36 start_response("200 OK", [('Content-Type', content_type),
37 ('Content-Length', str(len(body)))]) 37 ('Content-Length', str(len(body)))])