updates to support 2/3 along with not using vcmd c extension
This commit is contained in:
parent
864c7b69a1
commit
ecc63f4abb
22 changed files with 680 additions and 636 deletions
|
@ -692,7 +692,7 @@ class CoreBroker(object):
|
|||
|
||||
# send a Configuration message for the broker object and inform the
|
||||
# server of its local name
|
||||
tlvdata = ""
|
||||
tlvdata = b""
|
||||
tlvdata += coreapi.CoreConfigTlv.pack(ConfigTlvs.OBJECT.value, "broker")
|
||||
tlvdata += coreapi.CoreConfigTlv.pack(ConfigTlvs.TYPE.value, ConfigFlags.UPDATE.value)
|
||||
tlvdata += coreapi.CoreConfigTlv.pack(ConfigTlvs.DATA_TYPES.value, (ConfigDataTypes.STRING.value,))
|
||||
|
@ -722,7 +722,7 @@ class CoreBroker(object):
|
|||
cmd = msg.get_tlv(ExecuteTlvs.COMMAND.value)
|
||||
res = msg.get_tlv(ExecuteTlvs.RESULT.value)
|
||||
|
||||
tlvdata = ""
|
||||
tlvdata = b""
|
||||
tlvdata += coreapi.CoreExecuteTlv.pack(ExecuteTlvs.NODE.value, nodenum)
|
||||
tlvdata += coreapi.CoreExecuteTlv.pack(ExecuteTlvs.NUMBER.value, execnum)
|
||||
tlvdata += coreapi.CoreExecuteTlv.pack(ExecuteTlvs.COMMAND.value, cmd)
|
||||
|
@ -1029,7 +1029,7 @@ class CoreBroker(object):
|
|||
server.instantiation_complete = True
|
||||
|
||||
# broadcast out instantiate complete
|
||||
tlvdata = ""
|
||||
tlvdata = b""
|
||||
tlvdata += coreapi.CoreEventTlv.pack(EventTlvs.TYPE.value, EventTypes.INSTANTIATION_COMPLETE.value)
|
||||
message = coreapi.CoreEventMessage.pack(0, tlvdata)
|
||||
for session_client in self.session_clients:
|
||||
|
|
|
@ -157,7 +157,7 @@ class CoreTlvDataUint64(CoreTlvData):
|
|||
Helper class for packing uint64 data.
|
||||
"""
|
||||
data_format = "!2xQ"
|
||||
data_type = long
|
||||
data_type = int
|
||||
pad_len = 2
|
||||
|
||||
|
||||
|
@ -178,6 +178,7 @@ class CoreTlvDataString(CoreTlvData):
|
|||
"""
|
||||
if not isinstance(value, str):
|
||||
raise ValueError("value not a string: %s" % value)
|
||||
value = value.encode("utf-8")
|
||||
|
||||
if len(value) < 256:
|
||||
header_len = CoreTlv.header_len
|
||||
|
@ -185,7 +186,7 @@ class CoreTlvDataString(CoreTlvData):
|
|||
header_len = CoreTlv.long_header_len
|
||||
|
||||
pad_len = -(header_len + len(value)) % 4
|
||||
return len(value), value + "\0" * pad_len
|
||||
return len(value), value + b"\0" * pad_len
|
||||
|
||||
@classmethod
|
||||
def unpack(cls, data):
|
||||
|
@ -195,7 +196,7 @@ class CoreTlvDataString(CoreTlvData):
|
|||
:param str data: unpack string data
|
||||
:return: unpacked string data
|
||||
"""
|
||||
return data.rstrip("\0")
|
||||
return data.rstrip(b"\0").decode("utf-8")
|
||||
|
||||
|
||||
class CoreTlvDataUint16List(CoreTlvData):
|
||||
|
@ -266,7 +267,7 @@ class CoreTlvDataIpv4Addr(CoreTlvDataObj):
|
|||
return obj.addr
|
||||
|
||||
@staticmethod
|
||||
def new_obj(obj):
|
||||
def new_obj(value):
|
||||
"""
|
||||
Retrieve Ipv4 address from a string representation.
|
||||
|
||||
|
@ -274,7 +275,9 @@ class CoreTlvDataIpv4Addr(CoreTlvDataObj):
|
|||
:return: Ipv4 address
|
||||
:rtype: core.misc.ipaddress.IpAddress
|
||||
"""
|
||||
return IpAddress(af=socket.AF_INET, address=obj)
|
||||
# value = value.decode("ISO-8859-1")
|
||||
# value = socket.inet_ntoa(value)
|
||||
return IpAddress(af=socket.AF_INET, address=value)
|
||||
|
||||
|
||||
class CoreTlvDataIPv6Addr(CoreTlvDataObj):
|
||||
|
@ -304,6 +307,8 @@ class CoreTlvDataIPv6Addr(CoreTlvDataObj):
|
|||
:return: Ipv4 address
|
||||
:rtype: core.misc.ipaddress.IpAddress
|
||||
"""
|
||||
# value = value.decode("ISO-8859-1")
|
||||
# value = socket.inet_ntoa(value)
|
||||
return IpAddress(af=socket.AF_INET6, address=value)
|
||||
|
||||
|
||||
|
@ -336,6 +341,8 @@ class CoreTlvDataMacAddr(CoreTlvDataObj):
|
|||
:rtype: core.misc.ipaddress.MacAddress
|
||||
"""
|
||||
# only use 48 bits
|
||||
# value = value.decode("ISO-8859-1")
|
||||
# value = socket.inet_ntoa(value)
|
||||
return MacAddress(address=value[2:])
|
||||
|
||||
|
||||
|
@ -397,12 +404,10 @@ class CoreTlv(object):
|
|||
:return: header and packed data
|
||||
"""
|
||||
tlv_len, tlv_data = cls.tlv_data_class_map[tlv_type].pack(value)
|
||||
|
||||
if tlv_len < 256:
|
||||
hdr = struct.pack(cls.header_format, tlv_type, tlv_len)
|
||||
else:
|
||||
hdr = struct.pack(cls.long_header_format, tlv_type, 0, tlv_len)
|
||||
|
||||
return hdr + tlv_data
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -190,7 +190,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
thumbs = "|".join(thumb_list)
|
||||
|
||||
if num_sessions > 0:
|
||||
tlv_data = ""
|
||||
tlv_data = b""
|
||||
if len(session_ids) > 0:
|
||||
tlv_data += coreapi.CoreSessionTlv.pack(SessionTlvs.NUMBER.value, session_ids)
|
||||
if len(names) > 0:
|
||||
|
@ -224,7 +224,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
(EventTlvs.NAME, event_data.name),
|
||||
(EventTlvs.DATA, event_data.data),
|
||||
(EventTlvs.TIME, event_data.time),
|
||||
(EventTlvs.TIME, event_data.session)
|
||||
(EventTlvs.SESSION, event_data.session)
|
||||
])
|
||||
message = coreapi.CoreEventMessage.pack(0, tlv_data)
|
||||
|
||||
|
@ -373,7 +373,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
"""
|
||||
logging.info("GUI has connected to session %d at %s", self.session.id, time.ctime())
|
||||
|
||||
tlv_data = ""
|
||||
tlv_data = b""
|
||||
tlv_data += coreapi.CoreRegisterTlv.pack(RegisterTlvs.EXECUTE_SERVER.value, "core-daemon")
|
||||
tlv_data += coreapi.CoreRegisterTlv.pack(RegisterTlvs.EMULATION_SERVER.value, "core-daemon")
|
||||
tlv_data += coreapi.CoreRegisterTlv.pack(self.session.broker.config_type, self.session.broker.name)
|
||||
|
@ -424,7 +424,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
if message_len == 0:
|
||||
logging.warn("received message with no data")
|
||||
|
||||
data = ""
|
||||
data = b""
|
||||
while len(data) < message_len:
|
||||
data += self.request.recv(message_len - len(data))
|
||||
if len(data) > message_len:
|
||||
|
@ -504,7 +504,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
:param message: message for replies
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("dispatching replies")
|
||||
logging.debug("dispatching replies: %s", replies)
|
||||
for reply in replies:
|
||||
message_type, message_flags, message_length = coreapi.CoreMessage.unpack_header(reply)
|
||||
try:
|
||||
|
@ -682,7 +682,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
|
||||
# if we deleted a node broadcast out its removal
|
||||
if result and message.flags & MessageFlags.STRING.value:
|
||||
tlvdata = ""
|
||||
tlvdata = b""
|
||||
tlvdata += coreapi.CoreNodeTlv.pack(NodeTlvs.NUMBER.value, node_id)
|
||||
flags = MessageFlags.DELETE.value | MessageFlags.LOCAL.value
|
||||
replies.append(coreapi.CoreNodeMessage.pack(flags, tlvdata))
|
||||
|
@ -779,7 +779,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
node = self.session.get_node(node_num)
|
||||
|
||||
# build common TLV items for reply
|
||||
tlv_data = ""
|
||||
tlv_data = b""
|
||||
if node_num is not None:
|
||||
tlv_data += coreapi.CoreExecuteTlv.pack(ExecuteTlvs.NODE.value, node_num)
|
||||
tlv_data += coreapi.CoreExecuteTlv.pack(ExecuteTlvs.NUMBER.value, execute_num)
|
||||
|
@ -1667,7 +1667,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
:return: nothing
|
||||
"""
|
||||
if node_id in self.node_status_request:
|
||||
tlv_data = ""
|
||||
tlv_data = b""
|
||||
tlv_data += coreapi.CoreNodeTlv.pack(NodeTlvs.NUMBER.value, node_id)
|
||||
tlv_data += coreapi.CoreNodeTlv.pack(NodeTlvs.EMULATION_ID.value, node_id)
|
||||
reply = coreapi.CoreNodeMessage.pack(MessageFlags.ADD.value | MessageFlags.LOCAL.value, tlv_data)
|
||||
|
|
|
@ -15,7 +15,8 @@ def pack_values(clazz, packers):
|
|||
"""
|
||||
|
||||
# iterate through tuples of values to pack
|
||||
data = ""
|
||||
logging.debug("packing: %s", packers)
|
||||
data = b""
|
||||
for packer in packers:
|
||||
# check if a transformer was provided for valid values
|
||||
transformer = None
|
||||
|
@ -26,10 +27,6 @@ def pack_values(clazz, packers):
|
|||
else:
|
||||
raise RuntimeError("packer had more than 3 arguments")
|
||||
|
||||
# convert unicode to normal str for packing
|
||||
if isinstance(value, unicode):
|
||||
value = str(value)
|
||||
|
||||
# only pack actual values and avoid packing empty strings
|
||||
# protobuf defaults to empty strings and does no imply a value to set
|
||||
if value is None or (isinstance(value, str) and not value):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue