Skip to content

Commit 11e99d9

Browse files
author
brentru
committed
add licensing details
1 parent 9fad312 commit 11e99d9

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ The MIT License (MIT)
22

33
Copyright (c) 2019 Brent Rubell for Adafruit Industries
44

5+
56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal
78
in the Software without restriction, including without limitation the rights
@@ -19,3 +20,9 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1920
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2021
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2122
SOFTWARE.
23+
24+
matcher.py for matching MQTT topics from the Eclipse Paho MQTT Python Client
25+
https://github.com/eclipse/paho.mqtt.python
26+
27+
Eclipse Paho MQTT Python Client is dual licensed under the Eclipse Public License 1.0 and the
28+
Eclipse Distribution License 1.0 as described in the epl-v10 and edl-v10 files.

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Original Work Copyright (c) 2016 Paul Sokolovsky, uMQTT
66
# Modified Work Copyright (c) 2019 Bradley Beach, esp32spi_mqtt
7-
#
7+
#
88
# Permission is hereby granted, free of charge, to any person obtaining a copy
99
# of this software and associated documentation files (the "Software"), to deal
1010
# in the Software without restriction, including without limitation the rights

adafruit_minimqtt/matcher.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# Copyright (c) 2017 Yotch <https://github.com/yoch>
2+
#
3+
# This file is dual licensed under the Eclipse Public License 1.0 and the
4+
# Eclipse Distribution License 1.0 as described in the epl-v10 and edl-v10 files.
5+
#
6+
#
7+
"""
8+
`matcher`
9+
====================================================================================
10+
11+
MQTT topic filter matcher from the Eclipse Project's Paho.MQTT.Python
12+
https://github.com/eclipse/paho.mqtt.python/blob/master/src/paho/mqtt/matcher.py
13+
* Author(s): Yotch (https://github.com/yoch)
14+
"""
15+
116
class MQTTMatcher(object):
217
"""Intended to manage topic filters including wildcards.
318
@@ -7,7 +22,7 @@ class MQTTMatcher(object):
722
some topic name."""
823

924
class Node(object):
10-
__slots__ = "_children", "_content"
25+
__slots__ = '_children', '_content'
1126

1227
def __init__(self):
1328
self._children = {}
@@ -20,15 +35,15 @@ def __setitem__(self, key, value):
2035
"""Add a topic filter :key to the prefix tree
2136
and associate it to :value"""
2237
node = self._root
23-
for sym in key.split("/"):
38+
for sym in key.split('/'):
2439
node = node._children.setdefault(sym, self.Node())
2540
node._content = value
2641

2742
def __getitem__(self, key):
2843
"""Retrieve the value associated with some topic filter :key"""
2944
try:
3045
node = self._root
31-
for sym in key.split("/"):
46+
for sym in key.split('/'):
3247
node = node._children[sym]
3348
if node._content is None:
3449
raise KeyError(key)
@@ -41,25 +56,24 @@ def __delitem__(self, key):
4156
lst = []
4257
try:
4358
parent, node = None, self._root
44-
for k in key.split("/"):
45-
parent, node = node, node._children[k]
46-
lst.append((parent, k, node))
59+
for k in key.split('/'):
60+
parent, node = node, node._children[k]
61+
lst.append((parent, k, node))
4762
# TODO
4863
node._content = None
4964
except KeyError:
5065
raise KeyError(key)
5166
else: # cleanup
5267
for parent, k, node in reversed(lst):
5368
if node._children or node._content is not None:
54-
break
69+
break
5570
del parent._children[k]
5671

5772
def iter_match(self, topic):
5873
"""Return an iterator on all values associated with filters
5974
that match the :topic"""
60-
lst = topic.split("/")
61-
normal = not topic.startswith("$")
62-
75+
lst = topic.split('/')
76+
normal = not topic.startswith('$')
6377
def rec(node, i=0):
6478
if i == len(lst):
6579
if node._content is not None:
@@ -69,12 +83,11 @@ def rec(node, i=0):
6983
if part in node._children:
7084
for content in rec(node._children[part], i + 1):
7185
yield content
72-
if "+" in node._children and (normal or i > 0):
73-
for content in rec(node._children["+"], i + 1):
86+
if '+' in node._children and (normal or i > 0):
87+
for content in rec(node._children['+'], i + 1):
7488
yield content
75-
if "#" in node._children and (normal or i > 0):
76-
content = node._children["#"]._content
89+
if '#' in node._children and (normal or i > 0):
90+
content = node._children['#']._content
7791
if content is not None:
7892
yield content
79-
80-
return rec(self._root)
93+
return rec(self._root)

0 commit comments

Comments
 (0)