xref: /unit/test/python/ctx_iter_atexit/wsgi.py (revision 1848:4bd548074e2c)
1import atexit
2
3
4class application:
5    def __init__(self, environ, start_response):
6        self.environ = environ
7        self.start = start_response
8
9    def __iter__(self):
10        atexit.register(self._atexit)
11
12        content_length = int(self.environ.get('CONTENT_LENGTH', 0))
13        body = bytes(self.environ['wsgi.input'].read(content_length))
14
15        self.start(
16            '200',
17            [
18                ('Content-Type', self.environ.get('CONTENT_TYPE')),
19                ('Content-Length', str(len(body))),
20            ],
21        )
22        yield body
23
24    def _atexit(self):
25        self.start('200', [('Content-Length', '0')])
26