rename HBMQTT base exception to AMQTT

pull/80/head
Florian Ludwig 2021-07-31 19:52:13 +02:00
rodzic 4faf762292
commit f0cf7be59f
19 zmienionych plików z 43 dodań i 43 usunięć

Wyświetl plik

@ -15,7 +15,7 @@ from functools import partial
from transitions import Machine, MachineError from transitions import Machine, MachineError
from amqtt.session import Session from amqtt.session import Session
from amqtt.mqtt.protocol.broker_handler import BrokerProtocolHandler from amqtt.mqtt.protocol.broker_handler import BrokerProtocolHandler
from amqtt.errors import HBMQTTException, MQTTException from amqtt.errors import AMQTTException, MQTTException
from amqtt.utils import format_client_message, gen_client_id from amqtt.utils import format_client_message, gen_client_id
from amqtt.adapters import ( from amqtt.adapters import (
StreamReaderAdapter, StreamReaderAdapter,
@ -422,7 +422,7 @@ class Broker:
handler, client_session = await BrokerProtocolHandler.init_from_connect( handler, client_session = await BrokerProtocolHandler.init_from_connect(
reader, writer, self.plugins_manager, loop=self._loop reader, writer, self.plugins_manager, loop=self._loop
) )
except HBMQTTException as exc: except AMQTTException as exc:
self.logger.warning( self.logger.warning(
"[MQTT-3.1.0-1] %s: Can't read first packet an CONNECT: %s" "[MQTT-3.1.0-1] %s: Can't read first packet an CONNECT: %s"
% (format_client_message(address=remote_address, port=remote_port), exc) % (format_client_message(address=remote_address, port=remote_port), exc)

Wyświetl plik

@ -3,9 +3,9 @@
# See the file license.txt for copying permission. # See the file license.txt for copying permission.
class HBMQTTException(Exception): class AMQTTException(Exception):
""" """
HBMQTT base exception aMQTT base exception
""" """
pass pass

Wyświetl plik

@ -1,7 +1,7 @@
# Copyright (c) 2015 Nicolas JOUANIN # Copyright (c) 2015 Nicolas JOUANIN
# #
# See the file license.txt for copying permission. # See the file license.txt for copying permission.
from amqtt.errors import HBMQTTException from amqtt.errors import AMQTTException
from amqtt.mqtt.packet import ( from amqtt.mqtt.packet import (
CONNECT, CONNECT,
CONNACK, CONNACK,
@ -57,4 +57,4 @@ def packet_class(fixed_header: MQTTFixedHeader):
cls = packet_dict[fixed_header.packet_type] cls = packet_dict[fixed_header.packet_type]
return cls return cls
except KeyError: except KeyError:
raise HBMQTTException("Unexpected packet Type '%s'" % fixed_header.packet_type) raise AMQTTException("Unexpected packet Type '%s'" % fixed_header.packet_type)

Wyświetl plik

@ -3,7 +3,7 @@
# See the file license.txt for copying permission. # See the file license.txt for copying permission.
from amqtt.mqtt.packet import CONNACK, MQTTPacket, MQTTFixedHeader, MQTTVariableHeader from amqtt.mqtt.packet import CONNACK, MQTTPacket, MQTTFixedHeader, MQTTVariableHeader
from amqtt.codecs import read_or_raise, bytes_to_int from amqtt.codecs import read_or_raise, bytes_to_int
from amqtt.errors import HBMQTTException from amqtt.errors import AMQTTException
from amqtt.adapters import ReaderAdapter from amqtt.adapters import ReaderAdapter
CONNECTION_ACCEPTED = 0x00 CONNECTION_ACCEPTED = 0x00
@ -78,7 +78,7 @@ class ConnackPacket(MQTTPacket):
header = MQTTFixedHeader(CONNACK, 0x00) header = MQTTFixedHeader(CONNACK, 0x00)
else: else:
if fixed.packet_type is not CONNACK: if fixed.packet_type is not CONNACK:
raise HBMQTTException( raise AMQTTException(
"Invalid fixed packet type %s for ConnackPacket init" "Invalid fixed packet type %s for ConnackPacket init"
% fixed.packet_type % fixed.packet_type
) )

Wyświetl plik

@ -18,7 +18,7 @@ from amqtt.mqtt.packet import (
MQTTVariableHeader, MQTTVariableHeader,
MQTTPayload, MQTTPayload,
) )
from amqtt.errors import HBMQTTException, NoDataException from amqtt.errors import AMQTTException, NoDataException
from amqtt.adapters import ReaderAdapter from amqtt.adapters import ReaderAdapter
from amqtt.utils import gen_client_id from amqtt.utils import gen_client_id
@ -390,7 +390,7 @@ class ConnectPacket(MQTTPacket):
header = MQTTFixedHeader(CONNECT, 0x00) header = MQTTFixedHeader(CONNECT, 0x00)
else: else:
if fixed.packet_type is not CONNECT: if fixed.packet_type is not CONNECT:
raise HBMQTTException( raise AMQTTException(
"Invalid fixed packet type %s for ConnectPacket init" "Invalid fixed packet type %s for ConnectPacket init"
% fixed.packet_type % fixed.packet_type
) )

Wyświetl plik

@ -2,7 +2,7 @@
# #
# See the file license.txt for copying permission. # See the file license.txt for copying permission.
from amqtt.mqtt.packet import MQTTPacket, MQTTFixedHeader, DISCONNECT from amqtt.mqtt.packet import MQTTPacket, MQTTFixedHeader, DISCONNECT
from amqtt.errors import HBMQTTException from amqtt.errors import AMQTTException
class DisconnectPacket(MQTTPacket): class DisconnectPacket(MQTTPacket):
@ -14,7 +14,7 @@ class DisconnectPacket(MQTTPacket):
header = MQTTFixedHeader(DISCONNECT, 0x00) header = MQTTFixedHeader(DISCONNECT, 0x00)
else: else:
if fixed.packet_type is not DISCONNECT: if fixed.packet_type is not DISCONNECT:
raise HBMQTTException( raise AMQTTException(
"Invalid fixed packet type %s for DisconnectPacket init" "Invalid fixed packet type %s for DisconnectPacket init"
% fixed.packet_type % fixed.packet_type
) )

Wyświetl plik

@ -2,7 +2,7 @@
# #
# See the file license.txt for copying permission. # See the file license.txt for copying permission.
from amqtt.mqtt.packet import MQTTPacket, MQTTFixedHeader, PINGREQ from amqtt.mqtt.packet import MQTTPacket, MQTTFixedHeader, PINGREQ
from amqtt.errors import HBMQTTException from amqtt.errors import AMQTTException
class PingReqPacket(MQTTPacket): class PingReqPacket(MQTTPacket):
@ -14,7 +14,7 @@ class PingReqPacket(MQTTPacket):
header = MQTTFixedHeader(PINGREQ, 0x00) header = MQTTFixedHeader(PINGREQ, 0x00)
else: else:
if fixed.packet_type is not PINGREQ: if fixed.packet_type is not PINGREQ:
raise HBMQTTException( raise AMQTTException(
"Invalid fixed packet type %s for PingReqPacket init" "Invalid fixed packet type %s for PingReqPacket init"
% fixed.packet_type % fixed.packet_type
) )

Wyświetl plik

@ -2,7 +2,7 @@
# #
# See the file license.txt for copying permission. # See the file license.txt for copying permission.
from amqtt.mqtt.packet import MQTTPacket, MQTTFixedHeader, PINGRESP from amqtt.mqtt.packet import MQTTPacket, MQTTFixedHeader, PINGRESP
from amqtt.errors import HBMQTTException from amqtt.errors import AMQTTException
class PingRespPacket(MQTTPacket): class PingRespPacket(MQTTPacket):
@ -14,7 +14,7 @@ class PingRespPacket(MQTTPacket):
header = MQTTFixedHeader(PINGRESP, 0x00) header = MQTTFixedHeader(PINGRESP, 0x00)
else: else:
if fixed.packet_type is not PINGRESP: if fixed.packet_type is not PINGRESP:
raise HBMQTTException( raise AMQTTException(
"Invalid fixed packet type %s for PingRespPacket init" "Invalid fixed packet type %s for PingRespPacket init"
% fixed.packet_type % fixed.packet_type
) )

Wyświetl plik

@ -52,7 +52,7 @@ from amqtt.session import (
) )
from amqtt.mqtt.constants import QOS_0, QOS_1, QOS_2 from amqtt.mqtt.constants import QOS_0, QOS_1, QOS_2
from amqtt.plugins.manager import PluginManager from amqtt.plugins.manager import PluginManager
from amqtt.errors import HBMQTTException, MQTTException, NoDataException from amqtt.errors import AMQTTException, MQTTException, NoDataException
EVENT_MQTT_PACKET_SENT = "mqtt_packet_sent" EVENT_MQTT_PACKET_SENT = "mqtt_packet_sent"
@ -204,7 +204,7 @@ class ProtocolHandler:
if qos in (QOS_1, QOS_2): if qos in (QOS_1, QOS_2):
packet_id = self.session.next_packet_id packet_id = self.session.next_packet_id
if packet_id in self.session.inflight_out: if packet_id in self.session.inflight_out:
raise HBMQTTException( raise AMQTTException(
"A message with the same packet ID '%d' is already in flight" "A message with the same packet ID '%d' is already in flight"
% packet_id % packet_id
) )
@ -236,7 +236,7 @@ class ProtocolHandler:
elif app_message.qos == QOS_2: elif app_message.qos == QOS_2:
await self._handle_qos2_message_flow(app_message) await self._handle_qos2_message_flow(app_message)
else: else:
raise HBMQTTException("Unexcepted QOS value '%d" % str(app_message.qos)) raise AMQTTException("Unexcepted QOS value '%d" % str(app_message.qos))
async def _handle_qos0_message_flow(self, app_message): async def _handle_qos0_message_flow(self, app_message):
""" """
@ -276,7 +276,7 @@ class ProtocolHandler:
""" """
assert app_message.qos == QOS_1 assert app_message.qos == QOS_1
if app_message.puback_packet: if app_message.puback_packet:
raise HBMQTTException( raise AMQTTException(
"Message '%d' has already been acknowledged" % app_message.packet_id "Message '%d' has already been acknowledged" % app_message.packet_id
) )
if app_message.direction == OUTGOING: if app_message.direction == OUTGOING:
@ -322,7 +322,7 @@ class ProtocolHandler:
assert app_message.qos == QOS_2 assert app_message.qos == QOS_2
if app_message.direction == OUTGOING: if app_message.direction == OUTGOING:
if app_message.pubrel_packet and app_message.pubcomp_packet: if app_message.pubrel_packet and app_message.pubcomp_packet:
raise HBMQTTException( raise AMQTTException(
"Message '%d' has already been acknowledged" % app_message.packet_id "Message '%d' has already been acknowledged" % app_message.packet_id
) )
if not app_message.pubrel_packet: if not app_message.pubrel_packet:
@ -330,7 +330,7 @@ class ProtocolHandler:
if app_message.publish_packet is not None: if app_message.publish_packet is not None:
# This is a retry flow, no need to store just check the message exists in session # This is a retry flow, no need to store just check the message exists in session
if app_message.packet_id not in self.session.inflight_out: if app_message.packet_id not in self.session.inflight_out:
raise HBMQTTException( raise AMQTTException(
"Unknown inflight message '%d' in session" "Unknown inflight message '%d' in session"
% app_message.packet_id % app_message.packet_id
) )
@ -350,7 +350,7 @@ class ProtocolHandler:
% app_message.packet_id % app_message.packet_id
) )
self.logger.warning(message) self.logger.warning(message)
raise HBMQTTException(message) raise AMQTTException(message)
waiter = asyncio.Future(loop=self._loop) waiter = asyncio.Future(loop=self._loop)
self._pubrec_waiters[app_message.packet_id] = waiter self._pubrec_waiters[app_message.packet_id] = waiter
await waiter await waiter

Wyświetl plik

@ -7,7 +7,7 @@ from amqtt.mqtt.packet import (
PUBACK, PUBACK,
PacketIdVariableHeader, PacketIdVariableHeader,
) )
from amqtt.errors import HBMQTTException from amqtt.errors import AMQTTException
class PubackPacket(MQTTPacket): class PubackPacket(MQTTPacket):
@ -31,7 +31,7 @@ class PubackPacket(MQTTPacket):
header = MQTTFixedHeader(PUBACK, 0x00) header = MQTTFixedHeader(PUBACK, 0x00)
else: else:
if fixed.packet_type is not PUBACK: if fixed.packet_type is not PUBACK:
raise HBMQTTException( raise AMQTTException(
"Invalid fixed packet type %s for PubackPacket init" "Invalid fixed packet type %s for PubackPacket init"
% fixed.packet_type % fixed.packet_type
) )

Wyświetl plik

@ -7,7 +7,7 @@ from amqtt.mqtt.packet import (
PUBCOMP, PUBCOMP,
PacketIdVariableHeader, PacketIdVariableHeader,
) )
from amqtt.errors import HBMQTTException from amqtt.errors import AMQTTException
class PubcompPacket(MQTTPacket): class PubcompPacket(MQTTPacket):
@ -31,7 +31,7 @@ class PubcompPacket(MQTTPacket):
header = MQTTFixedHeader(PUBCOMP, 0x00) header = MQTTFixedHeader(PUBCOMP, 0x00)
else: else:
if fixed.packet_type is not PUBCOMP: if fixed.packet_type is not PUBCOMP:
raise HBMQTTException( raise AMQTTException(
"Invalid fixed packet type %s for PubcompPacket init" "Invalid fixed packet type %s for PubcompPacket init"
% fixed.packet_type % fixed.packet_type
) )

Wyświetl plik

@ -10,7 +10,7 @@ from amqtt.mqtt.packet import (
MQTTVariableHeader, MQTTVariableHeader,
MQTTPayload, MQTTPayload,
) )
from amqtt.errors import HBMQTTException, MQTTException from amqtt.errors import AMQTTException, MQTTException
from amqtt.codecs import decode_packet_id, decode_string, encode_string, int_to_bytes from amqtt.codecs import decode_packet_id, decode_string, encode_string, int_to_bytes
@ -103,7 +103,7 @@ class PublishPacket(MQTTPacket):
header = MQTTFixedHeader(PUBLISH, 0x00) header = MQTTFixedHeader(PUBLISH, 0x00)
else: else:
if fixed.packet_type is not PUBLISH: if fixed.packet_type is not PUBLISH:
raise HBMQTTException( raise AMQTTException(
"Invalid fixed packet type %s for PublishPacket init" "Invalid fixed packet type %s for PublishPacket init"
% fixed.packet_type % fixed.packet_type
) )

Wyświetl plik

@ -7,7 +7,7 @@ from amqtt.mqtt.packet import (
PUBREC, PUBREC,
PacketIdVariableHeader, PacketIdVariableHeader,
) )
from amqtt.errors import HBMQTTException from amqtt.errors import AMQTTException
class PubrecPacket(MQTTPacket): class PubrecPacket(MQTTPacket):
@ -31,7 +31,7 @@ class PubrecPacket(MQTTPacket):
header = MQTTFixedHeader(PUBREC, 0x00) header = MQTTFixedHeader(PUBREC, 0x00)
else: else:
if fixed.packet_type is not PUBREC: if fixed.packet_type is not PUBREC:
raise HBMQTTException( raise AMQTTException(
"Invalid fixed packet type %s for PubrecPacket init" "Invalid fixed packet type %s for PubrecPacket init"
% fixed.packet_type % fixed.packet_type
) )

Wyświetl plik

@ -7,7 +7,7 @@ from amqtt.mqtt.packet import (
PUBREL, PUBREL,
PacketIdVariableHeader, PacketIdVariableHeader,
) )
from amqtt.errors import HBMQTTException from amqtt.errors import AMQTTException
class PubrelPacket(MQTTPacket): class PubrelPacket(MQTTPacket):
@ -31,7 +31,7 @@ class PubrelPacket(MQTTPacket):
header = MQTTFixedHeader(PUBREL, 0x02) # [MQTT-3.6.1-1] header = MQTTFixedHeader(PUBREL, 0x02) # [MQTT-3.6.1-1]
else: else:
if fixed.packet_type is not PUBREL: if fixed.packet_type is not PUBREL:
raise HBMQTTException( raise AMQTTException(
"Invalid fixed packet type %s for PubrelPacket init" "Invalid fixed packet type %s for PubrelPacket init"
% fixed.packet_type % fixed.packet_type
) )

Wyświetl plik

@ -9,7 +9,7 @@ from amqtt.mqtt.packet import (
MQTTPayload, MQTTPayload,
MQTTVariableHeader, MQTTVariableHeader,
) )
from amqtt.errors import HBMQTTException, NoDataException from amqtt.errors import AMQTTException, NoDataException
from amqtt.adapters import ReaderAdapter from amqtt.adapters import ReaderAdapter
from amqtt.codecs import bytes_to_int, int_to_bytes, read_or_raise from amqtt.codecs import bytes_to_int, int_to_bytes, read_or_raise
@ -71,7 +71,7 @@ class SubackPacket(MQTTPacket):
header = MQTTFixedHeader(SUBACK, 0x00) header = MQTTFixedHeader(SUBACK, 0x00)
else: else:
if fixed.packet_type is not SUBACK: if fixed.packet_type is not SUBACK:
raise HBMQTTException( raise AMQTTException(
"Invalid fixed packet type %s for SubackPacket init" "Invalid fixed packet type %s for SubackPacket init"
% fixed.packet_type % fixed.packet_type
) )

Wyświetl plik

@ -11,7 +11,7 @@ from amqtt.mqtt.packet import (
MQTTPayload, MQTTPayload,
MQTTVariableHeader, MQTTVariableHeader,
) )
from amqtt.errors import HBMQTTException, NoDataException from amqtt.errors import AMQTTException, NoDataException
from amqtt.codecs import ( from amqtt.codecs import (
bytes_to_int, bytes_to_int,
decode_string, decode_string,
@ -77,7 +77,7 @@ class SubscribePacket(MQTTPacket):
header = MQTTFixedHeader(SUBSCRIBE, 0x02) # [MQTT-3.8.1-1] header = MQTTFixedHeader(SUBSCRIBE, 0x02) # [MQTT-3.8.1-1]
else: else:
if fixed.packet_type is not SUBSCRIBE: if fixed.packet_type is not SUBSCRIBE:
raise HBMQTTException( raise AMQTTException(
"Invalid fixed packet type %s for SubscribePacket init" "Invalid fixed packet type %s for SubscribePacket init"
% fixed.packet_type % fixed.packet_type
) )

Wyświetl plik

@ -7,7 +7,7 @@ from amqtt.mqtt.packet import (
UNSUBACK, UNSUBACK,
PacketIdVariableHeader, PacketIdVariableHeader,
) )
from amqtt.errors import HBMQTTException from amqtt.errors import AMQTTException
class UnsubackPacket(MQTTPacket): class UnsubackPacket(MQTTPacket):
@ -24,7 +24,7 @@ class UnsubackPacket(MQTTPacket):
header = MQTTFixedHeader(UNSUBACK, 0x00) header = MQTTFixedHeader(UNSUBACK, 0x00)
else: else:
if fixed.packet_type is not UNSUBACK: if fixed.packet_type is not UNSUBACK:
raise HBMQTTException( raise AMQTTException(
"Invalid fixed packet type %s for UnsubackPacket init" "Invalid fixed packet type %s for UnsubackPacket init"
% fixed.packet_type % fixed.packet_type
) )

Wyświetl plik

@ -11,7 +11,7 @@ from amqtt.mqtt.packet import (
MQTTPayload, MQTTPayload,
MQTTVariableHeader, MQTTVariableHeader,
) )
from amqtt.errors import HBMQTTException, NoDataException from amqtt.errors import AMQTTException, NoDataException
from amqtt.codecs import decode_string, encode_string from amqtt.codecs import decode_string, encode_string
@ -65,7 +65,7 @@ class UnsubscribePacket(MQTTPacket):
header = MQTTFixedHeader(UNSUBSCRIBE, 0x02) # [MQTT-3.10.1-1] header = MQTTFixedHeader(UNSUBSCRIBE, 0x02) # [MQTT-3.10.1-1]
else: else:
if fixed.packet_type is not UNSUBSCRIBE: if fixed.packet_type is not UNSUBSCRIBE:
raise HBMQTTException( raise AMQTTException(
"Invalid fixed packet type %s for UnsubscribePacket init" "Invalid fixed packet type %s for UnsubscribePacket init"
% fixed.packet_type % fixed.packet_type
) )

Wyświetl plik

@ -6,7 +6,7 @@ from transitions import Machine
from asyncio import Queue from asyncio import Queue
from collections import OrderedDict from collections import OrderedDict
from amqtt.mqtt.publish import PublishPacket from amqtt.mqtt.publish import PublishPacket
from amqtt.errors import HBMQTTException from amqtt.errors import AMQTTException
OUTGOING = 0 OUTGOING = 0
INCOMING = 1 INCOMING = 1
@ -172,7 +172,7 @@ class Session:
): ):
self._packet_id += 1 self._packet_id += 1
if self._packet_id > 65535: if self._packet_id > 65535:
raise HBMQTTException( raise AMQTTException(
"More than 65525 messages pending. No free packet ID" "More than 65525 messages pending. No free packet ID"
) )