diff options
author | Andrey Zelenkov <zelenkov@nginx.com> | 2018-04-02 17:03:41 +0300 |
---|---|---|
committer | Andrey Zelenkov <zelenkov@nginx.com> | 2018-04-02 17:03:41 +0300 |
commit | efb71121b98c4dfded212e8b6fe33873cfd83376 (patch) | |
tree | 409023ef2fa8b7fe34b70a92bf04af7de9cc625f /test/python/ctx_iter_atexit/wsgi.py | |
parent | 001af5112275fcee1061fa8c1bc776a61b366712 (diff) | |
download | unit-efb71121b98c4dfded212e8b6fe33873cfd83376.tar.gz unit-efb71121b98c4dfded212e8b6fe33873cfd83376.tar.bz2 |
Tests: added Python test with iterator context.
Diffstat (limited to 'test/python/ctx_iter_atexit/wsgi.py')
-rw-r--r-- | test/python/ctx_iter_atexit/wsgi.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/python/ctx_iter_atexit/wsgi.py b/test/python/ctx_iter_atexit/wsgi.py new file mode 100644 index 00000000..d0b33daa --- /dev/null +++ b/test/python/ctx_iter_atexit/wsgi.py @@ -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') + ]) |