def run_wsgi(self):
        headers_set = []
        headers_sent = []

        def write(data):
            if not headers_set:
                raise AssertionError("write() before start_response()")
            elif not headers_sent:
                # Before the first output, send the stored headers
                buf = []
                status, response_headers = headers_sent[:] = headers_set
                code, _, msg = status.partition(' ')
                buf.append(wsgi_to_bytes((self.protocol_version, int(code), msg) % '%s %d %s\r\n'))
                header_keys = set()
                for key, value in response_headers:
                    buf.append(wsgi_to_bytes('%s: %s\r\n' % (key, value)))
                    header_keys.add(key.lower())
                if 'content-length' not in header_keys:
                    self.close_connection = True
                if 'server' not in header_keys:
                    buf.append(wsgi_to_bytes('Server: uvwsgi/%s\r\n' % __version__))
                if 'date' not in header_keys:
                    buf.append(wsgi_to_bytes('Date: %s\r\n' % date_time_string()))
                buf.append(b'\r\n')
                self.connection.write(b''.join(buf))

            assert type(data) is bytes, 'applications must write bytes'
            self.connection.write(data)

        def start_response(status, response_headers, exc_info=None):
            if exc_info:
                try:
                    if headers_sent:
                        reraise(*exc_info)
                finally:
                    exc_info = None
            elif headers_set:
                raise AssertionError("Headers already set!")

            headers_set[:] = [status, response_headers]
            # TODO: check hop by hop headers here?
            return write

        # Prepare WSGI environment
        env = self.connection.parser.get_wsgi_environ()
        env['wsgi.version'] = (1, 0)
        env['wsgi.url_scheme'] = 'http'
        env['wsgi.input'] = self.body
        env['wsgi.errors'] = ErrorStream(logger)
        env['wsgi.multithread'] = False
        env['wsgi.multiprocess'] = False
        env['wsgi.run_once'] = False

        # Run WSGI application
        app = self.connection.server.app
        try:
            app_response = app(env, start_response)
        except Exception:
            logger.exception('Running WSGI application')
            if DEBUG:
                response_body = traceback.format_exc()
                response_headers = [('Content-Type', 'text/plain'),
                                    ('Content-Length', str(len(response_body)))]
                start_response('500 Internal Server Error', response_headers, exc_info=sys.exc_info())
                app_response = [response_body]
            else:
                self.connection.finish()
                return
        try:
            for data in app_response:
                write(data)
            if not headers_sent:
                write(b'')
        except Exception:
            logger.exception('Running WSGI application')
        finally:
            if hasattr(app_response, 'close'):
                app_response.close()
        self.end()
        if DEBUG:
            status = headers_set[0]
            self._log(int(status.split()[0]))
dataset/ETHPy150Open saghul/uvwsgi/uvwsgi.py/HTTPRequest.run_wsgi/swapped operands of `%`