kopia lustrzana https://github.com/Yakifo/amqtt
Merge pull request #87 from gdraynz/class-slots
Add __slots__ attribute to the most used classespull/8/head
commit
5021512917
|
@ -54,6 +54,9 @@ class BrokerException(BaseException):
|
|||
|
||||
|
||||
class RetainedApplicationMessage:
|
||||
|
||||
__slots__ = ('source_session', 'topic', 'data', 'qos')
|
||||
|
||||
def __init__(self, source_session, topic, data, qos=None):
|
||||
self.source_session = source_session
|
||||
self.topic = topic
|
||||
|
|
|
@ -430,7 +430,7 @@ class MQTTClient:
|
|||
@asyncio.coroutine
|
||||
def handle_connection_close(self):
|
||||
|
||||
def cancel_tasks(self):
|
||||
def cancel_tasks():
|
||||
while self.client_tasks:
|
||||
task = self.client_tasks.popleft()
|
||||
if not task.done():
|
||||
|
@ -456,7 +456,7 @@ class MQTTClient:
|
|||
yield from self.reconnect()
|
||||
except ConnectException:
|
||||
# Cancel client pending tasks
|
||||
cancel_tasks(self)
|
||||
cancel_tasks()
|
||||
else:
|
||||
# Cancel client pending tasks
|
||||
cancel_tasks()
|
||||
|
|
|
@ -16,6 +16,9 @@ NOT_AUTHORIZED = 0x05
|
|||
|
||||
|
||||
class ConnackVariableHeader(MQTTVariableHeader):
|
||||
|
||||
__slots__ = ('session_parent', 'return_code')
|
||||
|
||||
def __init__(self, session_parent=None, return_code=None):
|
||||
super().__init__()
|
||||
self.session_parent = session_parent
|
||||
|
|
|
@ -10,6 +10,9 @@ from hbmqtt.adapters import ReaderAdapter
|
|||
|
||||
|
||||
class ConnectVariableHeader(MQTTVariableHeader):
|
||||
|
||||
__slots__ = ('proto_name', 'proto_level', 'flags', 'keep_alive')
|
||||
|
||||
USERNAME_FLAG = 0x80
|
||||
PASSWORD_FLAG = 0x40
|
||||
WILL_RETAIN_FLAG = 0x20
|
||||
|
@ -130,6 +133,11 @@ class ConnectVariableHeader(MQTTVariableHeader):
|
|||
|
||||
|
||||
class ConnectPayload(MQTTPayload):
|
||||
|
||||
__slots__ = (
|
||||
'client_id', 'will_topic', 'will_message', 'username', 'password'
|
||||
)
|
||||
|
||||
def __init__(self, client_id=None, will_topic=None, will_message=None, username=None, password=None):
|
||||
super().__init__()
|
||||
self.client_id = client_id
|
||||
|
|
|
@ -29,6 +29,9 @@ RESERVED_15 = 0x0f
|
|||
|
||||
|
||||
class MQTTFixedHeader:
|
||||
|
||||
__slots__ = ('packet_type', 'remaining_length', 'flags')
|
||||
|
||||
def __init__(self, packet_type, flags=0, length=0):
|
||||
self.packet_type = packet_type
|
||||
self.remaining_length = length
|
||||
|
@ -139,6 +142,9 @@ class MQTTVariableHeader:
|
|||
|
||||
|
||||
class PacketIdVariableHeader(MQTTVariableHeader):
|
||||
|
||||
__slots__ = ('packet_id',)
|
||||
|
||||
def __init__(self, packet_id):
|
||||
super().__init__()
|
||||
self.packet_id = packet_id
|
||||
|
@ -178,6 +184,9 @@ class MQTTPayload:
|
|||
|
||||
|
||||
class MQTTPacket:
|
||||
|
||||
__slots__ = ('fixed_header', 'variable_header', 'payload', 'protocol_ts')
|
||||
|
||||
FIXED_HEADER = MQTTFixedHeader
|
||||
VARIABLE_HEADER = None
|
||||
PAYLOAD = None
|
||||
|
|
|
@ -9,6 +9,9 @@ from hbmqtt.codecs import decode_packet_id, decode_string, encode_string, int_to
|
|||
|
||||
|
||||
class PublishVariableHeader(MQTTVariableHeader):
|
||||
|
||||
__slots__ = ('topic_name', 'packet_id')
|
||||
|
||||
def __init__(self, topic_name: str, packet_id: int=None):
|
||||
super().__init__()
|
||||
if '*' in topic_name:
|
||||
|
@ -39,6 +42,9 @@ class PublishVariableHeader(MQTTVariableHeader):
|
|||
|
||||
|
||||
class PublishPayload(MQTTPayload):
|
||||
|
||||
__slots__ = ('data',)
|
||||
|
||||
def __init__(self, data: bytes=None):
|
||||
super().__init__()
|
||||
self.data = data
|
||||
|
|
|
@ -10,6 +10,9 @@ from hbmqtt.codecs import bytes_to_int, int_to_bytes, read_or_raise
|
|||
|
||||
|
||||
class SubackPayload(MQTTPayload):
|
||||
|
||||
__slots__ = ('return_codes',)
|
||||
|
||||
RETURN_CODE_00 = 0x00
|
||||
RETURN_CODE_01 = 0x01
|
||||
RETURN_CODE_02 = 0x02
|
||||
|
|
|
@ -9,6 +9,9 @@ from hbmqtt.codecs import bytes_to_int, decode_string, encode_string, int_to_byt
|
|||
|
||||
|
||||
class SubscribePayload(MQTTPayload):
|
||||
|
||||
__slots__ = ('topics',)
|
||||
|
||||
def __init__(self, topics=[]):
|
||||
super().__init__()
|
||||
self.topics = topics
|
||||
|
|
|
@ -9,6 +9,9 @@ from hbmqtt.codecs import decode_string, encode_string
|
|||
|
||||
|
||||
class UnubscribePayload(MQTTPayload):
|
||||
|
||||
__slots__ = ('topics',)
|
||||
|
||||
def __init__(self, topics=[]):
|
||||
super().__init__()
|
||||
self.topics = topics
|
||||
|
|
|
@ -13,9 +13,16 @@ INCOMING = 1
|
|||
|
||||
|
||||
class ApplicationMessage:
|
||||
|
||||
"""
|
||||
ApplicationMessage and subclasses are used to store published message information flow. These objects can contain different information depending on the way they were created (incoming or outgoing) and the quality of service used between peers.
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
'packet_id', 'topic', 'qos', 'data', 'retain', 'publish_packet',
|
||||
'puback_packet', 'pubrec_packet', 'pubrel_packet', 'pubcomp_packet',
|
||||
)
|
||||
|
||||
def __init__(self, packet_id, topic, qos, data, retain):
|
||||
self.packet_id = packet_id
|
||||
""" Publish message `packet identifier <http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718025>`_"""
|
||||
|
@ -61,18 +68,26 @@ class ApplicationMessage:
|
|||
|
||||
|
||||
class IncomingApplicationMessage(ApplicationMessage):
|
||||
|
||||
"""
|
||||
Incoming :class:`~hbmqtt.session.ApplicationMessage`.
|
||||
"""
|
||||
|
||||
__slots__ = ('direction',)
|
||||
|
||||
def __init__(self, packet_id, topic, qos, data, retain):
|
||||
super().__init__(packet_id, topic, qos, data, retain)
|
||||
self.direction = INCOMING
|
||||
|
||||
|
||||
class OutgoingApplicationMessage(ApplicationMessage):
|
||||
|
||||
"""
|
||||
Outgoing :class:`~hbmqtt.session.ApplicationMessage`.
|
||||
"""
|
||||
|
||||
__slots__ = ('direction',)
|
||||
|
||||
def __init__(self, packet_id, topic, qos, data, retain):
|
||||
super().__init__(packet_id, topic, qos, data, retain)
|
||||
self.direction = OUTGOING
|
||||
|
|
Ładowanie…
Reference in New Issue