提交 2488554a 编写于 作者: P Pierre Fersing 提交者: GitHub

Merge pull request #189 from Nzbuu/tidy-develop

Tidy develop branch
v2.x - 2017-xx-xx
v1.3.x - 2017-xx-xx
=================
- **BREAKING** Requires Python 2.7 or 3.4+. Closes #163.
- Allow username and password to be zero length (as opposed to not being
present). Closes #80.
- Allow zero length client ids when using MQTT v3.1.1.
- Add SSLContext support, including SNI. Closes #11.
- Remove support for SSL without SSLContext (Requires Python 2.7.9+ or 3.2+).
Closes #115.
- Move unit tests to pytest (#164)
- Move unit tests to pytest (#164) and tox (#187)
v1.2.2 - 2017-04-11
===================
......
__version__ = "1.2.2"
__version__ = "1.3.0.dev0"
class MQTTException(Exception):
def __init__(self, *args, **kwargs):
......
......@@ -59,17 +59,9 @@ if platform.system() == 'Windows':
else:
EAGAIN = errno.EAGAIN
VERSION_MAJOR = 1
VERSION_MINOR = 2
VERSION_REVISION = 2
VERSION_NUMBER = (VERSION_MAJOR * 1000000 + VERSION_MINOR * 1000 + VERSION_REVISION)
MQTTv31 = 3
MQTTv311 = 4
PROTOCOL_NAMEv31 = "MQIsdp"
PROTOCOL_NAMEv311 = "MQTT"
if sys.version_info[0] >= 3:
# define some alias for python2 compatibility
unicode = str
......@@ -150,10 +142,7 @@ MQTT_ERR_UNKNOWN = 13
MQTT_ERR_ERRNO = 14
MQTT_ERR_QUEUE_SIZE = 15
if sys.version_info[0] < 3:
sockpair_data = "0"
else:
sockpair_data = b"0"
sockpair_data = b"0"
class WebsocketConnectionError(ValueError):
......@@ -263,7 +252,7 @@ def _socketpair_compat():
return (sock1, sock2)
class MQTTMessageInfo:
class MQTTMessageInfo(object):
"""This is a class returned from Client.publish() and can be used to find
out the mid of the message that was published, and to determine whether the
message has been published, and/or wait until it is published.
......@@ -324,7 +313,7 @@ class MQTTMessageInfo:
return self._published
class MQTTMessage:
class MQTTMessage(object):
""" This is a class that describes an incoming or outgoing message. It is
passed to the on_message callback as the message parameter.
......@@ -2046,14 +2035,11 @@ class Client(object):
return self._packet_queue(command, packet, 0, 0)
def _send_connect(self, keepalive, clean_session):
if self._protocol == MQTTv31:
protocol = PROTOCOL_NAMEv31
proto_ver = 3
else:
protocol = PROTOCOL_NAMEv311
proto_ver = 4
protocol = protocol.encode('utf-8')
proto_ver = self._protocol
protocol = b"MQTT" if proto_ver >= MQTTv311 else b"MQIsdp" # hard-coded UTF-8 encoded string
remaining_length = 2 + len(protocol) + 1 + 1 + 2 + 2 + len(self._client_id)
connect_flags = 0
if clean_session:
connect_flags |= 0x02
......@@ -2583,7 +2569,7 @@ class Mosquitto(Client):
super(Mosquitto, self).__init__(client_id, clean_session, userdata)
class WebsocketWrapper:
class WebsocketWrapper(object):
OPCODE_CONTINUATION = 0x0
OPCODE_TEXT = 0x1
OPCODE_BINARY = 0x2
......
......@@ -248,7 +248,9 @@ def to_string(packet):
def gen_connect(client_id, clean_session=True, keepalive=60, username=None, password=None, will_topic=None, will_qos=0,
will_retain=False, will_payload="", proto_name="MQTT", proto_ver=4):
will_retain=False, will_payload="", proto_name=None, proto_ver=4):
proto_name = b"MQTT" if proto_ver >= 4 else b"MQIsdp"
if client_id is None:
remaining_length = 12
else:
......@@ -277,7 +279,7 @@ def gen_connect(client_id, clean_session=True, keepalive=60, username=None, pass
rl = pack_remaining_length(remaining_length)
packet = struct.pack("!B" + str(len(rl)) + "s", 0x10, rl)
packet = packet + struct.pack("!H" + str(len(proto_name)) + "sBBH",
len(proto_name), proto_name.encode('utf-8'),
len(proto_name), proto_name,
proto_ver, connect_flags, keepalive)
if client_id is not None:
packet = packet + struct.pack("!H" + str(len(client_id)) + "s", len(client_id), client_id)
......
......@@ -20,16 +20,16 @@ import paho_test
from testsupport.broker import fake_broker
@pytest.mark.parametrize("proto_ver,proto_name", [
(client.MQTTv31, "MQIsdp"),
(client.MQTTv311, "MQTT"),
@pytest.mark.parametrize("proto_ver", [
(client.MQTTv31),
(client.MQTTv311),
])
class Test_connect(object):
"""
Tests on connect/disconnect behaviour of the client
"""
def test_01_con_discon_success(self, proto_ver, proto_name, fake_broker):
def test_01_con_discon_success(self, proto_ver, fake_broker):
mqttc = client.Client(
"01-con-discon-success", protocol=proto_ver)
......@@ -47,7 +47,7 @@ class Test_connect(object):
connect_packet = paho_test.gen_connect(
"01-con-discon-success", keepalive=60,
proto_name=proto_name, proto_ver=proto_ver)
proto_ver=proto_ver)
packet_in = fake_broker.receive_packet(1000)
assert packet_in # Check connection was not closed
assert packet_in == connect_packet
......@@ -68,7 +68,7 @@ class Test_connect(object):
packet_in = fake_broker.receive_packet(1)
assert not packet_in # Check connection is closed
def test_01_con_failure_rc(self, proto_ver, proto_name, fake_broker):
def test_01_con_failure_rc(self, proto_ver, fake_broker):
mqttc = client.Client(
"01-con-failure-rc", protocol=proto_ver)
......@@ -85,7 +85,7 @@ class Test_connect(object):
connect_packet = paho_test.gen_connect(
"01-con-failure-rc", keepalive=60,
proto_name=proto_name, proto_ver=proto_ver)
proto_ver=proto_ver)
packet_in = fake_broker.receive_packet(1000)
assert packet_in # Check connection was not closed
assert packet_in == connect_packet
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册