コード例 #1
0
ファイル: client.py プロジェクト: hujunfei/samsa
def decode_message_sets(payload, from_offsets):
    offset = 0
    for from_offset in from_offsets:
        (length,) = ResponseFrameHeader.unpack_from(payload, offset=offset)
        header = ResponseErrorHeader.unpack_from(
            payload,
            offset=offset + ResponseFrameHeader.size
        )
        if header.error:
            error_class = ERROR_CODES.get(header.error, -1)
            raise error_class(error_class.reason)
        message_set_payload = buffer(payload,
            offset + (ResponseFrameHeader.size + ResponseErrorHeader.size),
            length - ResponseErrorHeader.size)
        yield decode_messages(message_set_payload, from_offset)
        offset += length + ResponseFrameHeader.size
コード例 #2
0
ファイル: client.py プロジェクト: hujunfei/samsa
    def response(self, future):
        """Wait for a response and assign to future.

        :param future: Where to assign response data.
        :type future: :class:`samsa.handlers.ResponseFuture`

        """
        try:
            response = recv_framed(self._socket, ResponseFrameHeader)
        except SocketDisconnectedError:
            self.disconnect()
            raise

        header = ResponseErrorHeader.unpack_from(buffer(response))
        if header.error:
            exception_class = ERROR_CODES.get(header.error, -1)
            # TODO: Add better error messaging.
            future.set_error(exception_class)
        else:
            future.set_response(buffer(response, ResponseErrorHeader.size))