Return none instead of throwing exception when no data is read

pull/8/head
Nicolas Jouanin 2015-06-24 23:19:11 +02:00
rodzic cc0454d335
commit b3ba2ccedb
1 zmienionych plików z 10 dodań i 7 usunięć

Wyświetl plik

@ -110,6 +110,7 @@ class MQTTFixedHeader:
raise MQTTException("Invalid remaining length bytes:%s" % bytes_to_hex_str(length_bytes))
return value
try:
b1 = yield from read_or_raise(reader, 1)
msg_type = decode_message_type(b1)
if msg_type is PacketType.RESERVED_0 or msg_type is PacketType.RESERVED_15:
@ -118,6 +119,8 @@ class MQTTFixedHeader:
remain_length = yield from decode_remaining_length()
return cls(msg_type, flags, remain_length)
except NoDataException:
return None
def __repr__(self):
return type(self).__name__ + '(type={0}, length={1}, flags={2})'.format(self.packet_type, self.remaining_length, hex(self.flags))