mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-07 21:51:14 -07:00
Update paho-mqtt==1.6.1
This commit is contained in:
parent
d981f6e51f
commit
966a6696d1
9 changed files with 680 additions and 502 deletions
|
@ -1,4 +1,4 @@
|
|||
__version__ = "1.5.1"
|
||||
__version__ = "1.6.1"
|
||||
|
||||
|
||||
class MQTTException(Exception):
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -3,7 +3,7 @@
|
|||
Copyright (c) 2017, 2019 IBM Corp.
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License v1.0
|
||||
are made available under the terms of the Eclipse Public License v2.0
|
||||
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Copyright (c) 2017, 2019 IBM Corp.
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License v1.0
|
||||
are made available under the terms of the Eclipse Public License v2.0
|
||||
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
|
@ -16,7 +16,8 @@
|
|||
*******************************************************************
|
||||
"""
|
||||
|
||||
import sys, struct
|
||||
import struct
|
||||
import sys
|
||||
|
||||
from .packettypes import PacketTypes
|
||||
|
||||
|
@ -268,6 +269,30 @@ class Properties(object):
|
|||
if self.packetType not in self.properties[self.getIdentFromName(name)][1]:
|
||||
raise MQTTException("Property %s does not apply to packet type %s"
|
||||
% (name, PacketTypes.Names[self.packetType]))
|
||||
|
||||
# Check for forbidden values
|
||||
if type(value) != type([]):
|
||||
if name in ["ReceiveMaximum", "TopicAlias"] \
|
||||
and (value < 1 or value > 65535):
|
||||
|
||||
raise MQTTException(
|
||||
"%s property value must be in the range 1-65535" % (name))
|
||||
elif name in ["TopicAliasMaximum"] \
|
||||
and (value < 0 or value > 65535):
|
||||
|
||||
raise MQTTException(
|
||||
"%s property value must be in the range 0-65535" % (name))
|
||||
elif name in ["MaximumPacketSize", "SubscriptionIdentifier"] \
|
||||
and (value < 1 or value > 268435455):
|
||||
|
||||
raise MQTTException(
|
||||
"%s property value must be in the range 1-268435455" % (name))
|
||||
elif name in ["RequestResponseInformation", "RequestProblemInformation", "PayloadFormatIndicator"] \
|
||||
and (value != 0 and value != 1):
|
||||
|
||||
raise MQTTException(
|
||||
"%s property value must be 0 or 1" % (name))
|
||||
|
||||
if self.allowsMultiple(name):
|
||||
if type(value) != type([]):
|
||||
value = [value]
|
||||
|
@ -294,7 +319,11 @@ class Properties(object):
|
|||
for name in self.names.keys():
|
||||
compressedName = name.replace(' ', '')
|
||||
if hasattr(self, compressedName):
|
||||
data[compressedName] = getattr(self, compressedName)
|
||||
val = getattr(self, compressedName)
|
||||
if compressedName == 'CorrelationData' and isinstance(val, bytes):
|
||||
data[compressedName] = val.hex()
|
||||
else:
|
||||
data[compressedName] = val
|
||||
return data
|
||||
|
||||
def isEmpty(self):
|
||||
|
@ -391,10 +420,10 @@ class Properties(object):
|
|||
buffer = buffer[VBIlen:] # strip the bytes used by the VBI
|
||||
propslenleft = propslen
|
||||
while propslenleft > 0: # properties length is 0 if there are none
|
||||
identifier, VBIlen = VariableByteIntegers.decode(
|
||||
identifier, VBIlen2 = VariableByteIntegers.decode(
|
||||
buffer) # property identifier
|
||||
buffer = buffer[VBIlen:] # strip the bytes used by the VBI
|
||||
propslenleft -= VBIlen
|
||||
buffer = buffer[VBIlen2:] # strip the bytes used by the VBI
|
||||
propslenleft -= VBIlen2
|
||||
attr_type = self.properties[identifier][0]
|
||||
value, valuelen = self.readProperty(
|
||||
buffer, attr_type, propslenleft)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Copyright (c) 2014 Roger Light <roger@atchoo.org>
|
||||
#
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are made available under the terms of the Eclipse Public License v1.0
|
||||
# are made available under the terms of the Eclipse Public License v2.0
|
||||
# and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
#
|
||||
# The Eclipse Public License is available at
|
||||
|
@ -21,13 +21,15 @@ broker, then disconnect and nothing else is required.
|
|||
from __future__ import absolute_import
|
||||
|
||||
import collections
|
||||
|
||||
try:
|
||||
from collections.abc import Iterable
|
||||
except ImportError:
|
||||
from collections import Iterable
|
||||
|
||||
from . import client as paho
|
||||
from .. import mqtt
|
||||
from . import client as paho
|
||||
|
||||
|
||||
def _do_publish(client):
|
||||
"""Internal function"""
|
||||
|
@ -52,6 +54,9 @@ def _on_connect(client, userdata, flags, rc):
|
|||
else:
|
||||
raise mqtt.MQTTException(paho.connack_string(rc))
|
||||
|
||||
def _on_connect_v5(client, userdata, flags, rc, properties):
|
||||
"""Internal v5 callback"""
|
||||
_on_connect(client, userdata, flags, rc)
|
||||
|
||||
def _on_publish(client, userdata, mid):
|
||||
"""Internal callback"""
|
||||
|
@ -131,11 +136,15 @@ def multiple(msgs, hostname="localhost", port=1883, client_id="", keepalive=60,
|
|||
if not isinstance(msgs, Iterable):
|
||||
raise TypeError('msgs must be an iterable')
|
||||
|
||||
|
||||
client = paho.Client(client_id=client_id, userdata=collections.deque(msgs),
|
||||
protocol=protocol, transport=transport)
|
||||
|
||||
client.on_publish = _on_publish
|
||||
client.on_connect = _on_connect
|
||||
if protocol == mqtt.client.MQTTv5:
|
||||
client.on_connect = _on_connect_v5
|
||||
else:
|
||||
client.on_connect = _on_connect
|
||||
|
||||
if proxy_args is not None:
|
||||
client.proxy_set(**proxy_args)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Copyright (c) 2017, 2019 IBM Corp.
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License v1.0
|
||||
are made available under the terms of the Eclipse Public License v2.0
|
||||
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
|
@ -17,6 +17,7 @@
|
|||
"""
|
||||
|
||||
import sys
|
||||
|
||||
from .packettypes import PacketTypes
|
||||
|
||||
|
||||
|
@ -120,7 +121,7 @@ class ReasonCodes:
|
|||
}
|
||||
if identifier == -1:
|
||||
if packetType == PacketTypes.DISCONNECT and aName == "Success":
|
||||
aName = "Normal disconnection"
|
||||
aName = "Normal disconnection"
|
||||
self.set(aName)
|
||||
else:
|
||||
self.value = identifier
|
||||
|
@ -153,7 +154,7 @@ class ReasonCodes:
|
|||
if self.packetType in self.names[code][name]:
|
||||
identifier = code
|
||||
break
|
||||
assert identifier != None, name
|
||||
assert identifier is not None, name
|
||||
return identifier
|
||||
|
||||
def set(self, name):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Copyright (c) 2016 Roger Light <roger@atchoo.org>
|
||||
#
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are made available under the terms of the Eclipse Public License v1.0
|
||||
# are made available under the terms of the Eclipse Public License v2.0
|
||||
# and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
#
|
||||
# The Eclipse Public License is available at
|
||||
|
@ -20,10 +20,11 @@ you to pass a callback for processing of messages.
|
|||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from . import client as paho
|
||||
from .. import mqtt
|
||||
from . import client as paho
|
||||
|
||||
def _on_connect(client, userdata, flags, rc):
|
||||
|
||||
def _on_connect_v5(client, userdata, flags, rc, properties):
|
||||
"""Internal callback"""
|
||||
if rc != 0:
|
||||
raise mqtt.MQTTException(paho.connack_string(rc))
|
||||
|
@ -34,6 +35,10 @@ def _on_connect(client, userdata, flags, rc):
|
|||
else:
|
||||
client.subscribe(userdata['topics'], userdata['qos'])
|
||||
|
||||
def _on_connect(client, userdata, flags, rc):
|
||||
"""Internal v5 callback"""
|
||||
_on_connect_v5(client, userdata, flags, rc, None)
|
||||
|
||||
|
||||
def _on_message_callback(client, userdata, message):
|
||||
"""Internal callback"""
|
||||
|
@ -142,7 +147,10 @@ def callback(callback, topics, qos=0, userdata=None, hostname="localhost",
|
|||
protocol=protocol, transport=transport,
|
||||
clean_session=clean_session)
|
||||
client.on_message = _on_message_callback
|
||||
client.on_connect = _on_connect
|
||||
if protocol == mqtt.client.MQTTv5:
|
||||
client.on_connect = _on_connect_v5
|
||||
else:
|
||||
client.on_connect = _on_connect
|
||||
|
||||
if proxy_args is not None:
|
||||
client.proxy_set(**proxy_args)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Copyright (c) 2017, 2019 IBM Corp.
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License v1.0
|
||||
are made available under the terms of the Eclipse Public License v2.0
|
||||
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue