예제 #1
0
    def raise_response_error(self, http_response):
        if http_response.status_code == 503:
            raise exceptions.Http503Error("error 503: service unavailable")

        raise exceptions.HttpError("error {}{}".format(
            http_response.status_code,
            ": {}".format(http_response.content)
            if http_response.content else "",
        ))
예제 #2
0
    def raise_response_error(self, http_response):
        if http_response.status_code == 503:
            raise exceptions.Http503Error('error 503: service unavailable')

        raise exceptions.HttpError('error {}{}'.format(
            http_response.status_code,
            ': {}'.format(http_response.content)
            if http_response.content else '',
        ))
예제 #3
0
    def process(self, http_response):
        # type: requests.Response -> PrestoStatus:
        status_code = http_response.status_code
        # mypy cannot follow module import
        if status_code != self.http.codes.ok:  # type: ignore
            if status_code == 503:
                raise exceptions.Http503Error('service unavailable')

            raise exceptions.HttpError('error {}: {}'.format(
                http_response.status_code,
                http_response.content,
            ))

        http_response.encoding = 'utf-8'
        response = http_response.json()
        logger.debug('HTTP {}: {}'.format(http_response.status_code, response))
        if 'error' in response:
            raise self._process_error(response['error'])

        if constants.HEADER_CLEAR_SESSION in http_response.headers:
            for prop in get_header_values(
                    response.headers,
                    constants.HEADER_CLEAR_SESSION,
            ):
                self._client_session.properties.pop(prop, None)

        if constants.HEADER_SET_SESSION in http_response.headers:
            for key, value in get_session_property_values(
                    response.headers,
                    constants.HEADER_SET_SESSION,
            ):
                self._client_session.properties[key] = value

        self._next_uri = response.get('nextUri')

        return PrestoStatus(
            id=response['id'],
            stats=response['stats'],
            info_uri=response['infoUri'],
            next_uri=self._next_uri,
            rows=response.get('data', []),
            columns=response.get('columns'),
        )
예제 #4
0
    def process(self, http_response):
        # type: requests.Response -> PrestoStatus:
        status_code = http_response.status_code
        # mypy cannot follow module import
        if status_code != self.http.codes.ok:  # type: ignore
            if status_code == 503:
                raise exceptions.Http503Error('service unavailable')

            raise exceptions.HttpError(
                'error {}: {}'.format(
                    http_response.status_code,
                    http_response.content,
                )
            )

        http_response.encoding = 'utf-8'
        response = http_response.json()
        logger.debug('HTTP {}: {}'.format(http_response.status_code, response))
        if 'error' in response:
            raise self._process_error(response['error'])

        if 'X-Presto-Clear-Session' in http_response.headers:
            propname = response.headers['X-Presto-Clear-Session']
            self._session_properties.pop(propname, None)

        if 'X-Presto-Set-Session' in http_response.headers:
            set_session_header = response.headers['X-Presto-Set-Session']
            name, value = set_session_header.split('=', 1)
            self._session_properties[name] = value

        self._next_uri = response.get('nextUri')

        return PrestoStatus(
            id=response['id'],
            stats=response['stats'],
            info_uri=response['infoUri'],
            next_uri=self._next_uri,
            rows=response.get('data', []),
            columns=response.get('columns'),
        )