def __call__(self, environ, start_response):
        url = []

        def change_response(status, headers, exc_info=None):
            status_code = status.split(' ')
            try:
                code = int(status_code[0])
            except (ValueError, __HOLE__):
                raise Exception(
                    'StatusBasedForward middleware '
                    'received an invalid status code %s'%repr(status_code[0])
                )
            message = ' '.join(status_code[1:])
            new_url = self.mapper(
                code,
                message,
                environ,
                self.global_conf,
                **self.params
            )
            if not (new_url == None or isinstance(new_url, str)):
                raise TypeError(
                    'Expected the url to internally '
                    'redirect to in the StatusBasedForward mapper'
                    'to be a string or None, not %r' % new_url)
            if new_url:
                url.append([new_url, status, headers])
                # We have to allow the app to write stuff, even though
                # we'll ignore it:
                return [].append
            else:
                return start_response(status, headers, exc_info)

        app_iter = self.application(environ, change_response)
        if url:
            if hasattr(app_iter, 'close'):
                app_iter.close()

            def factory(app):
                return StatusKeeper(app, status=url[0][1], url=url[0][0],
                                    headers=url[0][2])
            raise ForwardRequestException(factory=factory)
        else:
            return app_iter
dataset/ETHPy150Open cloudera/hue/desktop/core/ext-py/Paste-2.0.1/paste/errordocument.py/StatusBasedForward.__call__