mirror of
https://github.com/espressif/openthread.git
synced 2026-08-11 13:17:48 +00:00
[style] change python yapf column_limit to 119 (#5339)
This commit is contained in:
@@ -73,8 +73,7 @@ class Message(object):
|
||||
self._type = MessageType.MLE
|
||||
self._mle = udp_datagram.payload
|
||||
|
||||
elif isinstance(udp_datagram.payload,
|
||||
(coap.CoapMessage, coap.CoapMessageProxy)):
|
||||
elif isinstance(udp_datagram.payload, (coap.CoapMessage, coap.CoapMessageProxy)):
|
||||
self._type = MessageType.COAP
|
||||
self._coap = udp_datagram.payload
|
||||
|
||||
@@ -149,12 +148,10 @@ class Message(object):
|
||||
|
||||
elif self._mac_header.frame_type == mac802154.MacHeader.FrameType.DATA:
|
||||
self._type = MessageType.DATA
|
||||
elif (self._mac_header.frame_type ==
|
||||
mac802154.MacHeader.FrameType.COMMAND):
|
||||
elif (self._mac_header.frame_type == mac802154.MacHeader.FrameType.COMMAND):
|
||||
self._type = MessageType.COMMAND
|
||||
else:
|
||||
raise ValueError('Invalid mac frame type %d' %
|
||||
self._mac_header.frame_type)
|
||||
raise ValueError('Invalid mac frame type %d' % self._mac_header.frame_type)
|
||||
|
||||
@property
|
||||
def ipv6_packet(self):
|
||||
@@ -260,8 +257,7 @@ class Message(object):
|
||||
if contains_tlv:
|
||||
print("MleMessage contains optional TLV: {}".format(tlv_class_type))
|
||||
else:
|
||||
print("MleMessage doesn't contain optional TLV: {}".format(
|
||||
tlv_class_type))
|
||||
print("MleMessage doesn't contain optional TLV: {}".format(tlv_class_type))
|
||||
|
||||
def get_coap_message_tlv(self, tlv_class_type):
|
||||
if self.type != MessageType.COAP:
|
||||
@@ -303,8 +299,7 @@ class Message(object):
|
||||
if isinstance(tlv, tlv_class_type):
|
||||
break
|
||||
|
||||
print("CoapMessage doesn't contain optional TLV: {}".format(
|
||||
tlv_class_type))
|
||||
print("CoapMessage doesn't contain optional TLV: {}".format(tlv_class_type))
|
||||
|
||||
def assertCoapMessageRequestUriPath(self, uri_path):
|
||||
if self.type != MessageType.COAP:
|
||||
@@ -332,20 +327,17 @@ class Message(object):
|
||||
sent_to_node = True
|
||||
|
||||
elif self.mac_header.dest_address.type == common.MacAddressType.LONG:
|
||||
mac_address = common.MacAddress.from_eui64(
|
||||
bytearray(node.get_addr64(), encoding="utf-8"))
|
||||
mac_address = common.MacAddress.from_eui64(bytearray(node.get_addr64(), encoding="utf-8"))
|
||||
if self.mac_header.dest_address == mac_address:
|
||||
sent_to_node = True
|
||||
|
||||
assert sent_to_node
|
||||
|
||||
def assertSentToDestinationAddress(self, ipv6_address):
|
||||
assert (self.ipv6_packet.ipv6_header.destination_address ==
|
||||
ipaddress.ip_address(ipv6_address))
|
||||
assert (self.ipv6_packet.ipv6_header.destination_address == ipaddress.ip_address(ipv6_address))
|
||||
|
||||
def assertSentFromSourceAddress(self, ipv6_address):
|
||||
assert (self.ipv6_packet.ipv6_header.source_address ==
|
||||
ipaddress.ip_address(ipv6_address))
|
||||
assert (self.ipv6_packet.ipv6_header.source_address == ipaddress.ip_address(ipv6_address))
|
||||
|
||||
def assertSentWithHopLimit(self, hop_limit):
|
||||
assert self.ipv6_packet.ipv6_header.hop_limit == hop_limit
|
||||
@@ -354,8 +346,7 @@ class Message(object):
|
||||
return self.mac_header.dest_address.type == common.MacAddressType.LONG
|
||||
|
||||
def get_dst_udp_port(self):
|
||||
assert isinstance(self.ipv6_packet.upper_layer_protocol,
|
||||
ipv6.UDPDatagram)
|
||||
assert isinstance(self.ipv6_packet.upper_layer_protocol, ipv6.UDPDatagram)
|
||||
return self.ipv6_packet.upper_layer_protocol.header.dst_port
|
||||
|
||||
def is_data_poll(self):
|
||||
@@ -363,8 +354,7 @@ class Message(object):
|
||||
self._mac_header.command_type == mac802154.MacHeader.CommandIdentifier.DATA_REQUEST
|
||||
|
||||
def __repr__(self):
|
||||
if (self.type == MessageType.DTLS and
|
||||
self.dtls.content_type == dtls.ContentType.HANDSHAKE):
|
||||
if (self.type == MessageType.DTLS and self.dtls.content_type == dtls.ContentType.HANDSHAKE):
|
||||
return "Message(type={})".format(str(self.dtls.handshake_type))
|
||||
return "Message(type={})".format(MessageType(self.type).name)
|
||||
|
||||
@@ -411,8 +401,7 @@ class MessagesSet(object):
|
||||
break
|
||||
|
||||
if assert_enabled:
|
||||
assert (message is not None
|
||||
), "Could not find CoapMessage with code: {}".format(code)
|
||||
assert (message is not None), "Could not find CoapMessage with code: {}".format(code)
|
||||
|
||||
return message
|
||||
|
||||
@@ -441,22 +430,15 @@ class MessagesSet(object):
|
||||
break
|
||||
|
||||
if assert_enabled:
|
||||
assert (
|
||||
message is not None
|
||||
), "Could not find MleMessage with type: {}".format(command_type)
|
||||
assert (message is not None), "Could not find MleMessage with type: {}".format(command_type)
|
||||
|
||||
return message
|
||||
|
||||
def next_mle_message(self,
|
||||
command_type,
|
||||
assert_enabled=True,
|
||||
sent_to_node=None):
|
||||
def next_mle_message(self, command_type, assert_enabled=True, sent_to_node=None):
|
||||
message = self.next_mle_message_of_one_of_command_types(command_type)
|
||||
|
||||
if assert_enabled:
|
||||
assert (
|
||||
message is not None
|
||||
), "Could not find MleMessage of the type: {}".format(command_type)
|
||||
assert (message is not None), "Could not find MleMessage of the type: {}".format(command_type)
|
||||
|
||||
if sent_to_node is not None:
|
||||
message.assertSentToNode(sent_to_node)
|
||||
@@ -503,9 +485,7 @@ class MessagesSet(object):
|
||||
break
|
||||
|
||||
if assert_enabled:
|
||||
assert (
|
||||
message is not None
|
||||
), "Could not find Message of the type: {}".format(message_type)
|
||||
assert (message is not None), "Could not find Message of the type: {}".format(message_type)
|
||||
|
||||
return message
|
||||
|
||||
@@ -522,15 +502,12 @@ class MessagesSet(object):
|
||||
continue
|
||||
if msg.dtls.content_type != content_type:
|
||||
continue
|
||||
if (content_type == dtls.ContentType.HANDSHAKE and
|
||||
msg.dtls.handshake_type != handshake_type):
|
||||
if (content_type == dtls.ContentType.HANDSHAKE and msg.dtls.handshake_type != handshake_type):
|
||||
continue
|
||||
return msg
|
||||
|
||||
t = (handshake_type
|
||||
if content_type == dtls.ContentType.HANDSHAKE else content_type)
|
||||
raise ValueError("Could not find DTLS message of type: {}".format(
|
||||
str(t)))
|
||||
t = (handshake_type if content_type == dtls.ContentType.HANDSHAKE else content_type)
|
||||
raise ValueError("Could not find DTLS message of type: {}".format(str(t)))
|
||||
|
||||
def contains_icmp_message(self):
|
||||
for m in self.messages:
|
||||
@@ -586,12 +563,10 @@ class MessageFactory:
|
||||
for tlv in message.mle.command.tlvs:
|
||||
|
||||
if isinstance(tlv, mle.SourceAddress):
|
||||
mac802154.DeviceDescriptors.add(tlv.address,
|
||||
message.mac_header.src_address)
|
||||
mac802154.DeviceDescriptors.add(tlv.address, message.mac_header.src_address)
|
||||
|
||||
if isinstance(tlv, mle.Address16):
|
||||
mac802154.DeviceDescriptors.add(tlv.address,
|
||||
message.mac_header.dest_address)
|
||||
mac802154.DeviceDescriptors.add(tlv.address, message.mac_header.dest_address)
|
||||
|
||||
def _parse_mac_frame(self, data):
|
||||
mac_frame = mac802154.MacFrame()
|
||||
@@ -620,8 +595,7 @@ class MessageFactory:
|
||||
# Create stream with 6LoWPAN datagram
|
||||
lowpan_payload = io.BytesIO(mac_frame.payload.data)
|
||||
|
||||
ipv6_packet = self._lowpan_parser.parse(lowpan_payload,
|
||||
message_info)
|
||||
ipv6_packet = self._lowpan_parser.parse(lowpan_payload, message_info)
|
||||
if ipv6_packet is None:
|
||||
return [message]
|
||||
|
||||
@@ -633,7 +607,5 @@ class MessageFactory:
|
||||
return message.try_extract_dtls_messages()
|
||||
|
||||
except mac802154.KeyIdMode0Exception:
|
||||
print(
|
||||
'Received packet with key_id_mode = 0, cannot be handled in test scripts'
|
||||
)
|
||||
print('Received packet with key_id_mode = 0, cannot be handled in test scripts')
|
||||
raise DropPacketException
|
||||
|
||||
Reference in New Issue
Block a user