<s> '''<STR_LIT>''' <EOL> import struct <EOL> from core . api . data import * <EOL> from core . misc . ipaddr import * <EOL> class CoreTlvData ( object ) : <EOL> datafmt = None <EOL> datatype = None <EOL> padlen = None <EOL> @ classmethod <EOL> def pack ( cls , value ) : <EOL> "<STR_LIT>" <EOL> tmp = struct . pack ( cls . datafmt , value ) <EOL> return len ( tmp ) - cls . padlen , tmp <EOL> @ classmethod <EOL> def unpack ( cls , data ) : <EOL> return struct . unpack ( cls . datafmt , data ) [ <NUM_LIT:0> ] <EOL> @ classmethod <EOL> def packstring ( cls , strvalue ) : <EOL> return cls . pack ( cls . fromstring ( strvalue ) ) <EOL> @ classmethod <EOL> def fromstring ( cls , s ) : <EOL> return cls . datatype ( s ) <EOL> class CoreTlvDataObj ( CoreTlvData ) : <EOL> @ classmethod <EOL> def pack ( cls , obj ) : <EOL> "<STR_LIT>" <EOL> tmp = struct . pack ( cls . datafmt , cls . getvalue ( obj ) ) <EOL> return len ( tmp ) - cls . padlen , tmp <EOL> @ classmethod <EOL> def unpack ( cls , data ) : <EOL> return cls . newobj ( struct . unpack ( cls . datafmt , data ) [ <NUM_LIT:0> ] ) <EOL> @ staticmethod <EOL> def getvalue ( obj ) : <EOL> raise NotImplementedError <EOL> @ staticmethod <EOL> def newobj ( obj ) : <EOL> raise NotImplementedError <EOL> class CoreTlvDataUint16 ( CoreTlvData ) : <EOL> datafmt = "<STR_LIT>" <EOL> datatype = int <EOL> padlen = <NUM_LIT:0> <EOL> class CoreTlvDataUint32 ( CoreTlvData ) : <EOL> datafmt = "<STR_LIT>" <EOL> datatype = int <EOL> padlen = <NUM_LIT:2> <EOL> class CoreTlvDataUint64 ( CoreTlvData ) : <EOL> datafmt = "<STR_LIT>" <EOL> datatype = long <EOL> padlen = <NUM_LIT:2> <EOL> class CoreTlvDataString ( CoreTlvData ) : <EOL> datatype = str <EOL> @ staticmethod <EOL> def pack ( value ) : <EOL> if not isinstance ( value , str ) : <EOL> raise ValueError , "<STR_LIT>" % value <EOL> if len ( value ) < <NUM_LIT> : <EOL> hdrsiz = CoreTlv . hdrsiz <EOL> else : <EOL> hdrsiz = CoreTlv . longhdrsiz <EOL> padlen = - ( hdrsiz + len ( value ) ) % <NUM_LIT:4> <EOL> return len ( value ) , value + '<STR_LIT>' * padlen <EOL> @ staticmethod <EOL> def unpack ( data ) : <EOL> return data . rstrip ( '<STR_LIT>' ) <EOL> class CoreTlvDataUint16List ( CoreTlvData ) : <EOL> '''<STR_LIT>''' <EOL> datatype = tuple <EOL> @ staticmethod <EOL> def pack ( values ) : <EOL> if not isinstance ( values , tuple ) : <EOL> raise ValueError , "<STR_LIT>" % values <EOL> data = "<STR_LIT>" <EOL> for v in values : <EOL> data += struct . pack ( "<STR_LIT>" , v ) <EOL> padlen = - ( CoreTlv . hdrsiz + len ( data ) ) % <NUM_LIT:4> <EOL> return len ( data ) , data + '<STR_LIT>' * padlen <EOL> @ staticmethod <EOL> def unpack ( data ) : <EOL> datafmt = "<STR_LIT>" % ( len ( data ) / <NUM_LIT:2> ) <EOL> return struct . unpack ( datafmt , data ) <EOL> @ classmethod <EOL> def fromstring ( cls , s ) : <EOL> return tuple ( map ( lambda ( x ) : int ( x ) , s . split ( ) ) ) <EOL> class CoreTlvDataIPv4Addr ( CoreTlvDataObj ) : <EOL> datafmt = "<STR_LIT>" <EOL> datatype = IPAddr . fromstring <EOL> padlen = <NUM_LIT:2> <EOL> @ staticmethod <EOL> def getvalue ( obj ) : <EOL> return obj . addr <EOL> @ staticmethod <EOL> def newobj ( value ) : <EOL> return IPAddr ( af = AF_INET , addr = value ) <EOL> class CoreTlvDataIPv6Addr ( CoreTlvDataObj ) : <EOL> datafmt = "<STR_LIT>" <EOL> datatype = IPAddr . fromstring <EOL> padlen = <NUM_LIT:2> <EOL> @ staticmethod <EOL> def getvalue ( obj ) : <EOL> return obj . addr <EOL> @ staticmethod <EOL> def newobj ( value ) : <EOL> return IPAddr ( af = AF_INET6 , addr = value ) <EOL> class CoreTlvDataMacAddr ( CoreTlvDataObj ) : <EOL> datafmt = "<STR_LIT>" <EOL> datatype = MacAddr . fromstring <EOL> padlen = <NUM_LIT:2> <EOL> @ staticmethod <EOL> def getvalue ( obj ) : <EOL> return '<STR_LIT>' + obj . addr <EOL> @ staticmethod <EOL> def newobj ( value ) : <EOL> return MacAddr ( addr = value [ <NUM_LIT:2> : ] ) <EOL> class CoreTlv ( object ) : <EOL> hdrfmt = "<STR_LIT>" <EOL> hdrsiz = struct . calcsize ( hdrfmt ) <EOL> longhdrfmt = "<STR_LIT>" <EOL> longhdrsiz = struct . calcsize ( longhdrfmt ) <EOL> tlvtypemap = { } <EOL> tlvdataclsmap = { } <EOL> def __init__ ( self , tlvtype , tlvdata ) : <EOL> self . tlvtype = tlvtype <EOL> if tlvdata : <EOL> try : <EOL> self . value = self . tlvdataclsmap [ self . tlvtype ] . unpack ( tlvdata ) <EOL> except KeyError : <EOL> self . value = tlvdata <EOL> else : <EOL> self . value = None <EOL> @ classmethod <EOL> def unpack ( cls , data ) : <EOL> "<STR_LIT>" <EOL> tlvtype , tlvlen = struct . unpack ( cls . hdrfmt , data [ : cls . hdrsiz ] ) <EOL> hdrsiz = cls . hdrsiz <EOL> if tlvlen == <NUM_LIT:0> : <EOL> tlvtype , zero , tlvlen = struct . unpack ( cls . longhdrfmt , <EOL> data [ : cls . longhdrsiz ] ) <EOL> hdrsiz = cls . longhdrsiz <EOL> tlvsiz = hdrsiz + tlvlen <EOL> tlvsiz += - tlvsiz % <NUM_LIT:4> <EOL> return cls ( tlvtype , data [ hdrsiz : tlvsiz ] ) , data [ tlvsiz : ] <EOL> @ classmethod <EOL> def pack ( cls , tlvtype , value ) : <EOL> try : <EOL> tlvlen , tlvdata = cls . tlvdataclsmap [ tlvtype ] . pack ( value ) <EOL> except Exception , e : <EOL> raise ValueError , "<STR_LIT>" % ( tlvtype , e ) <EOL> if tlvlen < <NUM_LIT> : <EOL> hdr = struct . pack ( cls . hdrfmt , tlvtype , tlvlen ) <EOL> else : <EOL> hdr = struct . pack ( cls . longhdrfmt , tlvtype , <NUM_LIT:0> , tlvlen ) <EOL> return hdr + tlvdata <EOL> @ classmethod <EOL> def packstring ( cls , tlvtype , value ) : <EOL> return cls . pack ( tlvtype , cls . tlvdataclsmap [ tlvtype ] . fromstring ( value ) ) <EOL> def typestr ( self ) : <EOL> try : <EOL> return self . tlvtypemap [ self . tlvtype ] <EOL> except KeyError : <EOL> return "<STR_LIT>" % str ( self . tlvtype ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ . __name__ , self . typestr ( ) , self . value ) <EOL> class CoreNodeTlv ( CoreTlv ) : <EOL> tlvtypemap = node_tlvs <EOL> tlvdataclsmap = { <EOL> CORE_TLV_NODE_NUMBER : CoreTlvDataUint32 , <EOL> CORE_TLV_NODE_TYPE : CoreTlvDataUint32 , <EOL> CORE_TLV_NODE_NAME : CoreTlvDataString , <EOL> CORE_TLV_NODE_IPADDR : CoreTlvDataIPv4Addr , <EOL> CORE_TLV_NODE_MACADDR : CoreTlvDataMacAddr , <EOL> CORE_TLV_NODE_IP6ADDR : CoreTlvDataIPv6Addr , <EOL> CORE_TLV_NODE_MODEL : CoreTlvDataString , <EOL> CORE_TLV_NODE_EMUSRV : CoreTlvDataString , <EOL> CORE_TLV_NODE_SESSION : CoreTlvDataString , <EOL> CORE_TLV_NODE_XPOS : CoreTlvDataUint16 , <EOL> CORE_TLV_NODE_YPOS : CoreTlvDataUint16 , <EOL> CORE_TLV_NODE_CANVAS : CoreTlvDataUint16 , <EOL> CORE_TLV_NODE_EMUID : CoreTlvDataUint32 , <EOL> CORE_TLV_NODE_NETID : CoreTlvDataUint32 , <EOL> CORE_TLV_NODE_SERVICES : CoreTlvDataString , <EOL> CORE_TLV_NODE_LAT : CoreTlvDataString , <EOL> CORE_TLV_NODE_LONG : CoreTlvDataString , <EOL> CORE_TLV_NODE_ALT : CoreTlvDataString , <EOL> CORE_TLV_NODE_ICON : CoreTlvDataString , <EOL> CORE_TLV_NODE_OPAQUE : CoreTlvDataString , <EOL> } <EOL> class CoreLinkTlv ( CoreTlv ) : <EOL> tlvtypemap = link_tlvs <EOL> tlvdataclsmap = { <EOL> CORE_TLV_LINK_N1NUMBER : CoreTlvDataUint32 , <EOL> CORE_TLV_LINK_N2NUMBER : CoreTlvDataUint32 , <EOL> CORE_TLV_LINK_DELAY : CoreTlvDataUint64 , <EOL> CORE_TLV_LINK_BW : CoreTlvDataUint64 , <EOL> CORE_TLV_LINK_PER : CoreTlvDataString , <EOL> CORE_TLV_LINK_DUP : CoreTlvDataString , <EOL> CORE_TLV_LINK_JITTER : CoreTlvDataUint64 , <EOL> CORE_TLV_LINK_MER : CoreTlvDataUint16 , <EOL> CORE_TLV_LINK_BURST : CoreTlvDataUint16 , <EOL> CORE_TLV_LINK_SESSION : CoreTlvDataString , <EOL> CORE_TLV_LINK_MBURST : CoreTlvDataUint16 , <EOL> CORE_TLV_LINK_TYPE : CoreTlvDataUint32 , <EOL> CORE_TLV_LINK_GUIATTR : CoreTlvDataString , <EOL> CORE_TLV_LINK_UNI : CoreTlvDataUint16 , <EOL> CORE_TLV_LINK_EMUID : CoreTlvDataUint32 , <EOL> CORE_TLV_LINK_NETID : CoreTlvDataUint32 , <EOL> CORE_TLV_LINK_KEY : CoreTlvDataUint32 , <EOL> CORE_TLV_LINK_IF1NUM : CoreTlvDataUint16 , <EOL> CORE_TLV_LINK_IF1IP4 : CoreTlvDataIPv4Addr , <EOL> CORE_TLV_LINK_IF1IP4MASK : CoreTlvDataUint16 , <EOL> CORE_TLV_LINK_IF1MAC : CoreTlvDataMacAddr , <EOL> CORE_TLV_LINK_IF1IP6 : CoreTlvDataIPv6Addr , <EOL> CORE_TLV_LINK_IF1IP6MASK : CoreTlvDataUint16 , <EOL> CORE_TLV_LINK_IF2NUM : CoreTlvDataUint16 , <EOL> CORE_TLV_LINK_IF2IP4 : CoreTlvDataIPv4Addr , <EOL> CORE_TLV_LINK_IF2IP4MASK : CoreTlvDataUint16 , <EOL> CORE_TLV_LINK_IF2MAC : CoreTlvDataMacAddr , <EOL> CORE_TLV_LINK_IF2IP6 : CoreTlvDataIPv6Addr , <EOL> CORE_TLV_LINK_IF2IP6MASK : CoreTlvDataUint16 , <EOL> CORE_TLV_LINK_IF1NAME : CoreTlvDataString , <EOL> CORE_TLV_LINK_IF2NAME : CoreTlvDataString , <EOL> CORE_TLV_LINK_OPAQUE : CoreTlvDataString , <EOL> } <EOL> class CoreExecTlv ( CoreTlv ) : <EOL> tlvtypemap = exec_tlvs <EOL> tlvdataclsmap = { <EOL> CORE_TLV_EXEC_NODE : CoreTlvDataUint32 , <EOL> CORE_TLV_EXEC_NUM : CoreTlvDataUint32 , <EOL> CORE_TLV_EXEC_TIME : CoreTlvDataUint32 , <EOL> CORE_TLV_EXEC_CMD : CoreTlvDataString , <EOL> CORE_TLV_EXEC_RESULT : CoreTlvDataString , <EOL> CORE_TLV_EXEC_STATUS : CoreTlvDataUint32 , <EOL> CORE_TLV_EXEC_SESSION : CoreTlvDataString , <EOL> } <EOL> class CoreRegTlv ( CoreTlv ) : <EOL> tlvtypemap = reg_tlvs <EOL> tlvdataclsmap = { <EOL> CORE_TLV_REG_WIRELESS : CoreTlvDataString , <EOL> CORE_TLV_REG_MOBILITY : CoreTlvDataString , <EOL> CORE_TLV_REG_UTILITY : CoreTlvDataString , <EOL> CORE_TLV_REG_EXECSRV : CoreTlvDataString , <EOL> CORE_TLV_REG_GUI : CoreTlvDataString , <EOL> CORE_TLV_REG_EMULSRV : CoreTlvDataString , <EOL> CORE_TLV_REG_SESSION : CoreTlvDataString , <EOL> } <EOL> class CoreConfTlv ( CoreTlv ) : <EOL> tlvtypemap = conf_tlvs <EOL> tlvdataclsmap = { <EOL> CORE_TLV_CONF_NODE : CoreTlvDataUint32 , <EOL> CORE_TLV_CONF_OBJ : CoreTlvDataString , <EOL> CORE_TLV_CONF_TYPE : CoreTlvDataUint16 , <EOL> CORE_TLV_CONF_DATA_TYPES : CoreTlvDataUint16List , <EOL> CORE_TLV_CONF_VALUES : CoreTlvDataString , <EOL> CORE_TLV_CONF_CAPTIONS : CoreTlvDataString , <EOL> CORE_TLV_CONF_BITMAP : CoreTlvDataString , <EOL> CORE_TLV_CONF_POSSIBLE_VALUES : CoreTlvDataString , <EOL> CORE_TLV_CONF_GROUPS : CoreTlvDataString , <EOL> CORE_TLV_CONF_SESSION : CoreTlvDataString , <EOL> CORE_TLV_CONF_IFNUM : CoreTlvDataUint16 , <EOL> CORE_TLV_CONF_NETID : CoreTlvDataUint32 , <EOL> CORE_TLV_CONF_OPAQUE : CoreTlvDataString , <EOL> } <EOL> class CoreFileTlv ( CoreTlv ) : <EOL> tlvtypemap = file_tlvs <EOL> tlvdataclsmap = { <EOL> CORE_TLV_FILE_NODE : CoreTlvDataUint32 , <EOL> CORE_TLV_FILE_NAME : CoreTlvDataString , <EOL> CORE_TLV_FILE_MODE : CoreTlvDataString , <EOL> CORE_TLV_FILE_NUM : CoreTlvDataUint16 , <EOL> CORE_TLV_FILE_TYPE : CoreTlvDataString , <EOL> CORE_TLV_FILE_SRCNAME : CoreTlvDataString , <EOL> CORE_TLV_FILE_SESSION : CoreTlvDataString , <EOL> CORE_TLV_FILE_DATA : CoreTlvDataString , <EOL> CORE_TLV_FILE_CMPDATA : CoreTlvDataString , <EOL> } <EOL> class CoreIfaceTlv ( CoreTlv ) : <EOL> tlvtypemap = iface_tlvs <EOL> tlvdataclsmap = { <EOL> CORE_TLV_IFACE_NODE : CoreTlvDataUint32 , <EOL> CORE_TLV_IFACE_NUM : CoreTlvDataUint16 , <EOL> CORE_TLV_IFACE_NAME : CoreTlvDataString , <EOL> CORE_TLV_IFACE_IPADDR : CoreTlvDataIPv4Addr , <EOL> CORE_TLV_IFACE_MASK : CoreTlvDataUint16 , <EOL> CORE_TLV_IFACE_MACADDR : CoreTlvDataMacAddr , <EOL> CORE_TLV_IFACE_IP6ADDR : CoreTlvDataIPv6Addr , <EOL> CORE_TLV_IFACE_IP6MASK : CoreTlvDataUint16 , <EOL> CORE_TLV_IFACE_TYPE : CoreTlvDataUint16 , <EOL> CORE_TLV_IFACE_SESSION : CoreTlvDataString , <EOL> CORE_TLV_IFACE_STATE : CoreTlvDataUint16 , <EOL> CORE_TLV_IFACE_EMUID : CoreTlvDataUint32 , <EOL> CORE_TLV_IFACE_NETID : CoreTlvDataUint32 , <EOL> } <EOL> class CoreEventTlv ( CoreTlv ) : <EOL> tlvtypemap = event_tlvs <EOL> tlvdataclsmap = { <EOL> CORE_TLV_EVENT_NODE : CoreTlvDataUint32 , <EOL> CORE_TLV_EVENT_TYPE : CoreTlvDataUint32 , <EOL> CORE_TLV_EVENT_NAME : CoreTlvDataString , <EOL> CORE_TLV_EVENT_DATA : CoreTlvDataString , <EOL> CORE_TLV_EVENT_TIME : CoreTlvDataString , <EOL> CORE_TLV_EVENT_SESSION : CoreTlvDataString , <EOL> } <EOL> class CoreSessionTlv ( CoreTlv ) : <EOL> tlvtypemap = session_tlvs <EOL> tlvdataclsmap = { <EOL> CORE_TLV_SESS_NUMBER : CoreTlvDataString , <EOL> CORE_TLV_SESS_NAME : CoreTlvDataString , <EOL> CORE_TLV_SESS_FILE : CoreTlvDataString , <EOL> CORE_TLV_SESS_NODECOUNT : CoreTlvDataString , <EOL> CORE_TLV_SESS_DATE : CoreTlvDataString , <EOL> CORE_TLV_SESS_THUMB : CoreTlvDataString , <EOL> CORE_TLV_SESS_USER : CoreTlvDataString , <EOL> CORE_TLV_SESS_OPAQUE : CoreTlvDataString , <EOL> } <EOL> class CoreExceptionTlv ( CoreTlv ) : <EOL> tlvtypemap = exception_tlvs <EOL> tlvdataclsmap = { <EOL> CORE_TLV_EXCP_NODE : CoreTlvDataUint32 , <EOL> CORE_TLV_EXCP_SESSION : CoreTlvDataString , <EOL> CORE_TLV_EXCP_LEVEL : CoreTlvDataUint16 , <EOL> CORE_TLV_EXCP_SOURCE : CoreTlvDataString , <EOL> CORE_TLV_EXCP_DATE : CoreTlvDataString , <EOL> CORE_TLV_EXCP_TEXT : CoreTlvDataString , <EOL> CORE_TLV_EXCP_OPAQUE : CoreTlvDataString , <EOL> } <EOL> class CoreMessage ( object ) : <EOL> hdrfmt = "<STR_LIT>" <EOL> hdrsiz = struct . calcsize ( hdrfmt ) <EOL> msgtype = None <EOL> flagmap = { } <EOL> tlvcls = CoreTlv <EOL> def __init__ ( self , flags , hdr , data ) : <EOL> self . rawmsg = hdr + data <EOL> self . flags = flags <EOL> self . tlvdata = { } <EOL> self . parsedata ( data ) <EOL> @ classmethod <EOL> def unpackhdr ( cls , data ) : <EOL> "<STR_LIT>" <EOL> msgtype , msgflags , msglen = struct . unpack ( cls . hdrfmt , data [ : cls . hdrsiz ] ) <EOL> return msgtype , msgflags , msglen <EOL> @ classmethod <EOL> def pack ( cls , msgflags , tlvdata ) : <EOL> hdr = struct . pack ( cls . hdrfmt , cls . msgtype , msgflags , len ( tlvdata ) ) <EOL> return hdr + tlvdata <EOL> def addtlvdata ( self , k , v ) : <EOL> if k in self . tlvdata : <EOL> raise KeyError , "<STR_LIT>" % ( k , v ) <EOL> self . tlvdata [ k ] = v <EOL> def gettlv ( self , tlvtype ) : <EOL> if tlvtype in self . tlvdata : <EOL> return self . tlvdata [ tlvtype ] <EOL> else : <EOL> return None <EOL> def parsedata ( self , data ) : <EOL> while data : <EOL> tlv , data = self . tlvcls . unpack ( data ) <EOL> self . addtlvdata ( tlv . tlvtype , tlv . value ) <EOL> def packtlvdata ( self ) : <EOL> '''<STR_LIT>''' <EOL> tlvdata = "<STR_LIT>" <EOL> keys = sorted ( self . tlvdata . keys ( ) ) <EOL> for k in keys : <EOL> v = self . tlvdata [ k ] <EOL> tlvdata += self . tlvcls . pack ( k , v ) <EOL> return tlvdata <EOL> def repack ( self ) : <EOL> '''<STR_LIT>''' <EOL> tlvdata = self . packtlvdata ( ) <EOL> self . rawmsg = self . pack ( self . flags , tlvdata ) <EOL> def typestr ( self ) : <EOL> try : <EOL> return message_types [ self . msgtype ] <EOL> except KeyError : <EOL> return "<STR_LIT>" % str ( self . msgtype ) <EOL> def flagstr ( self ) : <EOL> msgflags = [ ] <EOL> flag = <NUM_LIT:1> L <EOL> while True : <EOL> if ( self . flags & flag ) : <EOL> try : <EOL> msgflags . append ( self . flagmap [ flag ] ) <EOL> except KeyError : <EOL> msgflags . append ( "<STR_LIT>" % flag ) <EOL> flag <<= <NUM_LIT:1> <EOL> if not ( self . flags & ~ ( flag - <NUM_LIT:1> ) ) : <EOL> break <EOL> return "<STR_LIT>" % ( self . flags , "<STR_LIT>" . join ( msgflags ) ) <EOL> def __str__ ( self ) : <EOL> tmp = "<STR_LIT>" % ( self . __class__ . __name__ , self . typestr ( ) , self . flagstr ( ) ) <EOL> for k , v in self . tlvdata . iteritems ( ) : <EOL> if k in self . tlvcls . tlvtypemap : <EOL> tlvtype = self . tlvcls . tlvtypemap [ k ] <EOL> else : <EOL> tlvtype = "<STR_LIT>" % k <EOL> tmp += "<STR_LIT>" % ( tlvtype , v ) <EOL> return tmp <EOL> def nodenumbers ( self ) : <EOL> '''<STR_LIT>''' <EOL> n = None <EOL> n2 = None <EOL> if self . msgtype == CORE_API_NODE_MSG : <EOL> n = self . gettlv ( CORE_TLV_NODE_NUMBER ) <EOL> elif self . msgtype == CORE_API_LINK_MSG : <EOL> n = self . gettlv ( CORE_TLV_LINK_N1NUMBER ) <EOL> n2 = self . gettlv ( CORE_TLV_LINK_N2NUMBER ) <EOL> elif self . msgtype == CORE_API_EXEC_MSG : <EOL> n = self . gettlv ( CORE_TLV_EXEC_NODE ) <EOL> elif self . msgtype == CORE_API_CONF_MSG : <EOL> n = self . gettlv ( CORE_TLV_CONF_NODE ) <EOL> elif self . msgtype == CORE_API_FILE_MSG : <EOL> n = self . gettlv ( CORE_TLV_FILE_NODE ) <EOL> elif self . msgtype == CORE_API_IFACE_MSG : <EOL> n = self . gettlv ( CORE_TLV_IFACE_NODE ) <EOL> elif self . msgtype == CORE_API_EVENT_MSG : <EOL> n = self . gettlv ( CORE_TLV_EVENT_NODE ) <EOL> r = [ ] <EOL> if n is not None : <EOL> r . append ( n ) <EOL> if n2 is not None : <EOL> r . append ( n2 ) <EOL> return r <EOL> def sessionnumbers ( self ) : <EOL> '''<STR_LIT>''' <EOL> r = [ ] <EOL> if self . msgtype == CORE_API_SESS_MSG : <EOL> s = self . gettlv ( CORE_TLV_SESS_NUMBER ) <EOL> elif self . msgtype == CORE_API_EXCP_MSG : <EOL> s = self . gettlv ( CORE_TLV_EXCP_SESSION ) <EOL> else : <EOL> s = self . gettlv ( CORE_TLV_NODE_SESSION ) <EOL> if s is not None : <EOL> for sid in s . split ( '<STR_LIT:|>' ) : <EOL> r . append ( int ( sid ) ) <EOL> return r <EOL> class CoreNodeMessage ( CoreMessage ) : <EOL> msgtype = CORE_API_NODE_MSG <EOL> flagmap = message_flags <EOL> tlvcls = CoreNodeTlv <EOL> class CoreLinkMessage ( CoreMessage ) : <EOL> msgtype = CORE_API_LINK_MSG <EOL> flagmap = message_flags <EOL> tlvcls = CoreLinkTlv <EOL> class CoreExecMessage ( CoreMessage ) : <EOL> msgtype = CORE_API_EXEC_MSG <EOL> flagmap = message_flags <EOL> tlvcls = CoreExecTlv <EOL> class CoreRegMessage ( CoreMessage ) : <EOL> msgtype = CORE_API_REG_MSG <EOL> flagmap = message_flags <EOL> tlvcls = CoreRegTlv <EOL> class CoreConfMessage ( CoreMessage ) : <EOL> msgtype = CORE_API_CONF_MSG <EOL> flagmap = message_flags <EOL> tlvcls = CoreConfTlv <EOL> class CoreFileMessage ( CoreMessage ) : <EOL> msgtype = CORE_API_FILE_MSG <EOL> flagmap = message_flags <EOL> tlvcls = CoreFileTlv <EOL> class CoreIfaceMessage ( CoreMessage ) : <EOL> msgtype = CORE_API_IFACE_MSG <EOL> flagmap = message_flags <EOL> tlvcls = CoreIfaceTlv <EOL> class CoreEventMessage ( CoreMessage ) : <EOL> msgtype = CORE_API_EVENT_MSG <EOL> flagmap = message_flags <EOL> tlvcls = CoreEventTlv <EOL> class CoreSessionMessage ( CoreMessage ) : <EOL> msgtype = CORE_API_SESS_MSG <EOL> flagmap = message_flags <EOL> tlvcls = CoreSessionTlv <EOL> class CoreExceptionMessage ( CoreMessage ) : <EOL> msgtype = CORE_API_EXCP_MSG <EOL> flagmap = message_flags <EOL> tlvcls = CoreExceptionTlv <EOL> msgclsmap = { <EOL> CORE_API_NODE_MSG : CoreNodeMessage , <EOL> CORE_API_LINK_MSG : CoreLinkMessage , <EOL> CORE_API_EXEC_MSG : CoreExecMessage , <EOL> CORE_API_REG_MSG : CoreRegMessage , <EOL> CORE_API_CONF_MSG : CoreConfMessage , <EOL> CORE_API_FILE_MSG : CoreFileMessage , <EOL> CORE_API_IFACE_MSG : CoreIfaceMessage , <EOL> CORE_API_EVENT_MSG : CoreEventMessage , <EOL> CORE_API_SESS_MSG : CoreSessionMessage , <EOL> CORE_API_EXCP_MSG : CoreExceptionMessage , <EOL> } <EOL> def msg_class ( msgtypeid ) : <EOL> global msgclsmap <EOL> return msgclsmap [ msgtypeid ] <EOL> nodeclsmap = { } <EOL> def add_node_class ( name , nodetypeid , nodecls , change = False ) : <EOL> global nodeclsmap <EOL> if nodetypeid in nodeclsmap : <EOL> if not change : <EOL> raise ValueError , "<STR_LIT>" % nodetypeid <EOL> nodeclsmap [ nodetypeid ] = nodecls <EOL> if nodetypeid not in node_types : <EOL> node_types [ nodetypeid ] = name <EOL> exec "<STR_LIT>" % ( name , nodetypeid ) in globals ( ) <EOL> elif name != node_types [ nodetypeid ] : <EOL> raise ValueError , "<STR_LIT>" % name <EOL> else : <EOL> pass <EOL> def change_node_class ( name , nodetypeid , nodecls ) : <EOL> return add_node_class ( name , nodetypeid , nodecls , change = True ) <EOL> def node_class ( nodetypeid ) : <EOL> global nodeclsmap <EOL> return nodeclsmap [ nodetypeid ] <EOL> def str_to_list ( s ) : <EOL> '''<STR_LIT>''' <EOL> if s is None : <EOL> return None <EOL> return s . split ( "<STR_LIT:|>" ) <EOL> def state_name ( n ) : <EOL> '''<STR_LIT>''' <EOL> if n in event_types : <EOL> eventname = event_types [ n ] <EOL> name = eventname . split ( '<STR_LIT:_>' ) [ <NUM_LIT:2> ] <EOL> else : <EOL> name = "<STR_LIT>" <EOL> return name </s>
