a | b | |
---|
| 0 | + | def my_awesome_application(environ): |
---|
| 0 | + | # do stuff |
---|
| 0 | + | return b'200 OK', [], ["Hello, World!"] |
---|
| 0 | + | |
---|
| 0 | + | def my_middelware(app): |
---|
| 0 | + | def wrapper(environ): |
---|
| 0 | + | # maybe edit environ |
---|
| 0 | + | try: |
---|
| 0 | + | status, headers, body = app(environ) |
---|
| 0 | + | # maybe edit response: |
---|
| 0 | + | # body = (piglatin(data) for data in body) |
---|
| 0 | + | return status, headers, body |
---|
| 0 | + | except: |
---|
| 0 | + | # maybe handle error |
---|
| 0 | + | finally: |
---|
| 0 | + | # maybe release resources |
---|
| 0 | + | |
---|
| 0 | + | def my_server(app, httpreq): |
---|
| 0 | + | environ = wsgi.make_environ(httpreq) |
---|
| 0 | + | try: |
---|
| 0 | + | status, headers, body = app(environ) |
---|
| 0 | + | write_headers(httpreq, status, headers) |
---|
| 0 | + | for data in body: |
---|
| 0 | + | write_data(httpreq, data) |
---|
| 0 | + | except: |
---|
| 0 | + | respond_with_500() |
---|
... | |
---|