Exemple #1
0
def thrift_headers_matcher(l, r):
    serializer = ThriftSerializer(None)
    try:
        left = serializer.deserialize_header(l)
        right = serializer.deserialize_header(r)

        return filter_headers(left) == filter_headers(right)
    except Exception:
        return l == r
Exemple #2
0
def thrift_headers_matcher(l, r):
    serializer = ThriftSerializer(None)
    try:
        left = serializer.deserialize_header(l)
        right = serializer.deserialize_header(r)

        return filter_headers(left) == filter_headers(right)
    except Exception:
        return l == r
Exemple #3
0
    def __call__(self,
                 request,
                 headers=None,
                 timeout=None,
                 retry_on=None,
                 retry_limit=None):

        if not headers:
            headers = {}

        serializer = ThriftSerializer(request.result_type)
        # serialize
        try:
            headers = serializer.serialize_header(headers=headers)
        except (AttributeError, TypeError):
            raise ValueError(
                'headers must be a map[string]string (a shallow dict'
                ' where keys and values are strings)')

        body = serializer.serialize_body(call_args=request.call_args)
        response = yield self._tchannel.call(scheme=self.NAME,
                                             service=request.service,
                                             arg1=request.endpoint,
                                             arg2=headers,
                                             arg3=body,
                                             timeout=timeout,
                                             retry_on=retry_on,
                                             retry_limit=retry_limit,
                                             hostport=request.hostport)

        # deserialize...
        response.headers = serializer.deserialize_header(
            headers=response.headers)
        body = serializer.deserialize_body(body=response.body)
        result_spec = request.result_type.thrift_spec

        # raise application exception, if present
        for exc_spec in result_spec[1:]:
            exc = getattr(body, exc_spec[2])
            if exc is not None:
                raise exc

        # success - non-void
        if len(result_spec) >= 1 and result_spec[0] is not None:

            # value expected, but got none
            # TODO - server side should use this same logic
            if body.success is None:
                raise ValueExpectedError(
                    'Expected a value to be returned for %s, '
                    'but recieved None - only void procedures can'
                    'return None.' % request.endpoint)

            response.body = body.success
            raise gen.Return(response)

        # success - void
        else:
            response.body = None
            raise gen.Return(response)
Exemple #4
0
def test_header(v1):
    serializer = ThriftSerializer(None)
    assert v1 == serializer.deserialize_header(serializer.serialize_header(v1))
Exemple #5
0
    def __call__(self, request, headers=None, timeout=None,
                 retry_on=None, retry_limit=None):

        if not headers:
            headers = {}

        serializer = ThriftSerializer(request.result_type)
        # serialize
        try:
            headers = serializer.serialize_header(headers=headers)
        except (AttributeError, TypeError):
            raise ValueError(
                'headers must be a map[string]string (a shallow dict'
                ' where keys and values are strings)'
            )

        body = serializer.serialize_body(call_args=request.call_args)
        response = yield self._tchannel.call(
            scheme=self.NAME,
            service=request.service,
            arg1=request.endpoint,
            arg2=headers,
            arg3=body,
            timeout=timeout,
            retry_on=retry_on,
            retry_limit=retry_limit,
            hostport=request.hostport
        )

        # deserialize...
        response.headers = serializer.deserialize_header(
            headers=response.headers
        )
        body = serializer.deserialize_body(body=response.body)
        result_spec = request.result_type.thrift_spec

        # raise application exception, if present
        for exc_spec in result_spec[1:]:
            exc = getattr(body, exc_spec[2])
            if exc is not None:
                raise exc

        # success - non-void
        if len(result_spec) >= 1 and result_spec[0] is not None:

            # value expected, but got none
            # TODO - server side should use this same logic
            if body.success is None:
                raise ValueExpectedError(
                    'Expected a value to be returned for %s, '
                    'but recieved None - only void procedures can'
                    'return None.' % request.endpoint
                )

            response.body = body.success
            raise gen.Return(response)

        # success - void
        else:
            response.body = None
            raise gen.Return(response)
def test_header(v1):
    serializer = ThriftSerializer(None)
    assert v1 == serializer.deserialize_header(
        serializer.serialize_header(v1)
    )