def __call__(self, request):
        """
        This function is called when a new request is received, and uses the
        method :meth:`Application.route_request` to select and execute the
        proper request handler, and then the method
        :meth:`Application.parse_output` to process the handler's output.
        """
        Application.current_app = self
        self.request = request

        try:
            request.auto_finish = True
            result = self.route_request(request)
            if request.auto_finish:
                self.parse_output(result)

        except Exception as err:
            # This should hopefully never happen, but it *could*.
            try:
                body, status, headers = self.handle_500(request, err)
            except Exception:
                # There's an error with our handle_500.
                log.exception("There was a problem handling a request, "
                              "and a problem running Application.handle_500 "
                              "for %r." % self)
                body, status, headers = error(500, request=request)

                # If an exception happens at *this* point, it's destined. Just
                # show the ugly page.

            if not headers in 'Content-Length':
                headers['Content-Length'] = len(body)

            request.send_status(status)
            request.send_headers(headers)
            request.write(body)
            request.finish()

        finally:
            if hasattr(request, '_hooks'):
                hks = request._hooks.get('request_teardown')
                if hks:
                    for hf in hks:
                        try:
                            hf(request)
                        except Exception as err:
                            # Log the exception, but continue.
                            log.exception("There was a problem handling a "
                                          "request teardown hook for: %r",
                                            request)

            if hasattr(request, '_converted_match'):
                del request._converted_match

            Application.current_app = None
            self.request = None
dataset/ETHPy150Open ecdavis/pants/pants/web/application.py/Application.__call__/swapped operands of `in`