Wrap a WSGI application so that cleaning up happens after
        request end.
428263
def make_middleware(self, app):
        

        def application(environ, start_response):
            return ClosingIterator(app(environ, start_response), self.cleanup)

        return application
383585
def wrap_handler(cls, handler, protocol, **kwargs):
        '''  '''
        def _wrapper(request, *args, **kwargs):
            instance = cls(request=request, **kwargs)
            if protocol == Resource.Protocol.http:
                return instance._wrap_http(handler, request=request, **kwargs)
            elif protocol == Resource.Protocol.websocket:
                return instance._wrap_ws(handler, request=request, **kwargs)
            elif protocol == Resource.Protocol.amqp:
                return instance._wrap_amqp(view_type, *args, **kwargs)
            else:
                raise Exception('Communication protocol not specified')
        return _wrapper
717135
def clean(bundle, before, after, keep_last):
    
    bundles_module.clean(
        bundle,
        before,
        after,
        keep_last,
    )
854485
def strip_wsgi(request):
    """"""

    meta = copy(request.META)
    for key in meta:
        if key[:4] == 'wsgi':
            meta[key] = None
    return meta
1367758
def finish(self):
        """"""
        if self._finished:
            raise RuntimeError("finish() called twice.  May be caused "
                               "by using async operations without the "
                               "@asynchronous decorator.")
        if not hasattr(self, '_stream_queue') or not self._stream_queue:
            raise RuntimeError("`_stream_queue` was not assigned, you should"
                               "call `write_stream_queue` to set.")

        # === Replace `if not self._headers_written` === #
        self.set_status(200)
        self.set_header("Content-Type", "text/event-stream")
        self.set_header("Cache-Control", "no-cache")
        self.set_header("Access-Control-Allow-Origin", "*")
        # ============================================== #

        self.request.connection.set_close_callback(None)

        # === Add before self.flush === #
        # Reset buffer
        self._write_buffer = []
        self._headers_written = False
        # ============================= #

        self.flush(include_footers=True)

        # === Add after self.flush === #
        self._write_buffer = self._stream_queue
        self.request.connection._write_buffer = self._stream_queue
        # ============================ #

        self.request.finish()
        self._log()
        self._finished = True
        self.on_finish()
        # Break up a reference cycle between this handler and the
        # _ui_module closures to allow for faster GC on CPython.
        self.ui = None
642887
def handle_one_request(self):
        """"""
        self.raw_requestline = self.rfile.readline()
        if not self.raw_requestline:
            self.close_connection = 1
        elif self.parse_request():
            return self.run_wsgi()
1105280
function makeServeMiddleware(/* config */) {
  return function handle(req, resp, next) {
    if (/^\/.*\.css$/.test(req.url)) {
      resp.end("");
    }
    else {
      next();
    }
  };
}
1096494
public function cleanUpAfterError()
    {
        foreach ($this->request->files as $file) {
            $cacheFile = $this->generateCacheFile($file);
            unlink($cacheFile);
        }
    }
737495
def post_run(self, outline=False, dump=False, *args, **kwargs):
        """"""
        hooks = self.context.config.post_build
        handle_hooks(
            "post_build",
            hooks,
            self.provider,
            self.context,
            dump,
            outline
        )
872926
function cleanup (exitCode) {
  if(_disabled) {
    return q.resolve();
  }

  var defer = q.defer();

  _readRunIdFile().then(function (run) {
    _logMessage('test finished. Your results can be viewed at: ' +
      'http://' + _hostname + ':' + _port + '/#/' + run.project_id + '/' + run.suite_id + '/' + run.run_id + '/rp');
    fs.unlink(RUN_PID_FILE, function (err) {
      if (err) {
        defer.reject(err);
      } else {
        defer.resolve();
      }
    });
  });

  return defer.promise;
}
34289
def handle_one_request(self):
        """Copy of WSGIRequestHandler, but with different ServerHandler"""

        self.raw_requestline = self.rfile.readline(65537)
        if len(self.raw_requestline) > 65536:
            self.requestline = ''
            self.request_version = ''
            self.command = ''
            self.send_error(414)
            return

        if not self.parse_request():  # An error code has been sent, just exit
            return

        handler = ServerHandler(
            self.rfile, self.wfile, self.get_stderr(), self.get_environ()
        )
        handler.request_handler = self      # backpointer for logging
        handler.run(self.server.get_app())
1203680
def end_headers(self):
        """"""
        if self.request_version != 'HTTP/0.9':
            self._headers_buffer.append(b"\r\n")
            self.flush_headers()
1080741
def cleanup(self):
        """"""
        self.parser = None
        self.request = None
        self.url = None
        self.headers = None
        self._request_handler_task = None
        self._request_stream_task = None
        self._total_request_size = 0
        self._is_stream_handler = False
1250342
def cleanup(self):
        """"""
        if self.allow_disable_global:
            # Return paging state
            output_mode_cmd = "set output {}".format(self._output_mode)
            enable_paging_commands = ["config system console", output_mode_cmd, "end"]
            if self.vdoms:
                enable_paging_commands.insert(0, "config global")
            # Should test output is valid
            for command in enable_paging_commands:
                self.send_command_timing(command)
33651
def exec_after_request_actions(actions, response, **kwargs):
    
    current_context["response"] = response
    groups = ("after_" + flask.request.method.lower(), "after")
    try:
        rv = execute_actions(actions, limit_groups=groups, **kwargs)
    except ReturnValueException as e:
        rv = e.value
    if rv:
        return rv
    return response
1354014
def _server_end_response_callback(self, respoonse: Response):
        ''''''
        request = self._item_session.request
        response = self._item_session.response

        _logger.info(__(
            _('Fetched ‘{url}’: {status_code} {reason}. '
              'Length: {content_length} [{content_type}].'),
            url=request.url,
            status_code=response.status_code,
            reason=wpull.string.printable_str(response.reason),
            content_length=wpull.string.printable_str(
                response.fields.get('Content-Length', _('none'))),
            content_type=wpull.string.printable_str(
                response.fields.get('Content-Type', _('none'))),
        ))

        self._result_rule.handle_response(self._item_session)

        if response.status_code in WebProcessor.DOCUMENT_STATUS_CODES:
            filename = self._file_writer_session.save_document(response)
            self._processing_rule.scrape_document(self._item_session)
            self._result_rule.handle_document(self._item_session, filename)

        elif response.status_code in WebProcessor.NO_DOCUMENT_STATUS_CODES:
            self._file_writer_session.discard_document(response)
            self._result_rule.handle_no_document(self._item_session)
        else:
            self._file_writer_session.discard_document(response)
            self._result_rule.handle_document_error(self._item_session)
508687
@AfterStory(uponGivenStory = false)
  public void cleanUp() {
    LOG.debug("Cleaning up after story run.");
    Mocks.reset();
    support.undeploy();
    support.resetClock();
    ProcessEngineAssertions.reset();
  }