4lFbZsTpPGA9N9niyOt9PF changeset

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