forked from chiho924/PyWeb-04
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemefacter.py
More file actions
47 lines (41 loc) · 1.39 KB
/
memefacter.py
File metadata and controls
47 lines (41 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
A Mashup that takes "facts" from http://www.unkno.com/ and adds them
to memes using https://imgflip.com/memegenerator
This base code is a copy of our initial pseudo calculator code; we will
modify it to our purpose.
"""
def resolve_path(path):
"""
Should return two values: a callable and an iterable of
arguments, based on the path.
"""
# TODO: Provide correct values for func and args. The
# examples provide the correct *syntax*, but you should
# determine the actual values of func and args using the
# path.
func = some_func
args = ['25', '32']
return func, args
def application(environ, start_response):
headers = [('Content-type', 'text/html')]
try:
path = environ.get('PATH_INFO', None)
if path is None:
raise NameError
func, args = resolve_path(path)
body = func(*args)
status = "200 OK"
except NameError:
status = "404 Not Found"
body = "<h1>Not Found</h1>"
except Exception:
status = "500 Internal Server Error"
body = "<h1> Internal Server Error</h1>"
finally:
headers.append(('Content-length', str(len(body))))
start_response(status, headers)
return [body.encode('utf8')]
if __name__ == '__main__':
from wsgiref.simple_server import make_server
srv = make_server('localhost', 8080, application)
srv.serve_forever()