4lFbZsTpPGA9N9niyOt9PF changeset

Changeset376330313937 (b)
Parent386562363634 (a)
ab
00def my_awesome_application(environ):
11    # do stuff
...
2-    return b'200 OK', [], ["Hello, World!"]
2+    yield b'200 OK', [], ["Hello, World!"]
...
33
44def my_middelware(app):
55    def wrapper(environ):
66        # maybe edit environ
77        try:
...
8-            status, headers, body = app(environ)
8+            status, headers, body = yield app(environ)
...
99            # maybe edit response:
1010            # body = (piglatin(data) for data in body)
1111            return status, headers, body
...
1616
1717def my_server(app, httpreq):
1818    environ = wsgi.make_environ(httpreq)
...
19-    try:
19-        status, headers, body = app(environ)
19+
19+    def process_response(result):
19+        status, headers, body = result
...
2121        write_headers(httpreq, status, headers)
...
22-        for data in body:
22-            write_data(httpreq, data)
22-     except:
22-         respond_with_500()
22+        Coroutine(body, body_trampoline, finish_response)
22+
22+    def finish_response(result):
22+        # cleanup, if any
22+
22+    Coroutine(app(environ), app_trampoline, process_response)
...
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
--- Revision 386562363634
+++ Revision 376330313937
@@ -1,12 +1,12 @@
def my_awesome_application(environ):
# do stuff
- return b'200 OK', [], ["Hello, World!"]
+ yield b'200 OK', [], ["Hello, World!"]
def my_middelware(app):
def wrapper(environ):
# maybe edit environ
try:
- status, headers, body = app(environ)
+ status, headers, body = yield app(environ)
# maybe edit response:
# body = (piglatin(data) for data in body)
return status, headers, body
@@ -17,10 +17,13 @@
def my_server(app, httpreq):
environ = wsgi.make_environ(httpreq)
- try:
- status, headers, body = app(environ)
+
+ def process_response(result):
+ status, headers, body = result
write_headers(httpreq, status, headers)
- for data in body:
- write_data(httpreq, data)
- except:
- respond_with_500()
+ Coroutine(body, body_trampoline, finish_response)
+
+ def finish_response(result):
+ # cleanup, if any
+
+ Coroutine(app(environ), app_trampoline, process_response)