Revision 376330313937 () - Diff

Link to this snippet: https://friendpaste.com/4lFbZsTpPGA9N9niyOt9PF
Embed:
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
def my_awesome_application(environ):
# do stuff
yield b'200 OK', [], ["Hello, World!"]

def my_middelware(app):
def wrapper(environ):
# maybe edit environ
try:
status, headers, body = yield app(environ)
# maybe edit response:
# body = (piglatin(data) for data in body)
return status, headers, body
except:
# maybe handle error
finally:
# maybe release resources

def my_server(app, httpreq):
environ = wsgi.make_environ(httpreq)

def process_response(result):
status, headers, body = result
write_headers(httpreq, status, headers)
Coroutine(body, body_trampoline, finish_response)

def finish_response(result):
# cleanup, if any

Coroutine(app(environ), app_trampoline, process_response)