From 3b171aa3f3f3e872a099f3de9ee25b3e7ad6ea53 Mon Sep 17 00:00:00 2001 From: Roger Light Date: Sat, 7 Dec 2013 23:34:59 +0000 Subject: [PATCH] Topics are no longer normalised. --- src/paho/mqtt/client.py | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/paho/mqtt/client.py b/src/paho/mqtt/client.py index 494444f..c8a3486 100755 --- a/src/paho/mqtt/client.py +++ b/src/paho/mqtt/client.py @@ -125,15 +125,6 @@ MQTT_ERR_UNKNOWN = 13 MQTT_ERR_ERRNO = 14 -def _fix_sub_topic(subtopic): - # Convert ////some////over/slashed///topic/etc/etc// - # into some/over/slashed/topic/etc/etc - if subtopic[0] == '/': - return '/'+'/'.join(filter(None, subtopic.split('/'))) - else: - return '/'.join(filter(None, subtopic.split('/'))) - - def error_string(mqtt_errno): """Return the error string associated with an mqtt error number.""" if mqtt_errno == MQTT_ERR_SUCCESS: @@ -197,30 +188,28 @@ def topic_matches_sub(sub, topic): non/matching would not match the subscription non/+/+ """ result = True - local_sub = _fix_sub_topic(sub) - local_topic = _fix_sub_topic(topic) multilevel_wildcard = False - slen = len(local_sub) - tlen = len(local_topic) + slen = len(sub) + tlen = len(topic) spos = 0 tpos = 0 while spos < slen and tpos < tlen: - if local_sub[spos] == local_topic[tpos]: + if sub[spos] == topic[tpos]: spos += 1 tpos += 1 else: - if local_sub[spos] == '+': + if sub[spos] == '+': spos += 1 - while tpos < tlen and local_topic[tpos] != '/': + while tpos < tlen and topic[tpos] != '/': tpos += 1 if tpos == tlen and spos == slen: result = True break - elif local_sub[spos] == '#': + elif sub[spos] == '#': multilevel_wildcard = True if spos+1 != slen: result = False @@ -235,7 +224,7 @@ def topic_matches_sub(sub, topic): if tpos == tlen-1: # Check for e.g. foo matching foo/# - if spos == slen-3 and local_sub[spos+1] == '/' and local_sub[spos+2] == '#': + if spos == slen-3 and sub[spos+1] == '/' and sub[spos+2] == '#': result = True multilevel_wildcard = True break @@ -1836,7 +1825,6 @@ class Client: if sys.version_info[0] >= 3: message.topic = message.topic.decode('utf-8') - message.topic = _fix_sub_topic(message.topic) if message.qos > 0: pack_format = "!H" + str(len(packet)-2) + 's' -- 2.39.5