提交 8569c40b 编写于 作者: R Roger Light 提交者: GitHub

Merge pull request #74 from yoch/clientid

fix for #73
......@@ -37,6 +37,7 @@ import threading
import time
import uuid
import base64
import string
import hashlib
try:
# Use monotionic clock if available
......@@ -199,6 +200,17 @@ def connack_string(connack_code):
return "Connection Refused: unknown reason."
def base62(num, base=string.digits+string.ascii_letters, padding=1):
"""Convert a number to base-62 representation."""
assert num >= 0
digits = []
while num:
num, rest = divmod(num, 62)
digits.append(base[rest])
digits.extend(base[0] for _ in range(len(digits), padding))
return ''.join(reversed(digits))
def topic_matches_sub(sub, topic):
"""Check whether a topic matches a subscription.
......@@ -453,9 +465,10 @@ class Client(object):
self._message_retry = 20
self._last_retry_check = 0
self._clean_session = clean_session
if client_id == "" or client_id is None:
if protocol == MQTTv31:
self._client_id = "paho/" + "".join(random.choice("0123456789ADCDEF") for x in range(23-5))
self._client_id = base62(uuid.uuid4().int, padding=22)
else:
self._client_id = ""
else:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册