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-Length', str(len(body))), 19 ], 20 ) 21 yield body 22 23 def _atexit(self): 24 self.start('200', [('Content-Length', '0')]) 25