|
10 | 10 | from .definitions import MessageCallback |
11 | 11 | from .topic_handler import TopicHandler |
12 | 12 |
|
13 | | -_CHANNEL_REGEX = re.compile(r'^[a-zA-Z0-9*/-]+[a-zA-Z0-9*#/-]$') |
| 13 | +_CHANNEL_REGEX = re.compile(r'^[a-zA-Z0-9_*/-]+[a-zA-Z0-9_*#/-]$') |
14 | 14 | """Allow for these patterns: |
15 | 15 |
|
16 | 16 | - alphanumeric characters |
17 | 17 | - hyphens |
| 18 | +- underscores |
18 | 19 | - `/` (topic separator; note that this is '.' on the broker) |
19 | 20 | - `*` (wildcard for exactly one word) |
20 | 21 | - `#` (wildcard for any number of words, but can ONLY appear at the end of the topic string, see section 4.7.1.2 at https://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718107) |
| 22 | +
|
| 23 | +This should be permissive relative to other patterns. You must cover system/service/hierarchy regexes, capability regexes, and event name regexes. |
21 | 24 | """ |
22 | 25 |
|
23 | 26 |
|
@@ -75,7 +78,11 @@ def __init__( |
75 | 78 | self._wildcards: dict[str, TopicHandler] = {} |
76 | 79 |
|
77 | 80 | def add_subscription_channel( |
78 | | - self, channel: str, callbacks: set[MessageCallback], persist: bool, queue_name: str |
| 81 | + self, |
| 82 | + channel: str, |
| 83 | + callbacks: set[MessageCallback], |
| 84 | + persist: bool, |
| 85 | + queue_name: str, |
79 | 86 | ) -> None: |
80 | 87 | """Start listening for messages on a channel on all configured brokers. |
81 | 88 |
|
@@ -167,7 +174,9 @@ def get_wildcard_topic_and_topic_handler(self, topic: str) -> tuple[str, TopicHa |
167 | 174 | return wildcard, topic_handler |
168 | 175 | return None |
169 | 176 |
|
170 | | - def get_all_subscription_channels(self) -> itertools.chain[tuple[str, TopicHandler]]: |
| 177 | + def get_all_subscription_channels( |
| 178 | + self, |
| 179 | + ) -> itertools.chain[tuple[str, TopicHandler]]: |
171 | 180 | """Get all subscription channels, including wildcard channels. |
172 | 181 |
|
173 | 182 | This function is safe to call from the broker clients, as it does not mutate state. |
|
0 commit comments