def _match_topic(subscription, topic):
 if subscription.endswith('#'):
  return ((subscription[:(-2)] == topic) or topic.startswith(subscription[:(-1)]))
 sub_parts = subscription.split('/')
 topic_parts = topic.split('/')
 return ((len(sub_parts) == len(topic_parts)) and all(((a == b) for (a, b) in zip(sub_parts, topic_parts) if (a != '+'))))

def _match_topic ( subscription , topic ) : if subscription . endswith ( '#' ) : return ( ( subscription [ : ( - 2 ) ] == topic ) or topic . startswith ( subscription [ : ( - 1 ) ] ) ) sub_parts = subscription . split ( '/' ) topic_parts = topic . split ( '/' ) return ( ( len ( sub_parts ) == len ( topic_parts ) ) and all ( ( ( a == b ) for ( a , b ) in zip ( sub_parts , topic_parts ) if ( a != '+' ) ) ) )
test if topic matches subscription .