#
# Autogenerated by Thrift Compiler (0.12.0)
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#
#  options string: py
#

from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException
from thrift.protocol.TProtocol import TProtocolException
from thrift.TRecursive import fix_spec

import sys
import base.ttypes

from thrift.transport import TTransport
all_structs = []


class ExampleEnum(object):
    A = 0
    B = 1
    C = 2

    _VALUES_TO_NAMES = {
        0: "A",
        1: "B",
        2: "C",
    }

    _NAMES_TO_VALUES = {
        "A": 0,
        "B": 1,
        "C": 2,
    }


class ErrCode(object):
    ERR_SUCCESS = 0
    ERR_REQ_PARAM_INVALID = 4000
    ERR_UNKNOWN = 5000
    ERR_SYSTEM_INNER_EXCEPTION = 5001
    ERR_LIMIT_EXCEEDED = 5002

    _VALUES_TO_NAMES = {
        0: "ERR_SUCCESS",
        4000: "ERR_REQ_PARAM_INVALID",
        5000: "ERR_UNKNOWN",
        5001: "ERR_SYSTEM_INNER_EXCEPTION",
        5002: "ERR_LIMIT_EXCEEDED",
    }

    _NAMES_TO_VALUES = {
        "ERR_SUCCESS": 0,
        "ERR_REQ_PARAM_INVALID": 4000,
        "ERR_UNKNOWN": 5000,
        "ERR_SYSTEM_INNER_EXCEPTION": 5001,
        "ERR_LIMIT_EXCEEDED": 5002,
    }


class Example(object):
    """
    Attributes:
     - A
     - B
     - C
     - D
     - E
     - F
     - G
     - H
     - I
     - J
     - K
     - L
     - M
     - N
     - O
     - P
     - Q

    """


    def __init__(self, A=None, B=None, C=None, D=None, E=True, F=None, G=0.1000000000000000, H="hello", I=None, J=None, K=None, L={
    }, M=None, N=None, O=None, P=None, Q=None,):
        self.A = A
        self.B = B
        self.C = C
        self.D = D
        self.E = E
        self.F = F
        self.G = G
        self.H = H
        self.I = I
        self.J = J
        self.K = K
        if L is self.thrift_spec[12][4]:
            L = {
            }
        self.L = L
        self.M = M
        self.N = N
        self.O = O
        self.P = P
        self.Q = Q

    def read(self, iprot):
        if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None:
            iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec])
            return
        iprot.readStructBegin()
        while True:
            (fname, ftype, fid) = iprot.readFieldBegin()
            if ftype == TType.STOP:
                break
            if fid == 1:
                if ftype == TType.MAP:
                    self.A = {}
                    (_ktype1, _vtype2, _size0) = iprot.readMapBegin()
                    for _i4 in range(_size0):
                        _key5 = {}
                        (_ktype8, _vtype9, _size7) = iprot.readMapBegin()
                        for _i11 in range(_size7):
                            _key12 = base.ttypes.Base()
                            _key12.read(iprot)
                            _val13 = base.ttypes.Base()
                            _val13.read(iprot)
                            _key5[_key12] = _val13
                        iprot.readMapEnd()
                        _val6 = base.ttypes.Base()
                        _val6.read(iprot)
                        self.A[_key5] = _val6
                    iprot.readMapEnd()
                else:
                    iprot.skip(ftype)
            elif fid == 2:
                if ftype == TType.I16:
                    self.B = iprot.readI16()
                else:
                    iprot.skip(ftype)
            elif fid == 3:
                if ftype == TType.I32:
                    self.C = iprot.readI32()
                else:
                    iprot.skip(ftype)
            elif fid == 4:
                if ftype == TType.I64:
                    self.D = iprot.readI64()
                else:
                    iprot.skip(ftype)
            elif fid == 5:
                if ftype == TType.BOOL:
                    self.E = iprot.readBool()
                else:
                    iprot.skip(ftype)
            elif fid == 6:
                if ftype == TType.BYTE:
                    self.F = iprot.readByte()
                else:
                    iprot.skip(ftype)
            elif fid == 7:
                if ftype == TType.DOUBLE:
                    self.G = iprot.readDouble()
                else:
                    iprot.skip(ftype)
            elif fid == 8:
                if ftype == TType.STRING:
                    self.H = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
                else:
                    iprot.skip(ftype)
            elif fid == 9:
                if ftype == TType.STRUCT:
                    self.I = base.ttypes.Base()
                    self.I.read(iprot)
                else:
                    iprot.skip(ftype)
            elif fid == 10:
                if ftype == TType.MAP:
                    self.J = {}
                    (_ktype15, _vtype16, _size14) = iprot.readMapBegin()
                    for _i18 in range(_size14):
                        _key19 = base.ttypes.Base()
                        _key19.read(iprot)
                        _val20 = {}
                        (_ktype22, _vtype23, _size21) = iprot.readMapBegin()
                        for _i25 in range(_size21):
                            _key26 = base.ttypes.Base()
                            _key26.read(iprot)
                            _val27 = base.ttypes.Base()
                            _val27.read(iprot)
                            _val20[_key26] = _val27
                        iprot.readMapEnd()
                        self.J[_key19] = _val20
                    iprot.readMapEnd()
                else:
                    iprot.skip(ftype)
            elif fid == 11:
                if ftype == TType.MAP:
                    self.K = {}
                    (_ktype29, _vtype30, _size28) = iprot.readMapBegin()
                    for _i32 in range(_size28):
                        _key33 = base.ttypes.Base()
                        _key33.read(iprot)
                        _val34 = base.ttypes.Base()
                        _val34.read(iprot)
                        self.K[_key33] = _val34
                    iprot.readMapEnd()
                else:
                    iprot.skip(ftype)
            elif fid == 12:
                if ftype == TType.MAP:
                    self.L = {}
                    (_ktype36, _vtype37, _size35) = iprot.readMapBegin()
                    for _i39 in range(_size35):
                        _key40 = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
                        _val41 = iprot.readBool()
                        self.L[_key40] = _val41
                    iprot.readMapEnd()
                else:
                    iprot.skip(ftype)
            elif fid == 13:
                if ftype == TType.MAP:
                    self.M = {}
                    (_ktype43, _vtype44, _size42) = iprot.readMapBegin()
                    for _i46 in range(_size42):
                        _key47 = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
                        _val48 = []
                        (_etype52, _size49) = iprot.readListBegin()
                        for _i53 in range(_size49):
                            _elem54 = {}
                            (_ktype56, _vtype57, _size55) = iprot.readMapBegin()
                            for _i59 in range(_size55):
                                _key60 = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
                                _val61 = base.ttypes.Base()
                                _val61.read(iprot)
                                _elem54[_key60] = _val61
                            iprot.readMapEnd()
                            _val48.append(_elem54)
                        iprot.readListEnd()
                        self.M[_key47] = _val48
                    iprot.readMapEnd()
                else:
                    iprot.skip(ftype)
            elif fid == 14:
                if ftype == TType.LIST:
                    self.N = []
                    (_etype65, _size62) = iprot.readListBegin()
                    for _i66 in range(_size62):
                        _elem67 = base.ttypes.Base()
                        _elem67.read(iprot)
                        self.N.append(_elem67)
                    iprot.readListEnd()
                else:
                    iprot.skip(ftype)
            elif fid == 15:
                if ftype == TType.LIST:
                    self.O = []
                    (_etype71, _size68) = iprot.readListBegin()
                    for _i72 in range(_size68):
                        _elem73 = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
                        self.O.append(_elem73)
                    iprot.readListEnd()
                else:
                    iprot.skip(ftype)
            elif fid == 16:
                if ftype == TType.SET:
                    self.P = set()
                    (_etype77, _size74) = iprot.readSetBegin()
                    for _i78 in range(_size74):
                        _elem79 = iprot.readI16()
                        self.P.add(_elem79)
                    iprot.readSetEnd()
                else:
                    iprot.skip(ftype)
            elif fid == 17:
                if ftype == TType.LIST:
                    self.Q = []
                    (_etype83, _size80) = iprot.readListBegin()
                    for _i84 in range(_size80):
                        _elem85 = {}
                        (_ktype87, _vtype88, _size86) = iprot.readMapBegin()
                        for _i90 in range(_size86):
                            _key91 = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
                            _val92 = base.ttypes.Base()
                            _val92.read(iprot)
                            _elem85[_key91] = _val92
                        iprot.readMapEnd()
                        self.Q.append(_elem85)
                    iprot.readListEnd()
                else:
                    iprot.skip(ftype)
            else:
                iprot.skip(ftype)
            iprot.readFieldEnd()
        iprot.readStructEnd()

    def write(self, oprot):
        if oprot._fast_encode is not None and self.thrift_spec is not None:
            oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec]))
            return
        oprot.writeStructBegin('Example')
        if self.A is not None:
            oprot.writeFieldBegin('A', TType.MAP, 1)
            oprot.writeMapBegin(TType.MAP, TType.STRUCT, len(self.A))
            for kiter93, viter94 in self.A.items():
                oprot.writeMapBegin(TType.STRUCT, TType.STRUCT, len(kiter93))
                for kiter95, viter96 in kiter93.items():
                    kiter95.write(oprot)
                    viter96.write(oprot)
                oprot.writeMapEnd()
                viter94.write(oprot)
            oprot.writeMapEnd()
            oprot.writeFieldEnd()
        if self.B is not None:
            oprot.writeFieldBegin('B', TType.I16, 2)
            oprot.writeI16(self.B)
            oprot.writeFieldEnd()
        if self.C is not None:
            oprot.writeFieldBegin('C', TType.I32, 3)
            oprot.writeI32(self.C)
            oprot.writeFieldEnd()
        if self.D is not None:
            oprot.writeFieldBegin('D', TType.I64, 4)
            oprot.writeI64(self.D)
            oprot.writeFieldEnd()
        if self.E is not None:
            oprot.writeFieldBegin('E', TType.BOOL, 5)
            oprot.writeBool(self.E)
            oprot.writeFieldEnd()
        if self.F is not None:
            oprot.writeFieldBegin('F', TType.BYTE, 6)
            oprot.writeByte(self.F)
            oprot.writeFieldEnd()
        if self.G is not None:
            oprot.writeFieldBegin('G', TType.DOUBLE, 7)
            oprot.writeDouble(self.G)
            oprot.writeFieldEnd()
        if self.H is not None:
            oprot.writeFieldBegin('H', TType.STRING, 8)
            oprot.writeString(self.H.encode('utf-8') if sys.version_info[0] == 2 else self.H)
            oprot.writeFieldEnd()
        if self.I is not None:
            oprot.writeFieldBegin('I', TType.STRUCT, 9)
            self.I.write(oprot)
            oprot.writeFieldEnd()
        if self.J is not None:
            oprot.writeFieldBegin('J', TType.MAP, 10)
            oprot.writeMapBegin(TType.STRUCT, TType.MAP, len(self.J))
            for kiter97, viter98 in self.J.items():
                kiter97.write(oprot)
                oprot.writeMapBegin(TType.STRUCT, TType.STRUCT, len(viter98))
                for kiter99, viter100 in viter98.items():
                    kiter99.write(oprot)
                    viter100.write(oprot)
                oprot.writeMapEnd()
            oprot.writeMapEnd()
            oprot.writeFieldEnd()
        if self.K is not None:
            oprot.writeFieldBegin('K', TType.MAP, 11)
            oprot.writeMapBegin(TType.STRUCT, TType.STRUCT, len(self.K))
            for kiter101, viter102 in self.K.items():
                kiter101.write(oprot)
                viter102.write(oprot)
            oprot.writeMapEnd()
            oprot.writeFieldEnd()
        if self.L is not None:
            oprot.writeFieldBegin('L', TType.MAP, 12)
            oprot.writeMapBegin(TType.STRING, TType.BOOL, len(self.L))
            for kiter103, viter104 in self.L.items():
                oprot.writeString(kiter103.encode('utf-8') if sys.version_info[0] == 2 else kiter103)
                oprot.writeBool(viter104)
            oprot.writeMapEnd()
            oprot.writeFieldEnd()
        if self.M is not None:
            oprot.writeFieldBegin('M', TType.MAP, 13)
            oprot.writeMapBegin(TType.STRING, TType.LIST, len(self.M))
            for kiter105, viter106 in self.M.items():
                oprot.writeString(kiter105.encode('utf-8') if sys.version_info[0] == 2 else kiter105)
                oprot.writeListBegin(TType.MAP, len(viter106))
                for iter107 in viter106:
                    oprot.writeMapBegin(TType.STRING, TType.STRUCT, len(iter107))
                    for kiter108, viter109 in iter107.items():
                        oprot.writeString(kiter108.encode('utf-8') if sys.version_info[0] == 2 else kiter108)
                        viter109.write(oprot)
                    oprot.writeMapEnd()
                oprot.writeListEnd()
            oprot.writeMapEnd()
            oprot.writeFieldEnd()
        if self.N is not None:
            oprot.writeFieldBegin('N', TType.LIST, 14)
            oprot.writeListBegin(TType.STRUCT, len(self.N))
            for iter110 in self.N:
                iter110.write(oprot)
            oprot.writeListEnd()
            oprot.writeFieldEnd()
        if self.O is not None:
            oprot.writeFieldBegin('O', TType.LIST, 15)
            oprot.writeListBegin(TType.STRING, len(self.O))
            for iter111 in self.O:
                oprot.writeString(iter111.encode('utf-8') if sys.version_info[0] == 2 else iter111)
            oprot.writeListEnd()
            oprot.writeFieldEnd()
        if self.P is not None:
            oprot.writeFieldBegin('P', TType.SET, 16)
            oprot.writeSetBegin(TType.I16, len(self.P))
            for iter112 in self.P:
                oprot.writeI16(iter112)
            oprot.writeSetEnd()
            oprot.writeFieldEnd()
        if self.Q is not None:
            oprot.writeFieldBegin('Q', TType.LIST, 17)
            oprot.writeListBegin(TType.MAP, len(self.Q))
            for iter113 in self.Q:
                oprot.writeMapBegin(TType.STRING, TType.STRUCT, len(iter113))
                for kiter114, viter115 in iter113.items():
                    oprot.writeString(kiter114.encode('utf-8') if sys.version_info[0] == 2 else kiter114)
                    viter115.write(oprot)
                oprot.writeMapEnd()
            oprot.writeListEnd()
            oprot.writeFieldEnd()
        oprot.writeFieldStop()
        oprot.writeStructEnd()

    def validate(self):
        return

    def __repr__(self):
        L = ['%s=%r' % (key, value)
             for key, value in self.__dict__.items()]
        return '%s(%s)' % (self.__class__.__name__, ', '.join(L))

    def __eq__(self, other):
        return isinstance(other, self.__class__) and self.__dict__ == other.__dict__

    def __ne__(self, other):
        return not (self == other)


class ExampleUnion(object):
    """
    Attributes:
     - A

    """


    def __init__(self, A=1,):
        self.A = A

    def read(self, iprot):
        if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None:
            iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec])
            return
        iprot.readStructBegin()
        while True:
            (fname, ftype, fid) = iprot.readFieldBegin()
            if ftype == TType.STOP:
                break
            if fid == 1:
                if ftype == TType.I32:
                    self.A = iprot.readI32()
                else:
                    iprot.skip(ftype)
            else:
                iprot.skip(ftype)
            iprot.readFieldEnd()
        iprot.readStructEnd()

    def write(self, oprot):
        if oprot._fast_encode is not None and self.thrift_spec is not None:
            oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec]))
            return
        oprot.writeStructBegin('ExampleUnion')
        if self.A is not None:
            oprot.writeFieldBegin('A', TType.I32, 1)
            oprot.writeI32(self.A)
            oprot.writeFieldEnd()
        oprot.writeFieldStop()
        oprot.writeStructEnd()

    def validate(self):
        return

    def __repr__(self):
        L = ['%s=%r' % (key, value)
             for key, value in self.__dict__.items()]
        return '%s(%s)' % (self.__class__.__name__, ', '.join(L))

    def __eq__(self, other):
        return isinstance(other, self.__class__) and self.__dict__ == other.__dict__

    def __ne__(self, other):
        return not (self == other)


class ByteException(TException):
    """
    Attributes:
     - ErrorCode

    """


    def __init__(self, ErrorCode=0,):
        self.ErrorCode = ErrorCode

    def read(self, iprot):
        if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None:
            iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec])
            return
        iprot.readStructBegin()
        while True:
            (fname, ftype, fid) = iprot.readFieldBegin()
            if ftype == TType.STOP:
                break
            if fid == 1:
                if ftype == TType.I32:
                    self.ErrorCode = iprot.readI32()
                else:
                    iprot.skip(ftype)
            else:
                iprot.skip(ftype)
            iprot.readFieldEnd()
        iprot.readStructEnd()

    def write(self, oprot):
        if oprot._fast_encode is not None and self.thrift_spec is not None:
            oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec]))
            return
        oprot.writeStructBegin('ByteException')
        if self.ErrorCode is not None:
            oprot.writeFieldBegin('ErrorCode', TType.I32, 1)
            oprot.writeI32(self.ErrorCode)
            oprot.writeFieldEnd()
        oprot.writeFieldStop()
        oprot.writeStructEnd()

    def validate(self):
        return

    def __str__(self):
        return repr(self)

    def __repr__(self):
        L = ['%s=%r' % (key, value)
             for key, value in self.__dict__.items()]
        return '%s(%s)' % (self.__class__.__name__, ', '.join(L))

    def __eq__(self, other):
        return isinstance(other, self.__class__) and self.__dict__ == other.__dict__

    def __ne__(self, other):
        return not (self == other)
all_structs.append(Example)
Example.thrift_spec = (
    None,  # 0
    (1, TType.MAP, 'A', (TType.MAP, (TType.STRUCT, [base.ttypes.Base, None], TType.STRUCT, [base.ttypes.Base, None], False), TType.STRUCT, [base.ttypes.Base, None], False), None, ),  # 1
    (2, TType.I16, 'B', None, None, ),  # 2
    (3, TType.I32, 'C', None, None, ),  # 3
    (4, TType.I64, 'D', None, None, ),  # 4
    (5, TType.BOOL, 'E', None, True, ),  # 5
    (6, TType.BYTE, 'F', None, None, ),  # 6
    (7, TType.DOUBLE, 'G', None, 0.1000000000000000, ),  # 7
    (8, TType.STRING, 'H', 'UTF8', "hello", ),  # 8
    (9, TType.STRUCT, 'I', [base.ttypes.Base, None], None, ),  # 9
    (10, TType.MAP, 'J', (TType.STRUCT, [base.ttypes.Base, None], TType.MAP, (TType.STRUCT, [base.ttypes.Base, None], TType.STRUCT, [base.ttypes.Base, None], False), False), None, ),  # 10
    (11, TType.MAP, 'K', (TType.STRUCT, [base.ttypes.Base, None], TType.STRUCT, [base.ttypes.Base, None], False), None, ),  # 11
    (12, TType.MAP, 'L', (TType.STRING, 'UTF8', TType.BOOL, None, False), {
    }, ),  # 12
    (13, TType.MAP, 'M', (TType.STRING, 'UTF8', TType.LIST, (TType.MAP, (TType.STRING, 'UTF8', TType.STRUCT, [base.ttypes.Base, None], False), False), False), None, ),  # 13
    (14, TType.LIST, 'N', (TType.STRUCT, [base.ttypes.Base, None], False), None, ),  # 14
    (15, TType.LIST, 'O', (TType.STRING, 'UTF8', False), None, ),  # 15
    (16, TType.SET, 'P', (TType.I16, None, False), None, ),  # 16
    (17, TType.LIST, 'Q', (TType.MAP, (TType.STRING, 'UTF8', TType.STRUCT, [base.ttypes.Base, None], False), False), None, ),  # 17
)
all_structs.append(ExampleUnion)
ExampleUnion.thrift_spec = (
    None,  # 0
    (1, TType.I32, 'A', None, 1, ),  # 1
)
all_structs.append(ByteException)
ByteException.thrift_spec = (
    None,  # 0
    (1, TType.I32, 'ErrorCode', None, 0, ),  # 1
)
fix_spec(all_structs)
del all_structs
