]> git.michaelhowe.org Git - packages/p/paho-mqtt.git/commitdiff
Topics are no longer normalised.
authorRoger Light <roger@atchoo.org>
Sat, 7 Dec 2013 23:34:59 +0000 (23:34 +0000)
committerRoger Light <roger@atchoo.org>
Mon, 3 Feb 2014 21:20:22 +0000 (21:20 +0000)
src/paho/mqtt/client.py

index 494444fab2996009609424e8ad8e85dcbb4ff995..c8a3486467b7fe6117065eae5a8af9d848a1a755 100755 (executable)
@@ -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'