Tests: added Python test with iterator context.

This commit is contained in:
Andrey Zelenkov
2018-04-02 17:03:41 +03:00
parent 001af51122
commit efb71121b9
2 changed files with 46 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
import atexit
class application:
def __init__(self, environ, start_response):
self.environ = environ
self.start = start_response
def __iter__(self):
atexit.register(self._atexit)
content_length = int(self.environ.get('CONTENT_LENGTH', 0))
body = bytes(self.environ['wsgi.input'].read(content_length))
self.start('200', [
('Content-Type', self.environ.get('CONTENT_TYPE')),
('Content-Length', str(len(body)))
])
yield body
def _atexit(self):
self.start('200', [
('Content-Length', '0')
])