diff options
author | Andrei Zeliankou <zelenkov@nginx.com> | 2019-11-14 18:46:28 +0300 |
---|---|---|
committer | Andrei Zeliankou <zelenkov@nginx.com> | 2019-11-14 18:46:28 +0300 |
commit | 1072c9482998fd698bc400953e0db9fe2c6b75f2 (patch) | |
tree | 639673b2e92cc19ca21e58bb55fec5e2d7ebd398 /test/python/iter_exception | |
parent | c2976fb3378b015b7c70247e0d462c1b52214458 (diff) | |
download | unit-1072c9482998fd698bc400953e0db9fe2c6b75f2.tar.gz unit-1072c9482998fd698bc400953e0db9fe2c6b75f2.tar.bz2 |
Tests: Python exception tests.
Diffstat (limited to '')
-rw-r--r-- | test/python/iter_exception/wsgi.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/python/iter_exception/wsgi.py b/test/python/iter_exception/wsgi.py new file mode 100644 index 00000000..66a09af7 --- /dev/null +++ b/test/python/iter_exception/wsgi.py @@ -0,0 +1,45 @@ +class application: + def __init__(self, environ, start_response): + self.environ = environ + self.start = start_response + + self.next = self.__next__ + + def __iter__(self): + self.__i = 0 + self._skip_level = int(self.environ.get('HTTP_X_SKIP', 0)) + self._not_skip_close = int(self.environ.get('HTTP_X_NOT_SKIP_CLOSE', 0)) + self._is_chunked = self.environ.get('HTTP_X_CHUNKED') + + headers = [(('Content-Length', '10'))] + if self._is_chunked is not None: + headers = [] + + if self._skip_level < 1: + raise Exception('first exception') + + write = self.start('200', headers) + + if self._skip_level < 2: + raise Exception('second exception') + + write(b'XXXXX') + + if self._skip_level < 3: + raise Exception('third exception') + + return self + + def __next__(self): + if self._skip_level < 4: + raise Exception('next exception') + + self.__i += 1 + if self.__i > 2: + raise StopIteration + + return b'X' + + def close(self): + if self._not_skip_close == 1: + raise Exception('close exception') |