Skip to content

Commit

Permalink
Run pre-commit to apply format
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreF committed Jan 3, 2024
1 parent 64fa870 commit cef5be4
Show file tree
Hide file tree
Showing 35 changed files with 1,104 additions and 1,259 deletions.
805 changes: 338 additions & 467 deletions src/paho/mqtt/client.py

Large diffs are not rendered by default.

28 changes: 15 additions & 13 deletions src/paho/mqtt/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class MQTTMatcher:
some topic name."""

class Node:
__slots__ = '_children', '_content'
__slots__ = "_children", "_content"

def __init__(self):
self._children = {}
Expand All @@ -20,15 +20,15 @@ def __setitem__(self, key, value):
"""Add a topic filter :key to the prefix tree
and associate it to :value"""
node = self._root
for sym in key.split('/'):
for sym in key.split("/"):
node = node._children.setdefault(sym, self.Node())
node._content = value

def __getitem__(self, key):
"""Retrieve the value associated with some topic filter :key"""
try:
node = self._root
for sym in key.split('/'):
for sym in key.split("/"):
node = node._children[sym]
if node._content is None:
raise KeyError(key)
Expand All @@ -41,24 +41,25 @@ def __delitem__(self, key):
lst = []
try:
parent, node = None, self._root
for k in key.split('/'):
parent, node = node, node._children[k]
lst.append((parent, k, node))
for k in key.split("/"):
parent, node = node, node._children[k]
lst.append((parent, k, node))
# TODO
node._content = None
except KeyError as ke:
raise KeyError(key) from ke
else: # cleanup
for parent, k, node in reversed(lst):
if node._children or node._content is not None:
break
break
del parent._children[k]

def iter_match(self, topic):
"""Return an iterator on all values associated with filters
that match the :topic"""
lst = topic.split('/')
normal = not topic.startswith('$')
lst = topic.split("/")
normal = not topic.startswith("$")

def rec(node, i=0):
if i == len(lst):
if node._content is not None:
Expand All @@ -68,11 +69,12 @@ def rec(node, i=0):
if part in node._children:
for content in rec(node._children[part], i + 1):
yield content
if '+' in node._children and (normal or i > 0):
for content in rec(node._children['+'], i + 1):
if "+" in node._children and (normal or i > 0):
for content in rec(node._children["+"], i + 1):
yield content
if '#' in node._children and (normal or i > 0):
content = node._children['#']._content
if "#" in node._children and (normal or i > 0):
content = node._children["#"]._content
if content is not None:
yield content

return rec(self._root)
26 changes: 19 additions & 7 deletions src/paho/mqtt/packettypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,26 @@ class PacketTypes:
indexes = range(1, 16)

# Packet types
CONNECT, CONNACK, PUBLISH, PUBACK, PUBREC, PUBREL, \
PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK, \
PINGREQ, PINGRESP, DISCONNECT, AUTH = indexes
CONNECT, CONNACK, PUBLISH, PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK, PINGREQ, PINGRESP, DISCONNECT, AUTH = indexes

# Dummy packet type for properties use - will delay only applies to will
WILLMESSAGE = 99

Names = [ "reserved", \
"Connect", "Connack", "Publish", "Puback", "Pubrec", "Pubrel", \
"Pubcomp", "Subscribe", "Suback", "Unsubscribe", "Unsuback", \
"Pingreq", "Pingresp", "Disconnect", "Auth"]
Names = [
"reserved",
"Connect",
"Connack",
"Publish",
"Puback",
"Pubrec",
"Pubrel",
"Pubcomp",
"Subscribe",
"Suback",
"Unsubscribe",
"Unsuback",
"Pingreq",
"Pingresp",
"Disconnect",
"Auth",
]
Loading

0 comments on commit cef5be4

Please sign in to comment.