# Path: zoonado/exc.py
# class ZKError(Exception):
# class ConnectError(ZKError):
# class NoServersError(ZKError):
# class SessionLost(ZKError):
# class InvalidClientState(ZKError):
# class TimeoutError(ZKError):
# class FailedRetry(ZKError):
# class ResponseErrorMeta(type):
# class ResponseError(ZKError):
# class UnknownError(ResponseError):
# class RolledBack(ResponseError):
# class ZKSystemError(ResponseError):
# class RuntimeInconsistency(ResponseError):
# class DataInconsistency(ResponseError):
# class ConnectionLoss(ResponseError):
# class MarshallingError(ResponseError):
# class Unimplemented(ResponseError):
# class OperationTimeout(ResponseError):
# class BadArguments(ResponseError):
# class UnknownSession(ResponseError):
# class NewConfigNoQuorum(ResponseError):
# class ReconfigInProcess(ResponseError):
# class APIError(ResponseError):
# class NoNode(ResponseError):
# class NoAuth(ResponseError):
# class BadVersion(ResponseError):
# class NoChildrenForEphemerals(ResponseError):
# class NodeExists(ResponseError):
# class NotEmpty(ResponseError):
# class SessionExpired(ResponseError):
# class InvalidCallback(ResponseError):
# class InvalidACL(ResponseError):
# class AuthFailed(ResponseError):
# class SessionMoved(ResponseError):
# class NotReadOnly(ResponseError):
# class EphemeralOnLocalSession(ResponseError):
# class NoWatcher(ResponseError):
#     def __init__(self, host, port, server_id=None):
#     def __str__(self):
#     def __new__(cls, name, bases, attrs):
#     def __str__(self):
#     def __init__(self, error_code):
#     def __str__(self):
# def get_response_error(error_code):
# 
# Path: zoonado/protocol/transaction.py
# class MultiHeader(Part):
# class TransactionRequest(Request):
# class TransactionResponse(Response):
#     def __init__(self, *args, **kwargs):
#     def add(self, request):
#     def serialize(self, xid=None):
#     def __str__(self):
#     def __init__(self, *args, **kwargs):
#     def deserialize(cls, raw_bytes):
#     def __str__(self):
# 
# Path: zoonado/protocol/request.py
# class Request(Part):
#     def serialize(self, xid=None):
# 
# Path: zoonado/protocol/response.py
# class ResponseMeta(type):
# class Response(Part):
#     def __new__(cls, name, bases, attrs):
#     def deserialize(cls, raw_bytes):
# 
# Path: zoonado/protocol/primitives.py
# class Primitive(object):
# class VariablePrimitive(Primitive):
# class Bool(Primitive):
# class Byte(Primitive):
# class Int(Primitive):
# class Long(Primitive):
# class Float(Primitive):
# class Double(Primitive):
# class UString(VariablePrimitive):
# class Buffer(VariablePrimitive):
# class Vector(Primitive):
#     def __init__(self, value):
#     def render(self):
#     def parse(cls, buff, offset):
#     def __eq__(self, other):
#     def __str__(self):
#     def render_value(self, value):
#     def parse_value(cls, value):
#     def render(self):
#     def parse(cls, buff, offset):
#     def render_value(self, value):
#     def parse_value(cls, value):
#     def __str__(self):
#     def render_value(self, value):
#     def parse_value(cls, value):
#     def of(cls, part_class):
#     def render(self):
#     def parse(cls, buff, offset):
#     def __str__(self):


import struct
import unittest
from mock import patch
from zoonado import exc
from zoonado.protocol import transaction, request, response, primitives
    def test_request_stringified(self):
        txn = transaction.TransactionRequest()

        txn.add(FakeOpRequest(foo="bar"))
        txn.add(FakeSpecialRequest())

        self.assertEqual(
            str(txn),
            "Txn[FakeOpRequest(foo=bar), FakeSpecialRequest()]"
        )

    @patch.object(transaction, "response_xref", fake_response_xref)
    def test_response_deserialization(self):

        payload = struct.pack(
            "!" + "".join([
                'i?i',  # multiheader: opcode, done, error
                'i3s',  # three-character string
                'i?i',  # multiheader
                '',     # special request's body is blank
                'i?i',  # ending multiheader
            ]),
            *[
                99, False, -1,  # 99 = opcode for fake op
                3, b"bar",
                999, False, -1,  # 999 = opcode for fake special response
                -1, True, -1,
            ]
        )


# Path: zoonado/exc.py
# class ZKError(Exception):
# class ConnectError(ZKError):
# class NoServersError(ZKError):
# class SessionLost(ZKError):
# class InvalidClientState(ZKError):
# class TimeoutError(ZKError):
# class FailedRetry(ZKError):
# class ResponseErrorMeta(type):
# class ResponseError(ZKError):
# class UnknownError(ResponseError):
# class RolledBack(ResponseError):
# class ZKSystemError(ResponseError):
# class RuntimeInconsistency(ResponseError):
# class DataInconsistency(ResponseError):
# class ConnectionLoss(ResponseError):
# class MarshallingError(ResponseError):
# class Unimplemented(ResponseError):
# class OperationTimeout(ResponseError):
# class BadArguments(ResponseError):
# class UnknownSession(ResponseError):
# class NewConfigNoQuorum(ResponseError):
# class ReconfigInProcess(ResponseError):
# class APIError(ResponseError):
# class NoNode(ResponseError):
# class NoAuth(ResponseError):
# class BadVersion(ResponseError):
# class NoChildrenForEphemerals(ResponseError):
# class NodeExists(ResponseError):
# class NotEmpty(ResponseError):
# class SessionExpired(ResponseError):
# class InvalidCallback(ResponseError):
# class InvalidACL(ResponseError):
# class AuthFailed(ResponseError):
# class SessionMoved(ResponseError):
# class NotReadOnly(ResponseError):
# class EphemeralOnLocalSession(ResponseError):
# class NoWatcher(ResponseError):
#     def __init__(self, host, port, server_id=None):
#     def __str__(self):
#     def __new__(cls, name, bases, attrs):
#     def __str__(self):
#     def __init__(self, error_code):
#     def __str__(self):
# def get_response_error(error_code):
# 
# Path: zoonado/protocol/transaction.py
# class MultiHeader(Part):
# class TransactionRequest(Request):
# class TransactionResponse(Response):
#     def __init__(self, *args, **kwargs):
#     def add(self, request):
#     def serialize(self, xid=None):
#     def __str__(self):
#     def __init__(self, *args, **kwargs):
#     def deserialize(cls, raw_bytes):
#     def __str__(self):
# 
# Path: zoonado/protocol/request.py
# class Request(Part):
#     def serialize(self, xid=None):
# 
# Path: zoonado/protocol/response.py
# class ResponseMeta(type):
# class Response(Part):
#     def __new__(cls, name, bases, attrs):
#     def deserialize(cls, raw_bytes):
# 
# Path: zoonado/protocol/primitives.py
# class Primitive(object):
# class VariablePrimitive(Primitive):
# class Bool(Primitive):
# class Byte(Primitive):
# class Int(Primitive):
# class Long(Primitive):
# class Float(Primitive):
# class Double(Primitive):
# class UString(VariablePrimitive):
# class Buffer(VariablePrimitive):
# class Vector(Primitive):
#     def __init__(self, value):
#     def render(self):
#     def parse(cls, buff, offset):
#     def __eq__(self, other):
#     def __str__(self):
#     def render_value(self, value):
#     def parse_value(cls, value):
#     def render(self):
#     def parse(cls, buff, offset):
#     def render_value(self, value):
#     def parse_value(cls, value):
#     def __str__(self):
#     def render_value(self, value):
#     def parse_value(cls, value):
#     def of(cls, part_class):
#     def render(self):
#     def parse(cls, buff, offset):
#     def __str__(self):


# Path: tests/protocol/test_transaction.py
import struct
import unittest
from mock import patch
from zoonado import exc
from zoonado.protocol import transaction, request, response, primitives

    def test_request_stringified(self):
        txn = transaction.TransactionRequest()

        txn.add(FakeOpRequest(foo="bar"))
        txn.add(FakeSpecialRequest())

        self.assertEqual(
            str(txn),
            "Txn[FakeOpRequest(foo=bar), FakeSpecialRequest()]"
        )

    @patch.object(transaction, "response_xref", fake_response_xref)
    def test_response_deserialization(self):

        payload = struct.pack(
            "!" + "".join([
                'i?i',  # multiheader: opcode, done, error
                'i3s',  # three-character string
                'i?i',  # multiheader
                '',     # special request's body is blank
                'i?i',  # ending multiheader
            ]),
            *[
                99, False, -1,  # 99 = opcode for fake op
                3, b"bar",
                999, False, -1,  # 999 = opcode for fake special response
                -1, True, -1,
            ]
        )


        response = transaction.TransactionResponse.deserialize(payload)