
    	h             
      0   U d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZmZmZmZmZmZmZmZmZmZm Z  ddl!m"Z" ddl#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z, ddl-m.Z. dd	l/m0Z0 dd
l1m2Z2m3Z3 ddl4m5Z5 	 ddlm6Z6 n# e7$ r	 ddl8m6Z6 Y nw xY wer\	 ddlm9Z9 n# e7$ r	 ddl8m9Z9 Y nw xY w	 ddlm:Z: n# e7$ r	 ddl8m:Z: Y nw xY w G d de9          Z; G d de9          Z< G d de:          Z=	 ddl>Z>n# e7$ r dZ>Y nw xY w	 ddl?Z?n# e7$ r dZ?Y nw xY w	 ej@        ZAn# eB$ r
 ej        ZAY nw xY w	 ddlCZDdZEn# e7$ r dZEY nw xY w e	jF                    dk    rejG        ZHnejH        ZHe3ZIe(jJ        ZJe(jK        ZKe(jL        ZLe(jM        ZMe(jN        ZNe(jO        ZOe(jP        ZPe(jQ        ZQe(jR        ZRe(jS        ZSe(jT        ZTe(jU        ZUe(jV        ZVe(jW        ZWe(jX        ZXe&jY        ZYe&jZ        ZZe&j[        Z[e&j\        Z\e&j]        Z]e&j]        ej^        e&jY        ej_        e&jZ        ej_        e&j[        ej`        e&j\        eja        iZbe%jc        Zce%jd        Zde%je        Zee%jf        Zfe%jg        Zge%jh        Zhe'ji        Zje'jk        Zle'jm        Zne'jo        Zpe'jq        Zre'js        Zte'ju        Zve'jw        Zxe'jy        Zze'j{        Z|e)j}        Z}e)j~        Z~e)j        Ze)j        Ze)j        Ze)j        Ze)j        Ze)j        Ze)j        Ze)j        Ze)j        Ze)j        Ze)j        Ze)j        Ze)j        Ze)j        Ze)j        Ze)j        Ze*j        Ze*j        Ze*j        Ze+j        Ze+j        ZdZded<   dZeeeeeedf         Zeeef         Zeeegef         ef         Zeee6d         f         Z G d de          Z G d de          Zed eeeef         e)gdf         Zed eeeef         e2ee0df         gdf         Zeeef         Zed eee2ee0df         gdf         Zeeef         Zed egdf         Zed ee)gdf         Zed eee2edf         ee0df         gdf         Zeeef         Zed eee2ee0df         gdf         Zeeef         Zed eeegdf         Zed ed!gdf         Zed egdf         Zed eegdf         Zed eee2e0gdf         Zeeef         Zed edgdf         Zed eeeed"f         gdf         Zed eeee2         e0gdf         Zeeef         Zed eeee2         ee0df         gdf         Zeeef         Zed eegdf         Zed eee0ee2ee2         f         gdf         Zeeef         Zed eeee2         ee0df         gdf         Zeeef         ZeZ G d# d$e          ZdLd)ZdMd,ZdNd/ZdOd2Zej        ej        z   dfdPd7ZdQd;ZdRd=ZdSdAZdTdEZ G dF dG          Z G dH d!          Z G dI d           Z G dJ dK          ZdS )Uz
This is an MQTT client module. MQTT is a lightweight pub/sub messaging
protocol that is easy to implement and suitable for low powered devices.
    )annotationsN)TYPE_CHECKINGAnyCallableDictIteratorList
NamedTupleSequenceTupleUnioncast)PacketTypes   )	CallbackAPIVersionConnackCodeLogLevelMessageStateMessageTypeMQTTErrorCodeMQTTProtocolVersionPahoClientMode_ConnectionState)MQTTMatcher)
Properties)
ReasonCodeReasonCodes)SubscribeOptions)Literal)	TypedDict)Protocolc                  `    e Zd ZU ded<   ded<   ded<   ded<   ded<   ded	<   ded
<   ded<   dS )	_InPacketintcommandhave_remainingz	list[int]remaining_countremaining_multremaining_length	bytearraypacket
to_processposN__name__
__module____qualname____annotations__     ]/var/www/html/web-builder-api.evdpl.com/venv/lib/python3.11/site-packages/paho/mqtt/client.pyr#   r#   @   sg         """"r4   r#   c                  V    e Zd ZU ded<   ded<   ded<   ded<   ded<   ded<   d	ed
<   dS )
_OutPacketr$   r%   midqosr-   r,   bytesr+   MQTTMessageInfo | NoneinfoNr.   r3   r4   r5   r7   r7   K   sT         $$$$$$r4   r7   c                  6    e Zd ZddZddZdd	Zdd
ZddZdS )
SocketLikebuffer_sizer$   returnr:   c                    d S Nr3   )selfr?   s     r5   recvzSocketLike.recvU       Cr4   bufferc                    d S rB   r3   )rC   rF   s     r5   sendzSocketLike.sendW   rE   r4   Nonec                    d S rB   r3   rC   s    r5   closezSocketLike.closeY   rE   r4   c                    d S rB   r3   rK   s    r5   filenozSocketLike.fileno[   rE   r4   flagboolc                    d S rB   r3   rC   rO   s     r5   setblockingzSocketLike.setblocking]   rE   r4   N)r?   r$   r@   r:   )rF   r:   r@   r$   r@   rI   r@   r$   rO   rP   r@   rI   )r/   r0   r1   rD   rH   rL   rN   rS   r3   r4   r5   r>   r>   T   sx        	 	 	 		 	 	 		 	 	 		 	 	 		 	 	 	 	 	r4   r>   TFWindows   CleanStartOptionMQTT_CLEAN_START_FIRST_ONLY   0c                      e Zd ZU dZded<   dS )ConnectFlagsz?Contains additional information passed to `on_connect` callbackrP   session_presentNr/   r0   r1   __doc__r2   r3   r4   r5   r]   r]      s(         II r4   r]   c                      e Zd ZU dZded<   dS )DisconnectFlagszBContains additional information passed to `on_disconnect` callbackrP    is_disconnect_packet_from_serverNr_   r3   r4   r5   rb   rb      s(         LL**** r4   rb   ClientMQTTMessage.c                      e Zd ZdZdS )WebsocketConnectionErrorz WebsocketConnectionError is a subclass of ConnectionError.

        It's raised when unable to perform the Websocket handshake.
    N)r/   r0   r1   r`   r3   r4   r5   rg   rg     s          	Dr4   rg   
mqtt_errnoMQTTErrorCode | intr@   strc                   | t           k    rdS | t          k    rdS | t          k    rdS | t          k    rdS | t          k    rdS | t
          k    rdS | t          k    rdS | t          k    rdS | t          k    rd	S | t          k    rd
S | t          k    rdS | t          k    rdS | t          k    rdS | t          k    rdS | t          k    rdS | t          k    rdS | t           k    rdS dS )z=Return the error string associated with an mqtt error number.z	No error.zOut of memory.zEA network protocol error occurred when communicating with the broker.z$Invalid function arguments provided.z&The client is not currently connected.zThe connection was refused.z#Message not found (internal error).zThe connection was lost.zA TLS error occurred.Payload too large.zThis feature is not supported.zAuthorisation failed.zAccess denied by ACL.zUnknown error.zError defined by errno.zMessage queue full.z?Client or broker did not communicate in the keepalive interval.)MQTT_ERR_SUCCESSMQTT_ERR_NOMEMMQTT_ERR_PROTOCOLMQTT_ERR_INVALMQTT_ERR_NO_CONNMQTT_ERR_CONN_REFUSEDMQTT_ERR_NOT_FOUNDMQTT_ERR_CONN_LOSTMQTT_ERR_TLSMQTT_ERR_PAYLOAD_SIZEMQTT_ERR_NOT_SUPPORTEDMQTT_ERR_AUTHMQTT_ERR_ACL_DENIEDMQTT_ERR_UNKNOWNMQTT_ERR_ERRNOMQTT_ERR_QUEUE_SIZEMQTT_ERR_KEEPALIVE)rh   s    r5   error_stringr~   #  s4   %%%{	~	%	%	(	(	(VV	~	%	%55	'	'	'77	,	,	,,,	)	)	)44	)	)	)))	|	#	#&&	,	,	,##	-	-	-//	}	$	$&&	*	*	*&&	'	'	'	~	%	%((	*	*	*$$	)	)	)PPr4   connack_codeint | ReasonCodec                    t          | t                    rt          |           S | t          k    rdS | t          k    rdS | t
          k    rdS | t          k    rdS | t          k    rdS | t          k    rdS dS )zJReturn the string associated with a CONNACK result or CONNACK reason code.zConnection Accepted.z2Connection Refused: unacceptable protocol version.z(Connection Refused: identifier rejected.z'Connection Refused: broker unavailable.z.Connection Refused: bad user name or password.z#Connection Refused: not authorised.z#Connection Refused: unknown reason.)	
isinstancer   rj   CONNACK_ACCEPTED CONNACK_REFUSED_PROTOCOL_VERSION#CONNACK_REFUSED_IDENTIFIER_REJECTED"CONNACK_REFUSED_SERVER_UNAVAILABLE%CONNACK_REFUSED_BAD_USERNAME_PASSWORDCONNACK_REFUSED_NOT_AUTHORIZEDr   s    r5   connack_stringr   K  s    ,
++ !<   '''%%	9	9	9CC	<	<	<99	;	;	;88	>	>	>??	7	7	74444r4   r   r   c                .   | t           j        k    rt          t          j        d          S | t           j        k    rt          t          j        d          S | t           j        k    rt          t          j        d          S | t           j        k    rt          t          j        d          S | t           j        k    rt          t          j        d          S | t           j	        k    rt          t          j        d          S t          t          j        d          S )aK  Convert a MQTTv3 / MQTTv3.1.1 connack result to `ReasonCode`.

    This is used in `on_connect` callback to have a consistent API.

    Be careful that the numeric value isn't the same, for example:

    >>> ConnackCode.CONNACK_REFUSED_SERVER_UNAVAILABLE == 3
    >>> convert_connack_rc_to_reason_code(ConnackCode.CONNACK_REFUSED_SERVER_UNAVAILABLE) == 136

    It's recommended to compare by names

    >>> code_to_test = ReasonCode(PacketTypes.CONNACK, "Server unavailable")
    >>> convert_connack_rc_to_reason_code(ConnackCode.CONNACK_REFUSED_SERVER_UNAVAILABLE) == code_to_test
    SuccessUnsupported protocol versionzClient identifier not validzServer unavailablezBad user name or passwordzNot authorizedUnspecified error)
r   r   r   r   CONNACKr   r   r   r   r   r   s    r5   !convert_connack_rc_to_reason_coder   `  s     {333+-y999{CCC+-/MNNN{FFF+-/LMMM{EEE+-/CDDD{HHH+-/JKKK{AAA+-/?@@@k)+>???r4   rcr   c                2   | t           j        k    rt          t          j        d          S | t           j        k    rt          t          j        d          S | t           j        k    rt          t          j        d          S t          t          j        d          S )a!  Convert an MQTTErrorCode to Reason code.

    This is used in `on_disconnect` callback to have a consistent API.

    Be careful that the numeric value isn't the same, for example:

    >>> MQTTErrorCode.MQTT_ERR_PROTOCOL == 2
    >>> convert_disconnect_error_code_to_reason_code(MQTTErrorCode.MQTT_ERR_PROTOCOL) == 130

    It's recommended to compare by names

    >>> code_to_test = ReasonCode(PacketTypes.DISCONNECT, "Protocol error")
    >>> convert_disconnect_error_code_to_reason_code(MQTTErrorCode.MQTT_ERR_PROTOCOL) == code_to_test
    r   zKeep alive timeoutr   )r   rm   r   r   
DISCONNECTr}   rt   )r   s    r5   ,convert_disconnect_error_code_to_reason_coder     s}     
]++++0)<<<	]---+02FGGG	]---+02EFFFk,.ABBBr4   numr$   basepaddingc                R   | dk     rt          d          g }| r0t          | d          \  } }|                    |                    | 0|                    fdt	          t          |          |          D                        d                    t          |                    S )z+Convert a number to base-62 representation.r   zNumber must be positive or zero>   c              3  (   K   | ]}d          V  dS )r   Nr3   ).0_r   s     r5   	<genexpr>z_base62.<locals>.<genexpr>  s'      ??a$q'??????r4    )
ValueErrordivmodappendextendrangelenjoinreversed)r   r   r   digitsrests    `   r5   _base62r     s     Qww:;;;F
 "3OO	Td4j!!!  " MM????5Vg#>#>??????778F##$$$r4   subtopicrP   c                    t                      }d|| <   	 t          |                    |                     dS # t          $ r Y dS w xY w)zCheck whether a topic matches a subscription.

    For example:

    * Topic "foo/bar" would match the subscription "foo/#" or "+/bar"
    * Topic "non/matching" would not match the subscription "non/+/+"
    TF)r   next
iter_matchStopIteration)r   r   matchers      r5   topic_matches_subr     s^     mmGGCLW&&'''t   uus   "9 
AA#tuple[socket.socket, socket.socket]c                    t          j         t           j        t           j        t           j                  } |                     t           j        t           j        d           |                     d           |                     d           | 	                                \  }}t          j         t           j        t           j        t           j                  }|
                    d           	 |                    d|f           n# t          $ r Y nw xY w|                                 \  }}|
                    d           |                                  ||fS )z+TCP/IP socketpair including Windows supportr   )	127.0.0.1r   Fr   )socketAF_INETSOCK_STREAM
IPPROTO_IP
setsockopt
SOL_SOCKETSO_REUSEADDRbindlistengetsocknamerS   connectBlockingIOErroracceptrL   )
listensockifaceportsock1sock2addresss         r5   _socketpair_compatr     s4   *F,=? ?J&+V-@!DDDOO$%%%a((**KE4M*F,=? ?E	e{D)****   &&((NE7	e5>s   +D 
DDsstr | bytesr:   c                Z    t          | t                    r|                     d          S | S )Nutf-8)r   rj   encode)r   s    r5   _force_bytesr     s+    !S !xx   Hr4   payload,str | bytes | bytearray | int | float | Nonebytes | bytearrayc                4   t          | t                    r|                     d          S t          | t          t          f          r"t          |                               d          S | dS t          | t
          t          f          st          d          | S )Nr   asciir4   z8payload must be a string, bytearray, int, float or None.)r   rj   r   r$   floatr:   r*   	TypeError)r   s    r5   _encode_payloadr     s    '3 '~~g&&&'C<(( ,7||""7+++sgy122 
F
 
 	
 Nr4   c                  `    e Zd ZdZdZddZddZdd
ZddZddZ	ddZ
ddZdddZd dZdS )!MQTTMessageInfozThis 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.
    )r8   
_published
_conditionr   _iterposr8   r$   c                    || _         	 d| _        t          j                    | _        t
          j        | _        	 d| _        d S NFr   )	r8   r   	threading	Conditionr   r   rm   r   r   rC   r8   s     r5   __init__zMQTTMessageInfo.__init__  s>    ##-//!.!?	Dr4   r@   rj   c                8    t          | j        | j        f          S rB   )rj   r   r8   rK   s    r5   __str__zMQTTMessageInfo.__str__  s    DGTX&'''r4   Iterator[MQTTErrorCode | int]c                    d| _         | S Nr   )r   rK   s    r5   __iter__zMQTTMessageInfo.__iter__  s    r4   ri   c                *    |                                  S rB   )r   rK   s    r5   __next__zMQTTMessageInfo.__next__  s    yy{{r4   c                t    | j         dk    rd| _         | j        S | j         dk    rd| _         | j        S t          )Nr   r      )r   r   r8   r   rK   s    r5   r   zMQTTMessageInfo.next  s>    =ADM7N]aDM8Or4   indexc                T    |dk    r| j         S |dk    r| j        S t          d          )Nr   r   zindex out of range)r   r8   
IndexError)rC   r   s     r5   __getitem__zMQTTMessageInfo.__getitem__  s1    A::7NaZZ8O1222r4   rI   c                    | j         5  d| _        | j                                          d d d            d S # 1 swxY w Y   d S )NT)r   r   notifyrK   s    r5   _set_as_publishedz!MQTTMessageInfo._set_as_published  s    _ 	% 	%"DOO""$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s   !6::Ntimeoutfloat | Nonec                "   | j         t          k    rt          d          | j         t          k    rn/| j         dk    r$t	          dt          | j                              |dnt                      |z   |dn|dz  }d	fd}| j        5  | j        s5 |            s+| j        	                    |           | j        s
 |            +ddd           n# 1 swxY w Y   | j         dk    r$t	          dt          | j                              dS )
a  Block until the message associated with this object is published, or
        until the timeout occurs. If timeout is None, this will never time out.
        Set timeout to a positive number of seconds, e.g. 1.2, to enable the
        timeout.

        :raises ValueError: if the message was not queued due to the outgoing
            queue being full.

        :raises RuntimeError: if the message was not published for another
            reason.
        +Message is not queued due to ERR_QUEUE_SIZEr   Message publish failed: Ng      $@r@   rP   c                 0     dnt                       k    S )NF)	time_func)timeout_times   r5   	timed_outz3MQTTMessageInfo.wait_for_publish.<locals>.timed_out.  s    (055ikkL6PPr4   r@   rP   )
r   r|   r   MQTT_ERR_AGAINRuntimeErrorr~   r   r   r   wait)rC   r   timeout_tenthr   r   s       @r5   wait_for_publishz MQTTMessageInfo.wait_for_publish  s    7)))JKKKW&&Wq[[Q,tw:O:OQQRRR&ttIKK'4I 'Ws]	Q 	Q 	Q 	Q 	Q 	Q _ 	4 	4o 4iikk 4$$]333 o 4iikk 4	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 7Q;;Q,tw:O:OQQRRR ;s   =CCCrP   c                $   | j         t          j        k    rt          d          | j         t          j        k    rn/| j         dk    r$t          dt          | j                              | j        5  | j        cddd           S # 1 swxY w Y   dS )zReturns True if the message associated with this object has been
        published, else returns False.

        To wait for this to become true, look at `wait_for_publish`.
        r   r   r   N)	r   r   r|   r   r   r   r~   r   r   rK   s    r5   is_publishedzMQTTMessageInfo.is_published8  s     7m777JKKKW444Wq[[Q,tw:O:OQQRRR_ 	# 	#?	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#s   1BB	B	)r8   r$   r@   rj   )r@   r   )r@   ri   )r   r$   r@   ri   rT   rB   )r   r   r@   rI   r   )r/   r0   r1   r`   	__slots__r   r   r   r   r   r   r   r  r  r3   r4   r5   r   r     s         
 DI   ( ( ( (             3 3 3 3% % % %
S S S S S># # # # # #r4   r   c                  j    e Zd ZdZdZddd	ZddZddZedd            Z	e	j
        dd            Z	dS )re   z This is a class that describes an incoming message. It is
    passed to the `on_message` callback as the message parameter.
    )
	timestampstatedupr8   _topicr   r9   retainr<   
propertiesr   r4   r8   r$   r   r:   c                    d| _         t          | _        d| _        || _        	 || _        d| _        	 d| _        	 d| _        	 t          |          | _
        d | _        d S )N        Fr4   r   )r  mqtt_ms_invalidr  r	  r8   r
  r   r9   r  r   r<   r  )rC   r8   r   s      r5   r   zMQTTMessage.__init__O  sb    $
$):H#C((	-1WWr4   otherobjectr@   rP   c                P    t          || j                  r| j        |j        k    S dS )z$Override the default Equals behaviorF)r   	__class__r8   rC   r  s     r5   __eq__zMQTTMessage.__eq__`  s*    eT^,, 	)8uy((ur4   c                .    |                      |           S )zDefine a non-equality test)r  r  s     r5   __ne__zMQTTMessage.__ne__f  s    ;;u%%%%r4   rj   c                6    | j                             d          S )zVtopic that the message was published on.

        This property is read-only.
        r   )r
  decoderK   s    r5   r   zMQTTMessage.topicj  s     {!!'***r4   valuerI   c                    || _         d S rB   )r
  rC   r  s     r5   r   zMQTTMessage.topicr  s    r4   N)r   r4   )r8   r$   r   r:   )r  r  r@   rP   r  )r  r:   r@   rI   )r/   r0   r1   r`   r  r   r  r  propertyr   setterr3   r4   r5   re   re   I  s          oIX X X X X"   & & & & + + + X+ \   \  r4   c                      e Zd ZdZej        dddedddfdCdZdDdZe	dEd            Z
e
j        dFd            Z
e	dGd            Zej        dHd             Ze	dGd!            Zej        dHd"            Ze	dId#            Zej        dJd%            Ze	dKd&            Ze	dLd(            Zej        dMd)            Ze	dNd*            Zej        dOd+            Ze	dNd,            Zej        dOd-            Ze	dGd.            Zej        dHd/            Ze	dGd0            Zej        dHd1            Ze	dNd2            Ze	dPd4            Ze	dQd6            Zej        dRd7            ZdSd:ZdTd<ZdDd=ZdUdVd?Z	 	 	 dWdXd@Z	 	 dYdZdEZ	 d[d\dHZ	 	 	 	 	 	 	 	 d]d^dTZd_dUZ d`dWZ!d[dadYZ"dDdZZ#d[d\dd]e$dfdbdhZ%dd\dd]e$dfdcdjZ&d[d\dd]e$dfdddkZ'dedfdpZ(dgdqZ)dhdidtZ*dhdiduZ+	 	 	 	 djdkd|Z,	 d[dldZ-dDdZ.dmdZ/dmdZ0	 	 dndodZ1	 	 	 dpdqdZ2	 d[drdZ3dsdtdZ4dgdZ5dmdZ6dgdZ7dudZ8dvdZ9dwdZ:dxdZ;	 	 	 	 djdydZ<dDdZ=dzdZ>	 	 d{d|dZ?dgdZ@dgdZAe	d}d            ZBe	d~d            ZCeCj        dd            ZCddZDe	dd            ZEeEj        dd            ZEddZFe	dd            ZGeGj        dd            ZGddZHe	dd            ZIeIj        dd            ZIddZJe	dd            ZKeKj        dd            ZKddZLe	dd            ZMeMj        dd            ZMddZNe	dd            ZOeOj        dd            ZOddĄZPe	ddƄ            ZQeQj        ddǄ            ZQddɄZRe	dd˄            ZSeSj        dd̄            ZSdd΄ZTe	ddЄ            ZUeUj        ddф            ZUddӄZVddքZWe	ddׄ            ZXeXj        dd؄            ZXddلZYddڄZZe	ddۄ            Z[e[j        dd܄            Z[dd݄Z\dDdބZ]e	dd߄            Z^e^j        dd            Z^ddZ_	 d[ddZ`ddZaddZbddZcddZddgdZedgdZfddZgdDdZhdGdZiejdd            Zkejdd            ZldgdZmdgdZnddZoddZpddZqddZr	 	 	 	 	 	 dddZsddZtdd	ZuddZvddZwddZx	 	 dndodZy	 d[ddZz	 d[ddZ{dmdZ|dDdZ}dDdZ~dDdZ	 d[ddZdgdZdgdZdgdZdgdZdDdZdDdZdgd Zdd!Zdd#Zdgd$Zdgd%Zdgd&Zdgd'Z	 	 dndd+Zdd/Zdd2Zdd5ZdDd6ZdDd7ZdDd8Zejdmd9            Zdd;Zdd<Zdd>Zdd?ZddBZdS (  rd   a  MQTT version 3.1/3.1.1/5.0 client class.

    This is the main class for use communicating with an MQTT broker.

    General usage flow:

    * Use `connect()`, `connect_async()` or `connect_srv()` to connect to a broker
    * Use `loop_start()` to set a thread running to call `loop()` for you.
    * Or use `loop_forever()` to handle calling `loop()` for you in a blocking function.
    * Or call `loop()` frequently to maintain network traffic flow with the broker
    * Use `subscribe()` to subscribe to a topic and receive messages
    * Use `publish()` to send messages
    * Use `disconnect()` to disconnect from the broker

    Data returned from the broker is made available with the use of callback
    functions as described below.

    :param CallbackAPIVersion callback_api_version: define the API version for user-callback (on_connect, on_publish,...).
        This field is required and it's recommended to use the latest version (CallbackAPIVersion.API_VERSION2).
        See each callback for description of API for each version. The file docs/migrations.rst contains details on
        how to migrate between version.

    :param str client_id: the unique client id string used when connecting to the
        broker. If client_id is zero length or None, then the behaviour is
        defined by which protocol version is in use. If using MQTT v3.1.1, then
        a zero length client id will be sent to the broker and the broker will
        generate a random for the client. If using MQTT v3.1 then an id will be
        randomly generated. In both cases, clean_session must be True. If this
        is not the case a ValueError will be raised.

    :param bool clean_session: a boolean that determines the client type. If True,
        the broker will remove all information about this client when it
        disconnects. If False, the client is a persistent client and
        subscription information and queued messages will be retained when the
        client disconnects.
        Note that a client will never discard its own outgoing messages on
        disconnect. Calling connect() or reconnect() will cause the messages to
        be resent.  Use reinitialise() to reset a client to its original state.
        The clean_session argument only applies to MQTT versions v3.1.1 and v3.1.
        It is not accepted if the MQTT version is v5.0 - use the clean_start
        argument on connect() instead.

    :param userdata: user defined data of any type that is passed as the "userdata"
        parameter to callbacks. It may be updated at a later point with the
        user_data_set() function.

    :param int protocol: allows explicit setting of the MQTT version to
        use for this client. Can be paho.mqtt.client.MQTTv311 (v3.1.1),
        paho.mqtt.client.MQTTv31 (v3.1) or paho.mqtt.client.MQTTv5 (v5.0),
        with the default being v3.1.1.

    :param transport: use "websockets" to use WebSockets as the transport
        mechanism. Set to "tcp" to use raw TCP, which is the default.
        Use "unix" to use Unix sockets as the transport mechanism; note that
        this option is only available on platforms that support Unix sockets,
        and the "host" argument is interpreted as the path to the Unix socket
        file in this case.

    :param bool manual_ack: normally, when a message is received, the library automatically
        acknowledges after on_message callback returns.  manual_ack=True allows the application to
        acknowledge receipt after it has completed processing of a message
        using a the ack() method. This addresses vulnerability to message loss
        if applications fails while processing a message, or while it pending
        locally.

    Callbacks
    =========

    A number of callback functions are available to receive data back from the
    broker. To use a callback, define a function and then assign it to the
    client::

        def on_connect(client, userdata, flags, reason_code, properties):
            print(f"Connected with result code {reason_code}")

        client.on_connect = on_connect

    Callbacks can also be attached using decorators::

        mqttc = paho.mqtt.Client()

        @mqttc.connect_callback()
        def on_connect(client, userdata, flags, reason_code, properties):
            print(f"Connected with result code {reason_code}")

    All of the callbacks as described below have a "client" and an "userdata"
    argument. "client" is the `Client` instance that is calling the callback.
    userdata" is user data of any type and can be set when creating a new client
    instance or with `user_data_set()`.

    If you wish to suppress exceptions within a callback, you should set
    ``mqttc.suppress_exceptions = True``

    The callbacks are listed below, documentation for each of them can be found
    at the same function name:

    `on_connect`, `on_connect_fail`, `on_disconnect`, `on_message`, `on_publish`,
    `on_subscribe`, `on_unsubscribe`, `on_log`, `on_socket_open`, `on_socket_close`,
    `on_socket_register_write`, `on_socket_unregister_write`
    r   NtcpTFcallback_api_versionr   	client_id
str | Noneclean_sessionbool | Noneuserdatar   protocolr   	transport$Literal['tcp', 'websockets', 'unix']reconnect_on_failurerP   
manual_ackr@   rI   c	           	        |                                 }|dk    r$t          t          d          st          d          |dvrt          d|           || _        || _        || _        || _        d | _        d | _	        d | _
        d| _        d| _        t          | _        || _        | j        t           j        k    rt%          j        dt(          d	
           t+          | j        t,                    rt          d          | j        t           vrt          d          t.          | _        |t2          k    r|t          d          n$|d}|s|dk    s|t          d          || _        |dk    s|S|t6          k    r@t9          t;          j                    j        d                               d          | _!        nd| _!        ntE          |          | _!        d | _#        d | _$        ddg ddtK          d          ddd| _&        tO          j(                    | _)        tU                      | _+        tU                      | _,        d| _-        d| _.        d | _/        || _0        d| _1        d| _2        tf          j4        | _5        tO          j6                    | _7        tO          j6                    | _8        d| _9        d| _:        d| _;        d | _<        d | _=        d| _>        d| _?        d| _@        d| _A        d| _B        t                      | _D        d| _E        d| _F        d| _G        d| _H        i | _I        t          jK                    | _L        t          jM                    | _N        t          jK                    | _O        t          jM                    | _P        t          jK                    | _Q        t          jK                    | _R        t          jK                    | _S        d | _T        d| _U        d| _V        d | _W        d| _X        d | _Y        d| _Z        d | _[        d | _\        d | _]        d | _^        d | __        d | _`        d | _a        d | _b        d | _c        d | _d        d | _e        d | _f        d | _g        d| _h        d | _i        d| _j        d| _k        d S )NunixAF_UNIXz"unix" transport not supported)
websocketsr   r-  z5transport must be "websockets", "tcp" or "unix", not <   g      @z>Callback API version 1 is deprecated, update to latest versionr   )category
stacklevelzoUnsupported callback API version: version 2.0 added a callback_api_version, see docs/migrations.rst for details Unsupported callback API versionz&Clean session is not used for MQTT 5.0Tr   z7A client id must be provided if clean session is False.   r   utf8r4   r   r   r%   r&   r'   r(   r)   r+   r,   r-   x   r     F[  /mqtt)llowerhasattrr   r   _manual_ack
_transport	_protocol	_userdata_sock
_sockpairR
_sockpairW
_keepalive_connect_timeoutMQTT_CLIENT_client_mode_callback_api_versionr   VERSION1warningswarnDeprecationWarningr   rj   rZ   _clean_startMQTTv5_clean_sessionMQTTv31r   uuiduuid4r$   r   
_client_idr   	_username	_passwordr*   
_in_packetcollectionsdeque_out_packetr   _last_msg_in_last_msg_out_reconnect_min_delay_reconnect_max_delay_reconnect_delay_reconnect_on_failure_ping_t	_last_midr   MQTT_CS_NEW_stateOrderedDict_out_messages_in_messages_max_inflight_messages_inflight_messages_max_queued_messages_connect_properties_will_properties_will_will_topic_will_payload	_will_qos_will_retainr   _on_message_filtered_host_port_bind_address
_bind_port_proxyr   Lock_in_callback_mutexRLock_callback_mutex_msgtime_mutex_out_message_mutex_in_message_mutex_reconnect_delay_mutex_mid_generate_mutex_thread_thread_terminate_ssl_ssl_context_tls_insecure_logger_registered_write_on_log_on_pre_connect_on_connect_on_connect_fail_on_subscribe_on_message_on_publish_on_unsubscribe_on_disconnect_on_socket_open_on_socket_close_on_socket_register_write_on_socket_unregister_write_websocket_path_websocket_extra_headers_mqttv5_first_connectsuppress_exceptions)	rC   r!  r"  r$  r&  r'  r(  r*  r+  s	            r5   r   zClient.__init__  s    OO%%	wvy'A'A=>>>;;;S	SSU U U &#!!(,
0404 #'%9"%);)DDDMP+   
 d0#66 	  B   %-????@@@!<v( !IJJJ ) $ $  Oi2oo9J MO O O"/D ??i/7""")$*,,*:B"G"G"G"N"Nv"V"V"%*955DO'+'+! !nn	&
 	&
 ;F:K:M:M%KK&[[$%!$'!,0%9"&2 #%% 	
 #%% 	 ')#"#$%!6: 37
 !$/MM!

"+."2"2(00'n.."+/"3"3!*!1!1&/n&6&6##,>#3#3 04!&	37".2!&-1<@59>B9=5959=A;?8<9=BF&DH(&AE%%)"#(   r4   c                .    |                                   d S rB   )_reset_socketsrK   s    r5   __del__zClient.__del__o  s    r4   rj   c                    | j         S )z
        Host to connect to. If `connect()` hasn't been called yet, returns an empty string.

        This property may not be changed if the connection is already open.
        )rs  rK   s    r5   hostzClient.hostr       zr4   r  c                |    |                                  st          d          |st          d          || _        d S )Nz8updating host on established connection is not supportedInvalid host.)_connection_closedr   r   rs  r  s     r5   r  zClient.host{  sG    &&(( 	[YZZZ 	._---


r4   r$   c                    | j         S )z}
        Broker TCP port to connect to.

        This property may not be changed if the connection is already open.
        )rt  rK   s    r5   r   zClient.port  r  r4   c                    |                                  st          d          |dk    rt          d          || _        d S )Nz8updating port on established connection is not supportedr   Invalid port number.)r  r   r   rt  r  s     r5   r   zClient.port  sI    &&(( 	[YZZZA::3444


r4   c                    | j         S )z
        Client keepalive interval (in seconds).

        This property may not be changed if the connection is already open.
        )rE  rK   s    r5   	keepalivezClient.keepalive       r4   c                    |                                  st          d          |dk     rt          d          || _        d S )Nz=updating keepalive on established connection is not supportedr   zKeepalive must be >=0.)r  r   r   rE  r  s     r5   r  zClient.keepalive  sK    &&(( 	` ^___1995666r4   c                    | j         S )z
        Transport method used for the connection ("tcp" or "websockets").

        This property may not be changed if the connection is already open.
        )r?  rK   s    r5   r(  zClient.transport  r  r4   Literal['tcp', 'websockets']c                Z    |                                  st          d          || _        d S )Nz=updating transport on established connection is not supported)r  r   r?  r  s     r5   r(  zClient.transport  s1    &&(( 	`^___r4   c                    | j         S )zj
        Protocol version used (MQTT v3, MQTT v3.11, MQTTv5)

        This property is read-only.
        )r@  rK   s    r5   r'  zClient.protocol  s     ~r4   r   c                    | j         S )z
        Connection establishment timeout in seconds.

        This property may not be changed if the connection is already open.
        )rF  rK   s    r5   connect_timeoutzClient.connect_timeout  s     $$r4   c                    |                                  st          d          |dk    rt          d          || _        d S )NzCupdating connect_timeout on established connection is not supportedr  z!timeout must be a positive number)r  r   r   rF  r  s     r5   r  zClient.connect_timeout  sL    &&(( 	fdeeeC<<@AAA %r4   c                H    | j         dS | j                             d          S )zThe username used to connect to the MQTT broker, or None if no username is used.

        This property may not be changed if the connection is already open.
        Nr   )rU  r  rK   s    r5   usernamezClient.username  '     >!4~$$W---r4   c                    |                                  st          d          |	d | _        d S |                    d          | _        d S )Nz<updating username on established connection is not supportedr   )r  r   rU  r   r  s     r5   r  zClient.username  M    &&(( 	_]^^^=!DNNN"\\'22DNNNr4   c                H    | j         dS | j                             d          S )zThe password used to connect to the MQTT broker, or None if no password is used.

        This property may not be changed if the connection is already open.
        Nr   )rV  r  rK   s    r5   passwordzClient.password  r  r4   c                    |                                  st          d          |	d | _        d S |                    d          | _        d S )Nz<updating password on established connection is not supportedr   )r  r   rV  r   r  s     r5   r  zClient.password  r  r4   c                    | j         S )z
        Maximum number of messages with QoS > 0 that can be partway through the network flow at once

        This property may not be changed if the connection is already open.
        )rh  rK   s    r5   max_inflight_messageszClient.max_inflight_messages  s     **r4   c                    |                                  st          d          |dk     rt          d          || _        d S )NzIupdating max_inflight_messages on established connection is not supportedr   zInvalid inflight.)r  r   r   rh  r  s     r5   r  zClient.max_inflight_messages  sN    &&(( 	l jkkk1990111&+###r4   c                    | j         S )z
        Maximum number of message in the outgoing message queue, 0 means unlimited

        This property may not be changed if the connection is already open.
        )rj  rK   s    r5   max_queued_messageszClient.max_queued_messages  s     ((r4   c                    |                                  st          d          |dk     rt          d          || _        d S )NzGupdating max_queued_messages on established connection is not supportedr   zInvalid queue size.)r  r   r   rj  r  s     r5   r  zClient.max_queued_messages  sL    &&(( 	jhiii1992333$)!!!r4   c                H    | j         dS | j                             d          S )z
        The topic name a will message is sent to when disconnecting unexpectedly. None if a will shall not be sent.

        This property is read-only. Use `will_set()` to change its value.
        Nr   )rn  r  rK   s    r5   
will_topiczClient.will_topic(  s)     #4&&w///r4   bytes | Nonec                    | j         S )z
        The payload for the will message that is sent when disconnecting unexpectedly. None if a will shall not be sent.

        This property is read-only. Use `will_set()` to change its value.
        )ro  rK   s    r5   will_payloadzClient.will_payload4  s     !!r4   logging.Logger | Nonec                    | j         S rB   r  rK   s    r5   loggerzClient.logger=  s
    |r4   c                    || _         d S rB   r  r  s     r5   r  zClient.loggerA  s    r4   bufsizer:   c                   | j         t          d          	 | j                             |          S # t          j        $ r}t                      |d }~wt          j        $ r(}|                                  t                      |d }~wt          $ r0}| 	                    t          d|           t                      |d }~ww xY w)Nself._sock is Nonezsocket was None: %s)rB  ConnectionErrorrD   sslSSLWantReadErrorr   SSLWantWriteError_call_socket_register_writeAttributeError	_easy_logMQTT_LOG_DEBUG)rC   r  errs      r5   
_sock_recvzClient._sock_recvE  s    :!"6777
	-:??7+++# 	- 	- 	-!##,$ 	- 	- 	-,,...!##, 	- 	- 	-NN 5s< < <!##,	-s-   2 CAC"#BC+B==Cbufc                z   | j         t          d          	 | j                             |          S # t          j        $ r}t                      |d }~wt          j        $ r(}|                                  t                      |d }~wt
          $ r(}|                                  t                      |d }~ww xY w)Nr  )rB  r  rH   r  r  r   r  r  )rC   r  r  s      r5   
_sock_sendzClient._sock_sendT  s    :!"6777		-:??3'''# 	- 	- 	-!##,$ 	- 	- 	-,,...!##, 	- 	- 	-,,...!##,	-s-   2 B:AB:"#BB:#B55B:c                    | j         sdS 	 | j         }d| _         |                     |           |                     |           |                                 dS # |                                 w xY w)z#Close the connection to the server.N)rB  _call_socket_unregister_write_call_socket_closerL   rC   socks     r5   _sock_closezClient._sock_closec  sq    z 	F	:DDJ..t444##D))) JJLLLLLDJJLLLLs   8A A/sockpair_onlyc                    |s|                                   | j        r | j                                         d | _        | j        r"| j                                         d | _        d S d S rB   )r  rC  rL   rD  )rC   r  s     r5   r  zClient._reset_socketsq  st     	? 	#O!!###"DO? 	#O!!###"DOOO	# 	#r4   c                \    |                                   |                     |||           d S rB   )r  r   )rC   r"  r$  r&  s       r5   reinitialisezClient.reinitialise|  s2     	i99999r4   r;  pathheadersWebSocketHeaders | Nonec                    || _         |<t          |t                    st          |          r	|| _        dS t          d          dS )a   Set the path and headers for a websocket connection

        :param str path: a string starting with / which should be the endpoint of the
            mqtt connection on the remote server

        :param headers:  can be either a dict or a callable object. If it is a dict then
            the extra items in the dict are added to the websocket headers. If it is
            a callable, then the default websocket headers are passed into this
            function and the result is used as the new headers.
        NzL'headers' option to ws_set_options has to be either a dictionary or callable)r  r   dictcallabler  r   )rC   r  r  s      r5   ws_set_optionszClient.ws_set_options  sc      $'4(( dHW,=,= d07--- bd d d	 r4   contextssl.SSLContext | Nonec                    | j         t          d          |t          j                    }d| _        || _         t          |d          r|j         | _        dS dS )a.  Configure network encryption and authentication context. Enables SSL/TLS support.

        :param context: an ssl.SSLContext object. By default this is given by
            ``ssl.create_default_context()``, if available.

        Must be called before `connect()`, `connect_async()` or `connect_srv()`.Nz$SSL/TLS has already been configured.Tcheck_hostname)r  r   r  create_default_contextr  r=  r  r  )rC   r  s     r5   tls_set_contextzClient.tls_set_context  sq     (CDDD?022G	# 7,-- 	<%,%;!;D	< 	<r4   ca_certscertfilekeyfile	cert_reqsssl.VerifyMode | Nonetls_version
int | Nonecipherskeyfile_passwordalpn_protocolslist[str] | Nonec	                   t           t          d          t          t           d          st          d          |)t          t           j        d          st          d          |Ot           j        }t          t           d          rt           j        }n!t          t           d          rt           j        }t          j        |          }	||	                    |           ||	                    |||           |t           j	        k    rt          |	d	          rd
|	_
        |t           j        n||	_        ||	                    |           n|	                                 |:t          t           dd          st          d          |	                    |           |                     |	           |t           j	        k    r|                     d
           dS |                     d           dS )a  Configure network encryption and authentication options. Enables SSL/TLS support.

        :param str ca_certs: a string path to the Certificate Authority certificate files
            that are to be treated as trusted by this client. If this is the only
            option given then the client will operate in a similar manner to a web
            browser. That is to say it will require the broker to have a
            certificate signed by the Certificate Authorities in ca_certs and will
            communicate using TLS v1,2, but will not attempt any form of
            authentication. This provides basic network encryption but may not be
            sufficient depending on how the broker is configured.

            By default, on Python 2.7.9+ or 3.4+, the default certification
            authority of the system is used. On older Python version this parameter
            is mandatory.
        :param str certfile: PEM encoded client certificate filename. Used with
            keyfile for client TLS based authentication. Support for this feature is
            broker dependent. Note that if the files in encrypted and needs a password to
            decrypt it, then this can be passed using the keyfile_password argument - you
            should take precautions to ensure that your password is
            not hard coded into your program by loading the password from a file
            for example. If you do not provide keyfile_password, the password will
            be requested to be typed in at a terminal window.
        :param str keyfile: PEM encoded client private keys filename. Used with
            certfile for client TLS based authentication. Support for this feature is
            broker dependent. Note that if the files in encrypted and needs a password to
            decrypt it, then this can be passed using the keyfile_password argument - you
            should take precautions to ensure that your password is
            not hard coded into your program by loading the password from a file
            for example. If you do not provide keyfile_password, the password will
            be requested to be typed in at a terminal window.
        :param cert_reqs: the certificate requirements that the client imposes
            on the broker to be changed. By default this is ssl.CERT_REQUIRED,
            which means that the broker must provide a certificate. See the ssl
            pydoc for more information on this parameter.
        :param tls_version: the version of the SSL/TLS protocol used to be
            specified. By default TLS v1.2 is used. Previous versions are allowed
            but not recommended due to possible security problems.
        :param str ciphers: encryption ciphers that are allowed
            for this connection, or None to use the defaults. See the ssl pydoc for
            more information.

        Must be called before `connect()`, `connect_async()` or `connect_srv()`.NzThis platform has no SSL/TLS.
SSLContextz@Python 2.7.9 and 3.2 are the minimum supported versions for TLS.load_default_certszca_certs must not be None.PROTOCOL_TLS_CLIENTPROTOCOL_TLSr  FHAS_ALPNz#SSL library has no support for ALPNT)r  r   r=  r  PROTOCOL_TLSv1_2r  r  set_ciphersload_cert_chain	CERT_NONEr  CERT_REQUIREDverify_modeload_verify_locationsr  getattrset_alpn_protocolsr  tls_insecure_set)
rC   r  r  r  r  r  r  r  r  r  s
             r5   tls_setzClient.tls_set  s   j ;<===sL)) 	TRT T T GCN<P$Q$Q9::: .Ks122 /!5n-- /!..-- (((##Hg7GHHH%%'';K*L*L%%*G"3<3Dc//)))(3333&&(((%3
D11 H !FGGG&&~666W%%%%% !!%((((( !!$'''''r4   c                    | j         t          d          || _        t          | j         d          r| | j         _        dS dS )ap  Configure verification of the server hostname in the server certificate.

        If value is set to true, it is impossible to guarantee that the host
        you are connecting to is not impersonating your server. This can be
        useful in initial server testing, but makes it possible for a malicious
        third party to impersonate your server through DNS spoofing, for
        example.

        Do not use this function in a real system. Setting value to true means
        there is no point using encryption.

        Must be called before `connect()` and after either `tls_set()` or
        `tls_set_context()`.Nz9Must configure SSL context before using tls_insecure_set.r  )r  r   r  r=  r  r  s     r5   r	  zClient.tls_insecure_set   sf     $KM M M # 4$&677 	9 49yD,,,	9 	9r4   
proxy_argsc                    t           t          d          |                     |          st          d          || _        dS )a  Configure proxying of MQTT connection. Enables support for SOCKS or
        HTTP proxies.

        Proxying is done through the PySocks library. Brief descriptions of the
        proxy_args parameters are below; see the PySocks docs for more info.

        (Required)

        :param proxy_type: One of {socks.HTTP, socks.SOCKS4, or socks.SOCKS5}
        :param proxy_addr: IP address or DNS name of proxy server

        (Optional)

        :param proxy_port: (int) port number of the proxy server. If not provided,
            the PySocks package default value will be utilized, which differs by proxy_type.
        :param proxy_rdns: boolean indicating whether proxy lookup should be performed
            remotely (True, default) or locally (False)
        :param proxy_username: username for SOCKS5 proxy, or userid for SOCKS4 proxy
        :param proxy_password: password for SOCKS5 proxy

        Example::

            mqttc.proxy_set(proxy_type=socks.HTTP, proxy_addr='1.2.3.4', proxy_port=4231)
        Nz,PySocks must be installed for proxy support.z)proxy_type and/or proxy_addr are invalid.)socksr   _proxy_is_validrw  )rC   r  s     r5   	proxy_setzClient.proxy_set;  sH    2 =KLLL%%j11 	%HIII$DKKKr4   r  c                \    |"| j         dS t          j        t                    }|| _        dS )a  
        Enables a logger to send log messages to

        :param logging.Logger logger: if specified, that ``logging.Logger`` object will be used, otherwise
            one will be created automatically.

        See `disable_logger` to undo this action.
        N)r  logging	getLoggerr/   r  )rC   r  s     r5   enable_loggerzClient.enable_logger[  s1     >|'&x00Fr4   c                    d| _         dS )zu
        Disable logging using standard python logging package. This has no effect on the `on_log` callback.
        Nr  rK   s    r5   disable_loggerzClient.disable_loggerk  s     r4   r:  r0  r   r  r   r  bind_address	bind_portclean_startrY   r  Properties | Noner   c           	         | j         t          k    rd| _        n+|t          k    rt	          d          |rt	          d          |                     |||||||           |                                 S )a  Connect to a remote broker. This is a blocking call that establishes
        the underlying connection and transmits a CONNECT packet.
        Note that the connection status will not be updated until a CONNACK is received and
        processed (this requires a running network loop, see `loop_start`, `loop_forever`, `loop`...).

        :param str host: the hostname or IP address of the remote broker.
        :param int port: the network port of the server host to connect to. Defaults to
            1883. Note that the default port for MQTT over SSL/TLS is 8883 so if you
            are using `tls_set()` the port may need providing.
        :param int keepalive: Maximum period in seconds between communications with the
            broker. If no other messages are being exchanged, this controls the
            rate at which the client will send ping messages to the broker.
        :param bool clean_start: (MQTT v5.0 only) True, False or MQTT_CLEAN_START_FIRST_ONLY.
            Sets the MQTT v5.0 clean_start flag always, never or on the first successful connect only,
            respectively.  MQTT session data (such as outstanding messages and subscriptions)
            is cleared on successful connect when the clean_start flag is set.
            For MQTT v3.1.1, the ``clean_session`` argument of `Client` should be used for similar
            result.
        :param Properties properties: (MQTT v5.0 only) the MQTT v5.0 properties to be sent in the
            MQTT connect packet.
        Tz#Clean start only applies to MQTT V5z Properties only apply to MQTT V5)r@  rO  r  rZ   r   connect_async	reconnectrC   r  r   r  r  r  r  r  s           r5   r   zClient.connectq  s    @ >V##)-D&&999 !FGGG E !CDDD4y'K	M 	M 	M~~r4   domainc           
        t           du rt          d          |3t          j                    }||                    d          dz   d         }	 d| }| j        rd| }g }t          j                            |t          j	        j
                  D ]K}	|	j                                        dd         }
|                    |
|	j        |	j        |	j        f           LnP# t          j        j        t          j        j        t          j        j        f$ r}t          d	|           |d}~ww xY w|D ]6}	|	\  }}}}	 |                     |||||||          c S # t*          $ r Y 3w xY wt          d
          )zConnect to a remote broker.

        :param str domain: the DNS domain to search for SRV records; if None,
            try to determine local domain name.
        :param keepalive, bind_address, clean_start and properties: see `connect()`
        Fz;No DNS resolver library found, try "pip install dnspython".N.r   z_mqtt._tcp.z_secure-mqtt._tcp.zNo answer/NXDOMAIN for SRV in zNo SRV hosts responded)HAVE_DNSr   r   getfqdnfindr  dnsresolverquery	rdatatypeSRVtargetto_textr   r   priorityweightNXDOMAINNoAnswerNoNameserversr   	Exception)rC   r  r  r  r  r  r  rranswersansweraddrr  r  r   prior.  s                   r5   connect_srvzClient.connect_srv  s     uMO O O >^%%FFKK,,q0112F	Q'v''By 32&22G,,,R1BCC I I},,..ss36;GI I I II %s|'<cl>XY 	Q 	Q 	QFfFFGGSP	Q  	 	F'-$D$f||D$	<T_aklllll    1222s+   BC 5D+D&&D+:E
E$#E$c                    |dk     rt          d          |                                  t          j        | _        || _        || _        || _        || _        || _	        || _
        || _        t          j        | _        dS )a  Connect to a remote broker asynchronously. This is a non-blocking
        connect call that can be used with `loop_start()` to provide very quick
        start.

        Any already established connection will be terminated immediately.

        :param str host: the hostname or IP address of the remote broker.
        :param int port: the network port of the server host to connect to. Defaults to
            1883. Note that the default port for MQTT over SSL/TLS is 8883 so if you
            are using `tls_set()` the port may need providing.
        :param int keepalive: Maximum period in seconds between communications with the
            broker. If no other messages are being exchanged, this controls the
            rate at which the client will send ping messages to the broker.
        :param bool clean_start: (MQTT v5.0 only) True, False or MQTT_CLEAN_START_FIRST_ONLY.
            Sets the MQTT v5.0 clean_start flag always, never or on the first successful connect only,
            respectively.  MQTT session data (such as outstanding messages and subscriptions)
            is cleared on successful connect when the clean_start flag is set.
            For MQTT v3.1.1, the ``clean_session`` argument of `Client` should be used for similar
            result.
        :param Properties properties: (MQTT v5.0 only) the MQTT v5.0 properties to be sent in the
            MQTT connect packet.
        r   zInvalid bind port number.N)r   r  r   rc  rd  r  r   r  ru  rv  rN  rk  MQTT_CS_CONNECT_ASYNCr  s           r5   r  zClient.connect_async  s}    @ q==8999 	&2		")#'#- &<r4   r   r8  	min_delay	max_delayc                p    | j         5  || _        || _        d| _        ddd           dS # 1 swxY w Y   dS )ah   Configure the exponential reconnect delay

            When connection is lost, wait initially min_delay seconds and
            double this time every attempt. The wait is capped at max_delay.
            Once the client is fully connected (e.g. not only TCP socket, but
            received a success CONNACK), the wait timer is reset to min_delay.
        N)r  r]  r^  r_  )rC   r;  r<  s      r5   reconnect_delay_setzClient.reconnect_delay_set  s     ( 	) 	)(1D%(1D%$(D!	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)s   +//c           	     ~   t          | j                  dk    rt          d          | j        dk    rt          d          ddg ddt	          d          ddd| _        d| _        t          j        | _	        | 
                                 | j        D ]V}|d         d	z  t          k    r@|d
         dk    r4|d         ,t          |d         _        |d                                          W| j                                         | j        5  t%                      | _        t%                      | _        ddd           n# 1 swxY w Y   |                                  | j        5  | j        }ddd           n# 1 swxY w Y   |rN	  || | j                   n;# t2          $ r.}|                     t6          d|           | j        s Y d}~nd}~ww xY w|                                 | _        | j                            d           d| _         | !                    | j                   | "                    | j#                  S )zdReconnect the client after a disconnect. Can only be called after
        connect()/connect_async().r   r  r  r   r4   r7  r  r%      r9   r<   Nz&Caught exception in on_pre_connect: %sF)$r   rs  r   rt  r*   rW  ra  r   MQTT_CS_CONNECTINGrd  r  rZ  PUBLISHrt   r   r   clearr|  r   r[  r\  _messages_reconnect_resetr{  on_pre_connectrA  r2  r  MQTT_LOG_ERRr  _create_socketrB  rS   r  _call_socket_open_send_connectrE  )rC   pktrE  r  s       r5   r  zClient.reconnect
  s    tz??a_---:??3444 ! !nn	
 	
 &9 # 	0 	0C9~$//CJ!OOFH_!3FF--///     	- 	- )D!*D	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-
 	&&(((! 	1 	1!0N	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1  	tT^4444    "JCQ Q Q/      ((**

u%%%!&tz***!!$/222s<   	'D<<E E "E66E:=E:F 
G $G		G      ?r   c                    | j         | j        1|                     d           t                      \  | _         | _        |                     |          S )a[  Process network events.

        It is strongly recommended that you use `loop_start()`, or
        `loop_forever()`, or if you are using an external event loop using
        `loop_read()`, `loop_write()`, and `loop_misc()`. Using loop() on it's own is
        no longer recommended.

        This function must be called regularly to ensure communication with the
        broker is carried out. It calls select() on the network socket to wait
        for network events. If incoming data is present it will then be
        processed. Outgoing commands, from e.g. `publish()`, are normally sent
        immediately that their function is called, but this is not always
        possible. loop() will also attempt to send any remaining outgoing
        messages, which also includes commands that are part of the flow for
        messages with QoS>0.

        :param int timeout: The time in seconds to wait for incoming/outgoing network
            traffic before timing out and returning.

        Returns MQTT_ERR_SUCCESS on success.
        Returns >0 on error.

        A ValueError will be raised if timeout < 0NT)r  )rC  rD  r  r   _loop)rC   r   s     r5   loopzClient.loopF  sP    2 ?"do&=d333/A/C/C,DOT_zz'"""r4   c                N   |dk     rt          d          |                                 r	| j        g}ng }d}t          | j        d          r| j                                        }|dk    rd}| j        	| j        g}n| j        | j        g}	 t          j        ||g |          }n# t          $ r? | j        t          j
        t          j        fvrt          j        | _        t          j        cY S t           $ r? | j        t          j
        t          j        fvrt          j        | _        t          j        cY S t          $ r t          j        cY S w xY w| j        |d         v s|dk    r|                                 }|s| j        |S | j        r\| j        |d         v rM|d                             d| j                   	 | j                            d           n# t(          $ r Y nw xY w| j        |d         v r|                                 }|s| j        |S |                                 S )Nr  zInvalid timeout.r   pendingr   i'  )r   
want_writerB  r=  rP  rC  selectr   rd  r   MQTT_CS_DISCONNECTINGMQTT_CS_DISCONNECTEDMQTT_CS_CONNECTION_LOSTr   rt   r2  rz   	loop_readinsertrD   r   
loop_write	loop_misc)rC   r   wlistpending_bytesrlistsocklistr   s          r5   rM  zClient._loope  ss   S==/000?? 	ZLEEE 4:y)) 	1 J..00M 1G ?"ZLEEZ1E	2}UE2w??HH 		4 		4 		4 {#3#IK[Kp"qqq.F 3333 	4 	4 	4 {#3#IK[Kp"qqq.F 3333 	2 	2 	2 !1111	2
 :!$$(9(9!!B TZ'	? 
	t(1+== QKq$*--- $$U++++"    :!$$""B TZ'	~~s2   B$ $AE,AE3E
E:G 
G"!G"r   r   PayloadTyper9   r  r   c                   | j         t          k    r$|t          |          dk    rt          d          |                    d          }|                     |           |dk     s|dk    rt          d          t          |          }t          |          dk    rt          d          |                                 }|dk    r4t          |          }	| 	                    |||||d	|	|          }
|
|	_
        |	S t          ||          }t                      |_        ||_        ||_        ||_        d	|_        ||_        | j        5  | j        dk    rFt          | j                  | j        k    r)t,          j        |j        _
        |j        cddd           S || j        v r)t,          j        |j        _
        |j        cddd           S || j        |j        <   | j        dk    s| j        | j        k     r| xj        d
z  c_        |d
k    rt8          |_        n|dk    rt<          |_        | 	                    |j        ||j        |j        |j        |j        |j        |j                  }
|
t,          j        k    r| xj        d
z  c_        t@          |_        |
|j        _
        |j        cddd           S tB          |_        t,          j"        |j        _
        |j        cddd           S # 1 swxY w Y   dS )a  Publish a message on a topic.

        This causes a message to be sent to the broker and subsequently from
        the broker to any clients subscribing to matching topics.

        :param str topic: The topic that the message should be published on.
        :param payload: The actual message to send. If not given, or set to None a
            zero length message will be used. Passing an int or float will result
            in the payload being converted to a string representing that number. If
            you wish to send a true int/float, use struct.pack() to create the
            payload you require.
        :param int qos: The quality of service level to use.
        :param bool retain: If set to true, the message will be set as the "last known
            good"/retained message for the topic.
        :param Properties properties: (MQTT v5.0 only) the MQTT v5.0 properties to be included.

        Returns a `MQTTMessageInfo` class, which can be used to determine whether
        the message has been delivered (using `is_published()`) or to block
        waiting for the message to be delivered (`wait_for_publish()`). The
        message ID and return code of the publish() call can be found at
        :py:attr:`info.mid <MQTTMessage.mid>` and :py:attr:`info.rc <MQTTMessage.rc>`.

        For backwards compatibility, the `MQTTMessageInfo` class is iterable so
        the old construct of ``(rc, mid) = client.publish(...)`` is still valid.

        rc is MQTT_ERR_SUCCESS to indicate success or MQTT_ERR_NO_CONN if the
        client is not currently connected.  mid is the message ID for the
        publish request. The mid value can be used to track the publish request
        by checking against the mid argument in the on_publish() callback if it
        is defined.

        :raises ValueError: if topic is None, has zero length or is
            invalid (contains a wildcard), except if the MQTT version used is v5.0.
            For v5.0, a zero length topic can be used when a Topic Alias has been set.
        :raises ValueError: if qos is not one of 0, 1 or 2
        :raises ValueError: if the length of the payload is greater than 268435455 bytes.
        Nr   Invalid topic.r   r   Invalid QoS level.irl   Fr   )#r@  rO  r   r   r   _raise_for_invalid_topicr   _mid_generater   _send_publishr   re   r   r  r   r9   r  r	  r  r}  rj  rf  r   r|   r<   r8   rh  ri  mqtt_ms_wait_for_pubackr  mqtt_ms_wait_for_pubrecrq   mqtt_ms_publishmqtt_ms_queuedrm   )rC   r   r   r9   r  r  topic_byteslocal_payload	local_midr<   r   messages               r5   publishzClient.publish  su   Z >V##}E

a !1222ll7++%%k22277cAgg1222'00}	))1222&&((	!88"9--D##;sFE4Q[] ]BDGK!)[99G )G+GOGK#GNGK!+G( ( (,q00S9K5L5LPTPi5i5i&3&GGLO"<( ( ( ( ( ( ( (
  222&3&GGLO"<( ( ( ( ( ( ( ( 3:"7;/.!33t7NQUQl7l7l++q0++axx(?(?++GKgoW^Wbdkdr,3KwGY[ [B ];;;//14//(7&(GLO"<5( ( ( ( ( ( ( (8 %3GM&3&DGLO"<=( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s&   AK(%K(
CK(3(K((K,/K,r  r  c                    |dn|                     d          | _        t          |t                    r|                     d          | _        dS || _        dS )ad  Set a username and optionally a password for broker authentication.

        Must be called before connect() to have any effect.
        Requires a broker that supports MQTT v3.1 or more.

        :param str username: The username to authenticate with. Need have no relationship to the client id. Must be str
            [MQTT-3.1.3-11].
            Set to None to reset client back to not using username/password for broker authentication.
        :param str password: The password to authenticate with. Optional, set to None if not required. If it is str, then it
            will be encoded as UTF-8.
        Nr   )r   rU  r   rj   rV  )rC   r  r  s      r5   username_pw_setzClient.username_pw_set  sT      "*!1xw7O7Oh$$ 	&%__W55DNNN%DNNNr4   c                    t           | _        dS )aO  Sets the client in a bridge mode instead of client mode.

        Must be called before `connect()` to have any effect.
        Requires brokers that support bridge mode.

        Under bridge mode, the broker will identify the client as a bridge and
        not send it's own messages back to it. Hence a subsciption of # is
        possible without message loops. This feature also correctly propagates
        the retain flag on the messages.

        Currently Mosquitto and RSMB support this feature. This feature can
        be used to create a bridge between multiple broker.
        N)MQTT_BRIDGErH  rK   s    r5   enable_bridge_modezClient.enable_bridge_mode1  s     (r4   c                |    | j         t          j        k    p'| j         t          j        t          j        fv o| j        du S )zX
        Return true if the connection is closed (and not trying to be opened).
        N)rd  r   rc  rS  rT  rB  rK   s    r5   r  zClient._connection_closedA  sO    
 K+77 G 0 FHXHmnn  Fsws}  BF  tF	Hr4   c                ,    | j         t          j        k    S )z~Returns the current status of the connection

        True if connection exists
        False if connection is closed
        )rd  r   MQTT_CS_CONNECTEDrK   s    r5   is_connectedzClient.is_connectedI  s     {.@@@r4   
reasoncodeReasonCode | Nonec                    | j         t          j        | _        t          S t          j        | _        |                     ||          S )a  Disconnect a connected client from the broker.

        :param ReasonCode reasoncode: (MQTT v5.0 only) a ReasonCode instance setting the MQTT v5.0
            reasoncode to be sent with the disconnect packet. It is optional, the receiver
            then assuming that 0 (success) is the value.
        :param Properties properties: (MQTT v5.0 only) a Properties instance setting the MQTT v5.0 properties
            to be included. Optional - if not set, no properties are sent.
        )rB  r   rT  rd  rq   rS  _send_disconnect)rC   rw  r  s      r5   
disconnectzClient.disconnectQ  s<     :*?DK##*@DK$$Z<<<r4   qstr | tuple[str, int] | tuple[str, SubscribeOptions] | list[tuple[str, int]] | list[tuple[str, SubscribeOptions]]optionsSubscribeOptions | None tuple[MQTTErrorCode, int | None]c                    d}t          |t                    r? j        t          k    r*|\  }}t          |t                    st          d          n|\  }}t          |t          t          f          r|dk     s|dk    rt          d           j        t          k    rf|t	          |          }n|dk    rt          d          t          |t                    st          d          |                    d          |fg}n|t          |          dk    rt          d	          |                    d          |fg}n_t          |t                    rIt          |          dk    rt          d
          g } j        t          k    rs|D ]o\  }}t          |t                    s+|dk     s|dk    rt          d          t	          |          }|                    |                    d          |f           pn|D ]\  }}t          |t                    s|dk     s|dk    rt          d          |/t          |          dk    st          |t          t          f          st          d	          |                    |                    d          |f           |t          d          t           fd|D                       rt          d           j        	t          dfS                      d||          S )am  Subscribe the client to one or more topics.

        This function may be called in three different ways (and a further three for MQTT v5.0):

        Simple string and integer
        -------------------------
        e.g. subscribe("my/topic", 2)

        :topic: A string specifying the subscription topic to subscribe to.
        :qos: The desired quality of service level for the subscription.
            Defaults to 0.
        :options and properties: Not used.

        Simple string and subscribe options (MQTT v5.0 only)
        ----------------------------------------------------
        e.g. subscribe("my/topic", options=SubscribeOptions(qos=2))

        :topic: A string specifying the subscription topic to subscribe to.
        :qos: Not used.
        :options: The MQTT v5.0 subscribe options.
        :properties: a Properties instance setting the MQTT v5.0 properties
            to be included. Optional - if not set, no properties are sent.

        String and integer tuple
        ------------------------
        e.g. subscribe(("my/topic", 1))

        :topic: A tuple of (topic, qos). Both topic and qos must be present in
               the tuple.
        :qos and options: Not used.
        :properties: Only used for MQTT v5.0.  A Properties instance setting the
            MQTT v5.0 properties. Optional - if not set, no properties are sent.

        String and subscribe options tuple (MQTT v5.0 only)
        ---------------------------------------------------
        e.g. subscribe(("my/topic", SubscribeOptions(qos=1)))

        :topic: A tuple of (topic, SubscribeOptions). Both topic and subscribe
                options must be present in the tuple.
        :qos and options: Not used.
        :properties: a Properties instance setting the MQTT v5.0 properties
            to be included. Optional - if not set, no properties are sent.

        List of string and integer tuples
        ---------------------------------
        e.g. subscribe([("my/topic", 0), ("another/topic", 2)])

        This allows multiple topic subscriptions in a single SUBSCRIPTION
        command, which is more efficient than using multiple calls to
        subscribe().

        :topic: A list of tuple of format (topic, qos). Both topic and qos must
               be present in all of the tuples.
        :qos, options and properties: Not used.

        List of string and subscribe option tuples (MQTT v5.0 only)
        -----------------------------------------------------------
        e.g. subscribe([("my/topic", SubscribeOptions(qos=0), ("another/topic", SubscribeOptions(qos=2)])

        This allows multiple topic subscriptions in a single SUBSCRIPTION
        command, which is more efficient than using multiple calls to
        subscribe().

        :topic: A list of tuple of format (topic, SubscribeOptions). Both topic and subscribe
                options must be present in all of the tuples.
        :qos and options: Not used.
        :properties: a Properties instance setting the MQTT v5.0 properties
            to be included. Optional - if not set, no properties are sent.

        The function returns a tuple (result, mid), where result is
        MQTT_ERR_SUCCESS to indicate success or (MQTT_ERR_NO_CONN, None) if the
        client is not currently connected.  mid is the message ID for the
        subscribe request. The mid value can be used to track the subscribe
        request by checking against the mid argument in the on_subscribe()
        callback if it is defined.

        Raises a ValueError if qos is not 0, 1 or 2, or if topic is None or has
        zero string length, or if topic is not a string, tuple or list.
        Nz=Subscribe options must be instance of SubscribeOptions class.r   r   ra  )r9   z8Subscribe options and qos parameters cannot be combined.r   r`  zEmpty topic list,No topic specified, or incorrect topic type.c              3  Z   K   | ]%\  }}                     |          t          k    V  &d S rB   )_filter_wildcard_len_checkrm   )r   r   r   rC   s      r5   r   z#Client.subscribe.<locals>.<genexpr>  s<      iiheUVt..u559IIiiiiiir4   zInvalid subscription filter.F)r   tupler@  rO  r   r   r:   rj   r   r   listr   anyrB  rq   _send_subscribe)	rC   r   r9   r}  r  topic_qos_listtoqs	   `        r5   	subscribezClient.subscribef  sS   l eU## 	#~''!&w!'+;<< Y$WY Y YY #
seeS\** $	BQww#'' !5666~''?.3777GGAXX$RT T T!'+;<< Y$WY Y Y#(<<#8#8'"B!C=CJJ!OO$%5666#(<<#8#8#">!?t$$ 	B5zzQ !3444N~''! B BDAq%a)9:: 4q55AEE",-A"B"BB,333"))188G+<+<a*@AAAAB " B BDAq!!%566 ?!a%%1q55()=>>>yCFFaKKz!eS\7R7RK()9:::"))188G+<+<a*@AAAA!KLLLiiiiZhiiiii 	=;<<<:$d++##E>:FFFr4   str | list[str]c                P   d}|t          d          t          |t          t          f          r9t	          |          dk    rt          d          |                    d          g}nt          |t                    rmg }|D ]h}t	          |          dk    st          |t          t          f          st          d          |                    |                    d                     i|t          d          | j        t          j
        dfS |                     d||          S )ae  Unsubscribe the client from one or more topics.

        :param topic: A single string, or list of strings that are the subscription
            topics to unsubscribe from.
        :param properties: (MQTT v5.0 only) a Properties instance setting the MQTT v5.0 properties
            to be included. Optional - if not set, no properties are sent.

        Returns a tuple (result, mid), where result is MQTT_ERR_SUCCESS
        to indicate success or (MQTT_ERR_NO_CONN, None) if the client is not
        currently connected.
        mid is the message ID for the unsubscribe request. The mid value can be
        used to track the unsubscribe request by checking against the mid
        argument in the on_unsubscribe() callback if it is defined.

        :raises ValueError: if topic is None or has zero string length, or is
            not a string or list.
        Nr`  r   r   r  F)r   r   r:   rj   r   r   r  r   rB  r   rq   _send_unsubscribe)rC   r   r  
topic_listr  s        r5   unsubscribezClient.unsubscribe  s#   ( 
=-...eeS\** 		55zzQ !1222,,w//0JJt$$ 	5J 5 5q66Q;;jUCL&A&A;$%5666!!!((7"3"34444KLLL:!2D99%%eZDDDr4   max_packetsc                   | j         t          j        S t          | j                  t          | j                  z   }|dk     rd}t          d|          D ]f}| j         t          j        c S |                                 }|dk    r|                     |          c S |t          j	        k    rt          j
        c S gt          j
        S )a6  Process read network events. Use in place of calling `loop()` if you
        wish to handle your client reads as part of your own application.

        Use `socket()` to obtain the client socket to call select() or equivalent
        on.

        Do not use if you are using `loop_start()` or `loop_forever()`.Nr   r   )rB  r   rq   r   rf  rg  r   _packet_read_loop_rc_handler   rm   )rC   r  r   r   s       r5   rV  zClient.loop_read"  s     : 11$,--D4E0F0FF??Kq+&& 	6 	6Az!$5555""$$BAvv++B/////}333$5555 4--r4   c                   | j         t          j        S 	 |                                 }|t          j        k    rIt          j        |                                 r|                                  S |                                  S |dk    rR| 	                    |          |                                 r|                                  S |                                  S t          j        |                                 r|                                  S |                                  S # |                                 r|                                  w |                                  w xY w)a  Process write network events. Use in place of calling `loop()` if you
        wish to handle your client writes as part of your own application.

        Use `socket()` to obtain the client socket to call select() or equivalent
        on.

        Use `want_write()` to determine if there is data waiting to be written.

        Do not use if you are using `loop_start()` or `loop_forever()`.Nr   )
rB  r   rq   _packet_writer   rm   rQ  r  r  r  rC   r   s     r5   rX  zClient.loop_write;  s]    : 11	5##%%B]111$5    5002222224444 a++B//    5002222224444 %5   5002222224444    5002222224444s   /D# D# D# #?E"c                2    t          | j                  dk    S )zCall to determine if there is network data waiting to be written.
        Useful if you are calling select() yourself rather than using `loop()`, `loop_start()` or `loop_forever()`.
        r   )r   rZ  rK   s    r5   rQ  zClient.want_writeV  s     4#$$q((r4   c                   | j         t          j        S t                      }|                                  | j        dk    r|| j        z
  | j        k    r|                                  | j        t          j
        t          j        fv rt          j        | _        t          j        }nt          j        | _        t          j        }|                     d|           t          j        S t          j        S )zProcess miscellaneous network events. Use in place of calling `loop()` if you
        wish to call select() or equivalent on.

        Do not use if you are using `loop_start()` or `loop_forever()`.Nr   Fpacket_from_brokerv1_rc)rB  r   rq   r   _check_keepalivera  rE  r  rd  r   rS  rT  rm   rU  r}   _do_on_disconnectrt   )rC   nowr   s      r5   rY  zClient.loop_misc\  s    
 : 11kk<!dl 2do E E {/EGWGlmmm.C"3.F"5""#( #   
 !33--r4   inflightc                    || _         dS )z~Set the maximum number of messages with QoS>0 that can be part way
        through their network flow at once. Defaults to 20.N)r  )rC   r  s     r5   max_inflight_messages_setz Client.max_inflight_messages_set|  s     &."""r4   
queue_sizec                \    t          |t                    st          d          || _        | S )z\Set the maximum number of messages in the outgoing message queue.
        0 means unlimited.zInvalid type of queue size.)r   r$   r   r  )rC   r  s     r5   max_queued_messages_setzClient.max_queued_messages_set  s2     *c** 	<:;;;#- r4   c                    || _         dS )zESet the user data variable passed to callbacks. May be any data type.NrA  )rC   r&  s     r5   user_data_setzClient.user_data_set  s    !r4   c                    | j         S )zEGet the user data variable passed to callbacks. May be any data type.r  rK   s    r5   user_data_getzClient.user_data_get  s
    ~r4   c                d   |t          |          dk    rt          d          |dk     s|dk    rt          d          |r$t          |t                    st          d          t	          |          | _        d| _        |                    d          | _        || _	        || _
        || _        dS )	a  Set a Will to be sent by the broker in case the client disconnects unexpectedly.

        This must be called before connect() to have any effect.

        :param str topic: The topic that the will message should be published on.
        :param payload: The message to send as a will. If not given, or set to None a
            zero length message will be used as the will. Passing an int or float
            will result in the payload being converted to a string representing
            that number. If you wish to send a true int/float, use struct.pack() to
            create the payload you require.
        :param int qos: The quality of service level to use for the will.
        :param bool retain: If set to true, the will message will be set as the "last known
            good"/retained message for the topic.
        :param Properties properties: (MQTT v5.0 only) the MQTT v5.0 properties
            to be included with the will message. Optional - if not set, no properties are sent.

        :raises ValueError: if qos is not 0, 1 or 2, or if topic is None or has
            zero string length.

        See `will_clear` to clear will. Note that will are NOT send if the client disconnect cleanly
        for example by calling `disconnect()`.
        Nr   r`  r   ra  zDThe properties argument must be an instance of the Properties class.Tr   )r   r   r   r   r   ro  rm  r   rn  rp  rq  rl  )rC   r   r   r9   r  r  s         r5   will_setzClient.will_set  s    < =CJJ!OO-...77cAgg1222 	XjZ@@ 	XVX X X -W55
 <<00" *r4   c                L    d| _         d| _        d| _        d| _        d| _        dS )z~ Removes a will that was previously configured with `will_set()`.

        Must be called before connect() to have any effect.Fr4   r   N)rm  rn  ro  rp  rq  rK   s    r5   
will_clearzClient.will_clear  s0     
 !r4   SocketLike | Nonec                    | j         S )z0Return the socket or ssl object for this client.)rB  rK   s    r5   r   zClient.socket  s
    zr4   retry_first_connectionc                l    dr j         du rn j        t          j        k    rl	                                   nW# t
          $ rI                                   |s                      t          d            	                                 Y nw xY wnrt          j        }|t          j        k    rl                     |          } j         du r>t           j                  dk    r&t           j                  dk    rt          j        }d|t          j        k    ld fd} |            s j        sdnv 	                                  |            rdnU	                                   n?# t
          $ r2                                                        t          d           Y nw xY w|S )	a  This function calls the network loop functions for you in an
        infinite blocking loop. It is useful for the case where you only want
        to run the MQTT client loop in your program.

        loop_forever() will handle reconnecting for you if reconnect_on_failure is
        true (this is the default behavior). If you call `disconnect()` in a callback
        it will return.

        :param int timeout: The time in seconds to wait for incoming/outgoing network
          traffic before timing out and returning.
        :param bool retry_first_connection: Should the first connection attempt be retried on failure.
          This is independent of the reconnect_on_failure setting.

        :raises OSError: if the first connection fail unless retry_first_connection=True
        TzConnection failed, retryingr   Fr@   rP   c                 \    j         t          j        t          j        fv p du pj        du S )NFT)rd  r   rS  rT  r  )runrC   s   r5   should_exitz(Client.loop_forever.<locals>.should_exit	  s;    K$4$JL\Lq#rr 35L3*d2r4   r   )r  rd  r   r:  r  OSError_handle_on_connect_failr  r  _reconnect_waitr   rm   rM  r   rZ  rf  rn   r`  )rC   r   r  r   r  r  s   `    @r5   loop_foreverzClient.loop_forever  sL   *  	%--{.DDD+NN$$$$ + + +002221 NN&(EG G G((*****+   	"  "	K/B666ZZ((
 *d22D,--22 233q88&5BC 666       {}} KD$> K$$&&&;== KCCK((((" K K K44666*,IK K K K KK?  "	KH 	s"   < ABBE2 29F.-F.c                B   | j         t          j        S t                      \  | _        | _        d| _        t          j        | j	        d| j
                                                   | _         d| j         _        | j                                          t          j        S )a`  This is part of the threaded client interface. Call this once to
        start a new thread to process network traffic. This provides an
        alternative to repeatedly calling `loop()` yourself.

        Under the hood, this will call `loop_forever` in a thread, which means that
        the thread will terminate if you call `disconnect()`
        NFzpaho-mqtt-client-)r+  nameT)r  r   rp   r   rC  rD  r  r   Thread_thread_mainrT  r  daemonstartrm   rK   s    r5   
loop_startzClient.loop_start	  s     <# //+=+?+?(!& 't/@Gu[_[j[q[q[s[sGuGuvvv"--r4   c                    | j         t          j        S d| _        t	          j                    | j         k    r| j                                          t          j        S )aZ  This is part of the threaded client interface. Call this once to
        stop the network thread previously created with `loop_start()`. This call
        will block until the network thread finishes.

        This don't guarantee that publish packet are sent, use `wait_for_publish` or
        `on_publish` to ensure `publish` are sent.
        NT)r  r   rp   r  r   current_threadr   rm   rK   s    r5   	loop_stopzClient.loop_stop/	  sP     < //!%#%%55L--r4   c                    | j         S )z
        Return the callback API version used for user-callback. See docstring for
        each user-callback (`on_connect`, `on_publish`, ...) for details.

        This property is read-only.
        )rI  rK   s    r5   r!  zClient.callback_api_version@	  s     ))r4   CallbackOnLog | Nonec                    | j         S )a  The callback called when the client has log information.
        Defined to allow debugging.

        Expected signature is::

            log_callback(client, userdata, level, buf)

        :param Client client: the client instance for this callback
        :param userdata: the private user data as set in Client() or user_data_set()
        :param int level: gives the severity of the message and will be one of
                    MQTT_LOG_INFO, MQTT_LOG_NOTICE, MQTT_LOG_WARNING,
                    MQTT_LOG_ERR, and MQTT_LOG_DEBUG.
        :param str buf: the message itself

        Decorator: @client.log_callback() (``client`` is the name of the
            instance which this callback is being attached to)
        r  rK   s    r5   on_logzClient.on_logJ	  s    & |r4   funcc                    || _         d S rB   r  rC   r  s     r5   r  zClient.on_log_	  s    r4   (Callable[[CallbackOnLog], CallbackOnLog]c                     d fd}|S )Nr  CallbackOnLogr@   c                    | _         | S rB   )r  r  rC   s    r5   	decoratorz&Client.log_callback.<locals>.decoratord	  s    DKKr4   )r  r  r@   r  r3   rC   r  s   ` r5   log_callbackzClient.log_callbackc	  s)    	 	 	 	 	 	 r4   CallbackOnPreConnect | Nonec                    | j         S )a  The callback called immediately prior to the connection is made
        request.

        Expected signature (for all callback API version)::

            connect_callback(client, userdata)

        :parama Client client: the client instance for this callback
        :parama userdata: the private user data as set in Client() or user_data_set()

        Decorator: @client.pre_connect_callback() (``client`` is the name of the
            instance which this callback is being attached to)

        )r  rK   s    r5   rE  zClient.on_pre_connecti	  s      ##r4   c                T    | j         5  || _        d d d            d S # 1 swxY w Y   d S rB   )r{  r  r  s     r5   rE  zClient.on_pre_connect{	  w    ! 	( 	(#'D 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(   !!6Callable[[CallbackOnPreConnect], CallbackOnPreConnect]c                     d fd}|S )Nr  CallbackOnPreConnectr@   c                    | _         | S rB   )rE  r  s    r5   r  z.Client.pre_connect_callback.<locals>.decorator	      "&DKr4   )r  r  r@   r  r3   r  s   ` r5   pre_connect_callbackzClient.pre_connect_callback	  )    	 	 	 	 	 	 r4   CallbackOnConnect | Nonec                    | j         S )a
  The callback called when the broker reponds to our connection request.

        Expected signature for callback API version 2::

            connect_callback(client, userdata, connect_flags, reason_code, properties)

        Expected signature for callback API version 1 change with MQTT protocol version:
            * For MQTT v3.1 and v3.1.1 it's::

                connect_callback(client, userdata, flags, rc)

            * For MQTT v5.0 it's::

                connect_callback(client, userdata, flags, reason_code, properties)


        :param Client client: the client instance for this callback
        :param userdata: the private user data as set in Client() or user_data_set()
        :param ConnectFlags connect_flags: the flags for this connection
        :param ReasonCode reason_code: the connection reason code received from the broken.
                       In MQTT v5.0 it's the reason code defined by the standard.
                       In MQTT v3, we convert return code to a reason code, see
                       `convert_connack_rc_to_reason_code()`.
                       `ReasonCode` may be compared to integer.
        :param Properties properties: the MQTT v5.0 properties received from the broker.
                       For MQTT v3.1 and v3.1.1 properties is not provided and an empty Properties
                       object is always used.
        :param dict flags: response flags sent by the broker
        :param int rc: the connection result, should have a value of `ConnackCode`

        flags is a dict that contains response flags from the broker:
            flags['session present'] - this flag is useful for clients that are
                using clean session set to 0 only. If a client with clean
                session=0, that reconnects to a broker that it has previously
                connected to, this flag indicates whether the broker still has the
                session information for the client. If 1, the session still exists.

        The value of rc indicates success or not:
            - 0: Connection successful
            - 1: Connection refused - incorrect protocol version
            - 2: Connection refused - invalid client identifier
            - 3: Connection refused - server unavailable
            - 4: Connection refused - bad username or password
            - 5: Connection refused - not authorised
            - 6-255: Currently unused.

        Decorator: @client.connect_callback() (``client`` is the name of the
            instance which this callback is being attached to)
        )r  rK   s    r5   
on_connectzClient.on_connect	  s    f r4   c                T    | j         5  || _        d d d            d S # 1 swxY w Y   d S rB   )r{  r  r  s     r5   r  zClient.on_connect	  w    ! 	$ 	$#D	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$r  0Callable[[CallbackOnConnect], CallbackOnConnect]c                     d fd}|S )Nr  CallbackOnConnectr@   c                    | _         | S rB   )r  r  s    r5   r  z*Client.connect_callback.<locals>.decorator	      "DOKr4   )r  r  r@   r  r3   r  s   ` r5   connect_callbackzClient.connect_callback	  r  r4   CallbackOnConnectFail | Nonec                    | j         S )a  The callback called when the client failed to connect
        to the broker.

        Expected signature is (for all callback_api_version)::

            connect_fail_callback(client, userdata)

        :param Client client: the client instance for this callback
        :parama userdata: the private user data as set in Client() or user_data_set()

        Decorator: @client.connect_fail_callback() (``client`` is the name of the
            instance which this callback is being attached to)
        )r  rK   s    r5   on_connect_failzClient.on_connect_fail	  s     $$r4   c                T    | j         5  || _        d d d            d S # 1 swxY w Y   d S rB   )r{  r  r  s     r5   r  zClient.on_connect_fail	  w    ! 	) 	)$(D!	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)r  8Callable[[CallbackOnConnectFail], CallbackOnConnectFail]c                     d fd}|S )Nr  CallbackOnConnectFailr@   c                    | _         | S rB   )r  r  s    r5   r  z/Client.connect_fail_callback.<locals>.decorator	      #'D Kr4   )r  r  r@   r  r3   r  s   ` r5   connect_fail_callbackzClient.connect_fail_callback	  r  r4   CallbackOnSubscribe | Nonec                    | j         S )a  The callback called when the broker responds to a subscribe
        request.

        Expected signature for callback API version 2::

            subscribe_callback(client, userdata, mid, reason_code_list, properties)

        Expected signature for callback API version 1 change with MQTT protocol version:
            * For MQTT v3.1 and v3.1.1 it's::

                subscribe_callback(client, userdata, mid, granted_qos)

            * For MQTT v5.0 it's::

                subscribe_callback(client, userdata, mid, reason_code_list, properties)

        :param Client client: the client instance for this callback
        :param userdata: the private user data as set in Client() or user_data_set()
        :param int mid: matches the mid variable returned from the corresponding
                          subscribe() call.
        :param list[ReasonCode] reason_code_list: reason codes received from the broker for each subscription.
                          In MQTT v5.0 it's the reason code defined by the standard.
                          In MQTT v3, we convert granted QoS to a reason code.
                          It's a list of ReasonCode instances.
        :param Properties properties: the MQTT v5.0 properties received from the broker.
                          For MQTT v3.1 and v3.1.1 properties is not provided and an empty Properties
                          object is always used.
        :param list[int] granted_qos: list of integers that give the QoS level the broker has
                          granted for each of the different subscription requests.

        Decorator: @client.subscribe_callback() (``client`` is the name of the
            instance which this callback is being attached to)
        )r  rK   s    r5   on_subscribezClient.on_subscribe	  s    F !!r4   c                T    | j         5  || _        d d d            d S # 1 swxY w Y   d S rB   )r{  r  r  s     r5   r  zClient.on_subscribe
  sw    ! 	& 	&!%D	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&r  4Callable[[CallbackOnSubscribe], CallbackOnSubscribe]c                     d fd}|S )Nr  CallbackOnSubscriber@   c                    | _         | S rB   )r  r  s    r5   r  z,Client.subscribe_callback.<locals>.decorator
  s     $DKr4   )r  r  r@   r  r3   r  s   ` r5   subscribe_callbackzClient.subscribe_callback
  r  r4   CallbackOnMessage | Nonec                    | j         S )a  The callback called when a message has been received on a topic
        that the client subscribes to.

        This callback will be called for every message received unless a
        `message_callback_add()` matched the message.

        Expected signature is (for all callback API version):
            message_callback(client, userdata, message)

        :param Client client: the client instance for this callback
        :param userdata: the private user data as set in Client() or user_data_set()
        :param MQTTMessage message: the received message.
                    This is a class with members topic, payload, qos, retain.

        Decorator: @client.message_callback() (``client`` is the name of the
            instance which this callback is being attached to)
        )r  rK   s    r5   
on_messagezClient.on_message
  s    & r4   c                T    | j         5  || _        d d d            d S # 1 swxY w Y   d S rB   )r{  r  r  s     r5   r  zClient.on_message/
  r  r  0Callable[[CallbackOnMessage], CallbackOnMessage]c                     d fd}|S )Nr  CallbackOnMessager@   c                    | _         | S rB   )r  r  s    r5   r  z*Client.message_callback.<locals>.decorator7
  r  r4   r  r  r@   r  r3   r  s   ` r5   message_callbackzClient.message_callback4
  r  r4   CallbackOnPublish | Nonec                    | j         S )a*  The callback called when a message that was to be sent using the
        `publish()` call has completed transmission to the broker.

        For messages with QoS levels 1 and 2, this means that the appropriate
        handshakes have completed. For QoS 0, this simply means that the message
        has left the client.
        This callback is important because even if the `publish()` call returns
        success, it does not always mean that the message has been sent.

        See also `wait_for_publish` which could be simpler to use.

        Expected signature for callback API version 2::

            publish_callback(client, userdata, mid, reason_code, properties)

        Expected signature for callback API version 1::

            publish_callback(client, userdata, mid)

        :param Client client: the client instance for this callback
        :param userdata: the private user data as set in Client() or user_data_set()
        :param int mid: matches the mid variable returned from the corresponding
                     `publish()` call, to allow outgoing messages to be tracked.
        :param ReasonCode reason_code: the connection reason code received from the broken.
                     In MQTT v5.0 it's the reason code defined by the standard.
                     In MQTT v3 it's always the reason code Success
        :parama Properties properties: the MQTT v5.0 properties received from the broker.
                     For MQTT v3.1 and v3.1.1 properties is not provided and an empty Properties
                     object is always used.

        Note: for QoS = 0, the reason_code and the properties don't really exist, it's the client
        library that generate them. It's always an empty properties and a success reason code.
        Because the (MQTTv5) standard don't have reason code for PUBLISH packet, the library create them
        at PUBACK packet, as if the message was sent with QoS = 1.

        Decorator: @client.publish_callback() (``client`` is the name of the
            instance which this callback is being attached to)

        )r  rK   s    r5   
on_publishzClient.on_publish<
  s    R r4   c                T    | j         5  || _        d d d            d S # 1 swxY w Y   d S rB   )r{  r  r  s     r5   r  zClient.on_publishg
  r  r  0Callable[[CallbackOnPublish], CallbackOnPublish]c                     d fd}|S )Nr  CallbackOnPublishr@   c                    | _         | S rB   )r  r  s    r5   r  z*Client.publish_callback.<locals>.decoratoro
  r  r4   )r  r  r@   r  r3   r  s   ` r5   publish_callbackzClient.publish_callbackl
  r  r4   CallbackOnUnsubscribe | Nonec                    | j         S )a  The callback called when the broker responds to an unsubscribe
        request.

        Expected signature for callback API version 2::

            unsubscribe_callback(client, userdata, mid, reason_code_list, properties)

        Expected signature for callback API version 1 change with MQTT protocol version:
            * For MQTT v3.1 and v3.1.1 it's::

                unsubscribe_callback(client, userdata, mid)

            * For MQTT v5.0 it's::

                unsubscribe_callback(client, userdata, mid, properties, v1_reason_codes)

        :param Client client: the client instance for this callback
        :param userdata: the private user data as set in Client() or user_data_set()
        :param mid: matches the mid variable returned from the corresponding
                          unsubscribe() call.
        :param list[ReasonCode] reason_code_list: reason codes received from the broker for each unsubscription.
                          In MQTT v5.0 it's the reason code defined by the standard.
                          In MQTT v3, there is not equivalent from broken and empty list
                          is always used.
        :param Properties properties: the MQTT v5.0 properties received from the broker.
                          For MQTT v3.1 and v3.1.1 properties is not provided and an empty Properties
                          object is always used.
        :param v1_reason_codes: the MQTT v5.0 reason codes received from the broker for each
                          unsubscribe topic.  A list of ReasonCode instances OR a single
                          ReasonCode when we unsubscribe from a single topic.

        Decorator: @client.unsubscribe_callback() (``client`` is the name of the
            instance which this callback is being attached to)
        )r  rK   s    r5   on_unsubscribezClient.on_unsubscribet
  s    H ##r4   c                T    | j         5  || _        d d d            d S # 1 swxY w Y   d S rB   )r{  r  r  s     r5   r  zClient.on_unsubscribe
  r  r  8Callable[[CallbackOnUnsubscribe], CallbackOnUnsubscribe]c                     d fd}|S )Nr  CallbackOnUnsubscriber@   c                    | _         | S rB   )r  r  s    r5   r  z.Client.unsubscribe_callback.<locals>.decorator
  r  r4   )r  r  r@   r  r3   r  s   ` r5   unsubscribe_callbackzClient.unsubscribe_callback
  r  r4   CallbackOnDisconnect | Nonec                    | j         S )a  The callback called when the client disconnects from the broker.

        Expected signature for callback API version 2::

            disconnect_callback(client, userdata, disconnect_flags, reason_code, properties)

        Expected signature for callback API version 1 change with MQTT protocol version:
            * For MQTT v3.1 and v3.1.1 it's::

                disconnect_callback(client, userdata, rc)

            * For MQTT v5.0 it's::

                disconnect_callback(client, userdata, reason_code, properties)

        :param Client client: the client instance for this callback
        :param userdata:  the private user data as set in Client() or user_data_set()
        :param DisconnectFlag disconnect_flags: the flags for this disconnection.
        :param ReasonCode reason_code:  the disconnection reason code possibly received from the broker (see disconnect_flags).
                          In MQTT v5.0 it's the reason code defined by the standard.
                          In MQTT v3 it's never received from the broker, we convert an MQTTErrorCode,
                          see `convert_disconnect_error_code_to_reason_code()`.
                          `ReasonCode` may be compared to integer.
        :param Properties properties: the MQTT v5.0 properties received from the broker.
                          For MQTT v3.1 and v3.1.1 properties is not provided and an empty Properties
                          object is always used.
        :param int rc: the disconnection result
                          The rc parameter indicates the disconnection state. If
                          MQTT_ERR_SUCCESS (0), the callback was called in response to
                          a disconnect() call. If any other value the disconnection
                          was unexpected, such as might be caused by a network error.

        Decorator: @client.disconnect_callback() (``client`` is the name of the
            instance which this callback is being attached to)

        )r  rK   s    r5   on_disconnectzClient.on_disconnect
  s    L ""r4   c                T    | j         5  || _        d d d            d S # 1 swxY w Y   d S rB   )r{  r  r  s     r5   r  zClient.on_disconnect
  sw    ! 	' 	'"&D	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'r  6Callable[[CallbackOnDisconnect], CallbackOnDisconnect]c                     d fd}|S )Nr  CallbackOnDisconnectr@   c                    | _         | S rB   )r  r  s    r5   r  z-Client.disconnect_callback.<locals>.decorator
  s    !%DKr4   )r  r"  r@   r"  r3   r  s   ` r5   disconnect_callbackzClient.disconnect_callback
  r  r4   CallbackOnSocket | Nonec                    | j         S )a  The callback called just after the socket was opend.

        This should be used to register the socket to an external event loop for reading.

        Expected signature is (for all callback API version)::

            socket_open_callback(client, userdata, socket)

        :param Client client:     the client instance for this callback
        :param userdata:   the private user data as set in Client() or user_data_set()
        :param SocketLike sock: the socket which was just opened.

        Decorator: @client.socket_open_callback() (``client`` is the name of the
            instance which this callback is being attached to)
        )r  rK   s    r5   on_socket_openzClient.on_socket_open
  s    " ##r4   c                T    | j         5  || _        d d d            d S # 1 swxY w Y   d S rB   )r{  r  r  s     r5   r'  zClient.on_socket_open
  r  r  .Callable[[CallbackOnSocket], CallbackOnSocket]c                     d fd}|S )Nr  CallbackOnSocketr@   c                    | _         | S rB   )r'  r  s    r5   r  z.Client.socket_open_callback.<locals>.decorator
  r  r4   r  r+  r@   r+  r3   r  s   ` r5   socket_open_callbackzClient.socket_open_callback
  r  r4   r  r>   c                8   | j         5  | j        }ddd           n# 1 swxY w Y   |rq| j        5  	  || | j        |           n;# t          $ r.}|                     t          d|           | j        s Y d}~nd}~ww xY wddd           dS # 1 swxY w Y   dS dS )z9Call the socket_open callback with the just-opened socketNz&Caught exception in on_socket_open: %s)r{  r'  ry  rA  r2  r  rF  r  )rC   r  r'  r  s       r5   rH  zClient._call_socket_open
  so   ! 	1 	1!0N	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1  	(  "N4>>>>    NN$&NPSU U U3                      	 	F     BAB
A=$A83B8A==BBBc                    | j         S )a  The callback called just before the socket is closed.

        This should be used to unregister the socket from an external event loop for reading.

        Expected signature is (for all callback API version)::

            socket_close_callback(client, userdata, socket)

        :param Client client: the client instance for this callback
        :param userdata: the private user data as set in Client() or user_data_set()
        :param SocketLike sock: the socket which is about to be closed.

        Decorator: @client.socket_close_callback() (``client`` is the name of the
            instance which this callback is being attached to)
        )r  rK   s    r5   on_socket_closezClient.on_socket_close  s    " $$r4   c                T    | j         5  || _        d d d            d S # 1 swxY w Y   d S rB   )r{  r  r  s     r5   r2  zClient.on_socket_close  r  r  c                     d fd}|S )Nr  r+  r@   c                    | _         | S rB   )r2  r  s    r5   r  z/Client.socket_close_callback.<locals>.decorator&  r  r4   r-  r3   r  s   ` r5   socket_close_callbackzClient.socket_close_callback#  r  r4   c                8   | j         5  | j        }ddd           n# 1 swxY w Y   |rq| j        5  	  || | j        |           n;# t          $ r.}|                     t          d|           | j        s Y d}~nd}~ww xY wddd           dS # 1 swxY w Y   dS dS )zACall the socket_close callback with the about-to-be-closed socketNz'Caught exception in on_socket_close: %s)r{  r2  ry  rA  r2  r  rF  r  )rC   r  r2  r  s       r5   r  zClient._call_socket_close+  so   ! 	3 	3"2O	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3  	(  #OD$.$????    NN$&OQTV V V3                      	 	r0  c                    | j         S )a  The callback called when the socket needs writing but can't.

        This should be used to register the socket with an external event loop for writing.

        Expected signature is (for all callback API version)::

            socket_register_write_callback(client, userdata, socket)

        :param Client client: the client instance for this callback
        :param userdata: the private user data as set in Client() or user_data_set()
        :param SocketLike sock: the socket which should be registered for writing

        Decorator: @client.socket_register_write_callback() (``client`` is the name of the
            instance which this callback is being attached to)
        r  rK   s    r5   on_socket_register_writezClient.on_socket_register_write:  s    " --r4   c                T    | j         5  || _        d d d            d S # 1 swxY w Y   d S rB   )r{  r  r  s     r5   r:  zClient.on_socket_register_writeM  sw    ! 	2 	2-1D*	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2r  c                     d fd}|S )Nr  r+  r@   c                    | _         | S rB   r9  r  s    r5   r  z8Client.socket_register_write_callback.<locals>.decoratorU  s    -1D*Kr4   r-  r3   r  s   ` r5   socket_register_write_callbackz%Client.socket_register_write_callbackR  r  r4   c                0   | j         r| j        rdS d| _        | j        5  | j        }ddd           n# 1 swxY w Y   |rV	  || | j        | j                    dS # t
          $ r/}|                     t          d|           | j        s Y d}~dS d}~ww xY wdS )zBCall the socket_register_write callback with the unwritable socketNTz0Caught exception in on_socket_register_write: %s)	rB  r  r{  r:  rA  r2  r  rF  r  )rC   r:  r  s      r5   r  z"Client._call_socket_register_writeZ  sK   z 	T3 	F!%! 	E 	E'+'D$	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E $ 	(($.$*6 6 6 6 6    "TVY[ [ [/      		 	s$   377A 
B$$BBc                    | j         S )a  The callback called when the socket doesn't need writing anymore.

        This should be used to unregister the socket from an external event loop for writing.

        Expected signature is (for all callback API version)::

            socket_unregister_write_callback(client, userdata, socket)

        :param Client client: the client instance for this callback
        :param userdata: the private user data as set in Client() or user_data_set()
        :param SocketLike sock: the socket which should be unregistered for writing

        Decorator: @client.socket_unregister_write_callback() (``client`` is the name of the
            instance which this callback is being attached to)
        r  rK   s    r5   on_socket_unregister_writez!Client.on_socket_unregister_writel  s    & //r4   c                T    | j         5  || _        d d d            d S # 1 swxY w Y   d S rB   )r{  r  r  s     r5   rB  z!Client.on_socket_unregister_write  sy     ! 	4 	4/3D,	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4r  c                     d fd}|S )Nr  r+  r@   c                    | _         | S rB   rA  r  s    r5   r  z:Client.socket_unregister_write_callback.<locals>.decorator  s     04D,Kr4   r-  r3   r  s   ` r5    socket_unregister_write_callbackz'Client.socket_unregister_write_callback  s)    	 	 	 	 	 	
 r4   c                .   |p| j         }|r| j        sdS d| _        | j        5  | j        }ddd           n# 1 swxY w Y   |rQ	  || | j        |           dS # t
          $ r/}|                     t          d|           | j        s Y d}~dS d}~ww xY wdS )zBCall the socket_unregister_write callback with the writable socketNFz2Caught exception in on_socket_unregister_write: %s)	rB  r  r{  rB  rA  r2  r  rF  r  )rC   r  rB  r  s       r5   r  z$Client._call_socket_unregister_write  sJ    !tz 	41 	F!&! 	I 	I)-)H&	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I & 	**4FFFFF    "VX[] ] ]/      	 	s$   7;;A 
B#$BBr   callbackr  c                    ||t          d          | j        5  || j        |<   ddd           dS # 1 swxY w Y   dS )a  Register a message callback for a specific topic.
        Messages that match 'sub' will be passed to 'callback'. Any
        non-matching messages will be passed to the default `on_message`
        callback.

        Call multiple times with different 'sub' to define multiple topic
        specific callbacks.

        Topic specific callbacks may be removed with
        `message_callback_remove()`.

        See `on_message` for the expected signature of the callback.

        Decorator: @client.topic_callback(sub) (``client`` is the name of the
            instance which this callback is being attached to)

        Example::

            @client.topic_callback("mytopic/#")
            def handle_mytopic(client, userdata, message):
                ...
        Nz&sub and callback must both be defined.)r   r{  rr  )rC   r   rH  s      r5   message_callback_addzClient.message_callback_add  s    . s{EFFF! 	6 	6-5D%c*	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   377c                     d fd}|S )Nr  r  r@   c                4                         |            | S rB   )rJ  )r  rC   r   s    r5   r  z(Client.topic_callback.<locals>.decorator  s    %%c4000Kr4   r  r3   )rC   r   r  s   `` r5   topic_callbackzClient.topic_callback  s/    	 	 	 	 	 	 	 r4   c                    |t          d          | j        5  	 | j        |= n# t          $ r Y nw xY wddd           dS # 1 swxY w Y   dS )zVRemove a message callback previously registered with
        `message_callback_add()`.Nzsub must defined.)r   r{  rr  KeyError)rC   r   s     r5   message_callback_removezClient.message_callback_remove  s     ;0111! 	 	-c22   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s,   A$A
1A1AAAr   c                   |rg|                                   | j        t          j        t          j        fv rt          j        | _        t
          j        }|                     d|           |t          k    rt          j	        | _        |S )NFr  )
r  rd  r   rS  rT  r   rm   r  rt   rU  r  s     r5   r  zClient._loop_rc_handle  s      	G{/EGWGlmmm.C"3""e2"FFF###*BDK	r4   c           	        | j         d         dk    r	 |                     d          }t          |          dk    rt          j        S |d         | j         d<   n# t
          $ r t          j        cY S t          $ r2}|                     t          d|           t          j        cY d }~S d }~wt          $ r2}|                     t          d|           t          j        cY d }~S d }~ww xY w| j         d         dk    rH	 	 |                     d          }t          |          dk    rt          j        S |d         }| j         d                             |           t          | j         d                   d	k    rt          j        S | j         d
xx         |dz  | j         d         z  z  cc<   | j         d         dz  | j         d<   nV# t
          $ r t          j        cY S t          $ r2}|                     t          d|           t          j        cY d }~S d }~ww xY w|dz  dk    rn(d| j         d<   | j         d
         | j         d<   d}| j         d         dk    r)	 |                     | j         d                   }t          |          dk    rt          j        S | j         dxx         t          |          z  cc<   | j         dxx         |z  cc<   nV# t
          $ r t          j        cY S t          $ r2}|                     t          d|           t          j        cY d }~S d }~ww xY w|dz  }|dk    r>| j        5  t                      | _        d d d            n# 1 swxY w Y   t          j        S | j         d         dk    )d| j         d<   |                                 }ddg ddt#          d          ddd| _         | j        5  t                      | _        d d d            n# 1 swxY w Y   |S )Nr%   r   r   ztimeout on socket: %sfailed to receive on socket: %sr&   Tr'      r)      r(      r,   d   r+   r-   r4   r7  )rW  r  r   r   rt   r   r   TimeoutErrorr  rF  r  r   ro   r|  r   r[  _packet_handler*   )rC   r%   r  byte
byte_valuecountdatar   s           r5   r  zClient._packet_read  s0    ?9%**8//!,, w<<1$$(;;-4QZ	** # 4 4 4$3333 8 8 8 "93@ @ @$7777777 8 8 8 "CSJ J J$77777778 ?+,11`??1--D 4yyA~~,??!%aJO$56==jIII 4?+<=>>BB,>>O$6777"S(DO<L,M<N N7778<HX8Y\_8_DO$455% ' 8 8 8(7777 < < <NN$&GN N N(;;;;;;;<$ $**14 12DO,-,0O<N,ODOL)ol+a//2t|'DEE t99>>(;;---T:---)))T1)))) # 4 4 4$3333 8 8 8 "CSJ J J$77777778 QJEzz( 4 4(1D%4 4 4 4 4 4 4 4 4 4 4 4 4 4 4$33% ol+a//* "#  "" ! !nn	
 	
   	, 	, )D	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,	s   A C%0	C%9'B& C%&C%3'C C% C%<G H	H"'H	HH K L!&	L!/'LL!L!6MMMO!!O%(O%c           
        	 	 | j                                         }n# t          $ r t          j        cY S w xY w	 |                     |d         |d         d                    }n# t          t          f$ r) | j                             |           t          j        cY S t          $ r) | j                             |           t          j
        cY S t          $ rL}| j                             |           |                     t          d|           t          j        cY d }~S d }~ww xY w|dk    r||dxx         |z  cc<   |dxx         |z  cc<   |d         dk    r4|d         dz  t          k    rq|d	         dk    rd| j        5  | j        }d d d            n# 1 swxY w Y   |r!| j        5  	 | j        t(          j        k    r.t-          t.          |          } || | j        |d
                    n| j        t(          j        k    r^t-          t4          |          } || | j        |d
         t7          t8          j                  t=          t8          j                             nt?          d          n;# t@          $ r.}|                     t          d|           | j!        s Y d }~nd }~ww xY wd d d            n# 1 swxY w Y   |d         "                                 |d         dz  tF          k    r| j$        5  tK                      | _&        d d d            n# 1 swxY w Y   | '                    dt          j                   | (                                 | j)        tT          j+        k    rtT          j,        | _)        t          j        S n| j                             |           nn| j$        5  tK                      | _&        d d d            n# 1 swxY w Y   t          j        S )NTr+   r-   rS  r   r,   r%   r@  r9   r8   r3  "Caught exception in on_publish: %sr<   Fr  )-rZ  popleftr   r   rm   r  r  r   
appendleftr   r   r  r  rF  rt   rB  r{  r  ry  rI  r   rJ  r   CallbackOnPublish_v1rA  VERSION2CallbackOnPublish_v2r   r   PUBACKr   r   r2  r  r   r   r|  r   r\  r  r  rd  r   rS  rT  )rC   r+   write_lengthr  r  s        r5   r  zClient._packet_writeX  sd   Q	6)1133 6 6 6$555568#8$VE]^^4 6  6"J/ 6 6 6 ++F333$5555" 4 4 4 ++F333$3333 8 8 8 ++F333 "CSJ J J$7777777	8 a|$$$4$$$u-,'1,,y)D0W<<RSASAS!1 9 9)-J9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 & .!%!8 . .!.'+'AEWE`'`'`59:NPZ5[5[
(2
4PU(W(W(W(W)-)CGYGb)b)b59:NPZ5[5[
(2
,0,0N,25M,6{7I,J,J,6{7I,J,J)* )* )* )* /;;].^.^(^'0 !. !. !.$(NN(46Z\_%a %a %a+/+C %.(-%. %. %. %. %.!.%. . . . . . . . . . . . . . .8 v88:::y)D0Z??!0 = =1:D.= = = = = = = = = = = = = = = ../4"/"@ /    ((***  ;*:*PPP*:*ODK,== @$ $//7777cQ	f   	- 	-!*D	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- --s    66)A$ $7D#/D#	D#ADD#D#FFF,J;.CI43J;4
J,>$J'"J;'J,,J;;J?J?;LL"L3OOOlevelr   fmtargsc                    | j         4||z  }	 |                      | | j        ||           n# t          $ r Y nw xY w| j        #t          |         } | j        j        ||g|R   d S d S rB   )r  rA  r2  r  LOGGING_LEVELlog)rC   rg  rh  ri  r  	level_stds         r5   r  zClient._easy_log  s    ;"*CD$.%====    <#%e,IDLY3d333333 $#s   , 
99c                &   | j         dk    rd S t                      }| j        5  | j        }| j        }d d d            n# 1 swxY w Y   | j        >||z
  | j         k    s||z
  | j         k    r#| j        t          j        k    r| j	        dk    r	 | 
                                 | j        5  || _        || _        d d d            d S # 1 swxY w Y   d S # t          $ r9 |                                  |                     dt          j                   Y d S w xY w|                                  | j        t          j        t          j        fv rt          j        | _        t          j        }nt          j        }|                     d|           d S d S d S )Nr   Fr  )rE  r   r|  r\  r[  rB  rd  r   ru  ra  _send_pingreqr2  r  r  r   rt   rS  rT  rm   r}   )rC   r  last_msg_outlast_msg_inr   s        r5   r  zClient._check_keepalive  sX   ?aFkk  	, 	,-L+K	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, :!s\'9T_'L'LPSVaPaeietPtPt{.@@@T\UVEVEV0&&((( , 0 0-0*,/)0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 !   $$&&&**+0+> +         """;#3#IK[Kp"qqq"2"GDK&7BB&9B&&', '     / "!PtPts3   >AAC *CC
C
?DDc                    | j         5  | xj        dz  c_        | j        dk    rd| _        | j        cd d d            S # 1 swxY w Y   d S )Nr      )r  rb  rK   s    r5   rc  zClient._mid_generate  s    % 	" 	"NNaNN~&&!">		" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s   )>AAc                x    d| v sd| v rt          d          t          |           dk    rt          d          dS )z Check if the topic is a topic without wildcard and valid length.

            Raise ValueError if the topic isn't valid.
           +   #z'Publish topic cannot contain wildcards.  zPublish topic is too long.N)r   r   )r   s    r5   rb  zClient._raise_for_invalid_topic  sL     5==DEMMFGGGu::9::: r4   c                    t          |           dk    sCt          |           dk    s0t          d |                     d          D                       sd| v rt          j        S t          j        S )Nr   rw  c              3  L   K   | ]}t          |          d k    d|v pd|v V   dS )r   ru  rv  N)r   )r   ps     r5   r   z4Client._filter_wildcard_len_check.<locals>.<genexpr>  s9      QQac!ffqjj419)	jjjjQQr4      /s   #/)r   r  splitr   rp   rm   )r   s    r5   r  z!Client._filter_wildcard_len_check  se    HHMMSXX--QQ399T??QQQQQ .C<< // 11r4   c                    |                      t          d           |                     t                    }|t          j        k    rt                      | _        |S )NzSending PINGREQ)r  r  _send_simple_commandPINGREQr   rm   r   ra  r  s     r5   ro  zClient._send_pingreq  sH    ~'8999&&w/////$;;DL	r4   c                l    |                      t          d           |                     t                    S )NzSending PINGRESP)r  r  r~  PINGRESPrK   s    r5   _send_pingrespzClient._send_pingresp  s+    ~'9:::((222r4   r8   c                r    |                      t          d|           |                     t          |d          S )NzSending PUBACK (Mid: %d)F)r  r  _send_command_with_midre  r   s     r5   _send_pubackzClient._send_puback	  1    ~'A3GGG**63>>>r4   c                r    |                      t          d|           |                     t          |d          S )NzSending PUBCOMP (Mid: %d)F)r  r  r  PUBCOMPr   s     r5   _send_pubcompzClient._send_pubcomp  s1    ~'BCHHH**7C???r4   r+   r*   r)   c                    g }	 |dz  }|dz  }|dk    r|dz  }|                     |           |                     |           |dk    r|S H)NTrV  r   )r   )rC   r+   r)   remaining_bytesrZ  s        r5   _pack_remaining_lengthzClient._pack_remaining_length  sr     	#c)D/36!##""4(((MM$1$$	r4   r]  bytes | strc                    t          |          }|                    t          j        dt	          |                               |                    |           d S )N!H)r   r   structpackr   )rC   r+   r]  s      r5   _pack_str16zClient._pack_str16"  sK    D!!fk$D		22333dr4   r4   r   r	  r<   r;   c	                   t          |t                    st          d          |r+t          |t          t          f          st          d          | j        t
          j        S t          |dz  dz  z  |dz  z  |z  }	t                      }
|
                    |	           t          |          }dt          |          z   |z   }|dk    rS| j
        t          k    r"|                     t          d||||||           nu|                     t          d|||||           nT| j
        t          k    r#|                     t          d	|||||||	  	         n!|                     t          d
||||||           |dk    r|dz  }| j
        t          k    r+|d}n|                                }|t          |          z  }|                     |
|           |                     |
|           |dk    r(|
                    t%          j        d|                     | j
        t          k    r|
                    |           |
                    |           |                     t          |
|||          S )Nztopic must be bytes, not strzpayload must be bytes if setr   rX   r   r   zHSending PUBLISH (d%d, q%d, r%d, m%d), '%s', properties=%s (NULL payload)z9Sending PUBLISH (d%d, q%d, r%d, m%d), '%s' (NULL payload)zISending PUBLISH (d%d, q%d, r%d, m%d), '%s', properties=%s, ... (%d bytes)z:Sending PUBLISH (d%d, q%d, r%d, m%d), '%s', ... (%d bytes)    r  )r   r:   r   r*   rB  r   rq   rB  r   r   r@  rO  r  r  r  r  r  r   r  _packet_queue)rC   r8   r   r   r9   r  r	  r<   r  r%   r+   
payloadlenr)   packed_propertiess                 r5   rd  zClient._send_publish'  s    %'' 	<:;;; 	<:gy/ABB 	<:;;;: 11cCiA-.#(;fDg\\
s5zz>J6??~''"^fc5*    "Ofc5    ~''"_fc5*j    "Pfc5*   77!>V##!$+!!$.OO$5$5!$5 6 66##F,<==='''77MM&+dC00111>V##MM+,,,g!!'63TBBBr4   c                r    |                      t          d|           |                     t          |d          S )NzSending PUBREC (Mid: %d)F)r  r  r  PUBRECr   s     r5   _send_pubreczClient._send_pubrecv  r  r4   c                x    |                      t          d|           |                     t          dz  |d          S )NzSending PUBREL (Mid: %d)r   F)r  r  r  PUBRELr   s     r5   _send_pubrelzClient._send_pubrelz  s5    ~'A3GGG**6A:sEBBBr4   r%   c                r    |r|dz  }d}t          j        d|||          }|                     |||d          S )N   r   z!BBHr   r  r  r  )rC   r%   r8   r	  r)   r+   s         r5   r  zClient._send_command_with_mid~  sI     	sNGVW.>DD!!'63:::r4   c                b    d}t          j        d||          }|                     ||dd          S )Nr   !BBr  )rC   r%   r)   r+   s       r5   r~  zClient._send_simple_command  s6    UG-=>>!!'61a888r4   c                   t          | j                  }|t          k    rdnd}dt          |          z   dz   dz   dz   dz   t          | j                  z   }d}| j        t
          k    r,| j        du r|dz  }n)| j        t          k    r| j        r|dz  }n| j	        r|dz  }| j
        rS|dt          | j                  z   dz   t          | j                  z   z  }|d| j        dz  dz  z  | j        dz  d	z  z  z  }| j        E|dt          | j                  z   z  }|d
z  }| j        |dz  }|dt          | j                  z   z  }| j        t
          k    rq| j        d}n| j                                        }|t          |          z  }| j
        r5| j        d}n| j                                        }|t          |          z  }t(          }t+                      }	|	                    |           | j        t0          k    r|d
z  }|                     |	|           |	                    t7          j        dt          |           dt          |          ||||                     | j        t
          k    r|	|z  }	|                     |	| j                   | j
        rK| j        t
          k    r|	|z  }	|                     |	| j                   |                     |	| j                   | j        =|                     |	| j                   | j        |                     |	| j                   || _        | j        t
          k    rS|                     t>          d|d
z  dz	  |dz  dz	  |dz  d	z	  |dz  dz	  |dz  dz	  |dz  dz	  || j        | j                   nL|                     t>          d|d
z  dz	  |dz  dz	  |dz  d	z	  |dz  dz	  |dz  dz	  |dz  dz	  || j        
  
         |                      ||	dd          S )Ns   MQTTs   MQIsdpr   r   r   TrT  rX      rV  @   r  r  sBBHzQSending CONNECT (u%d, p%d, wr%d, wq%d, wf%d, c%d, k%d) client_id=%s properties=%s             zCSending CONNECT (u%d, p%d, wr%d, wq%d, wf%d, c%d, k%d) client_id=%s)!r$   r@  MQTTv311r   rT  rO  rN  rZ   r  rP  rm  rn  ro  rp  rq  rU  rV  rk  r  rl  CONNECTr*   r   rH  rq  r  r   r  r  rE  r  r  r  )
rC   r  	proto_verr'  r)   connect_flagspacked_connect_propertiespacked_will_propertiesr%   r+   s
             r5   rI  zClient._send_connect  s   ''	'83377s8}},q0DO,,- >V## D((%"&AAAdF`A%  	"T!M: 	1D$%%!&()!*,/0B,C,C!D DTdnt&;%AB"T)a/1 1M >%C$7$7 77T!M~)% ADN(;(;$;; >V##'/,3)),0,D,I,I,K,K)$= > >>z @(0-4**-1-B-G-G-I-I* C(>$?$?? g ++I##F,<===fk$X$$$MM8Yy
 
 	 	 	
 >V##//F111: 	9~''00VT%5666VT%7888>%VT^444~)  888#>V##NNc%!+%!+%!+%!+$*$*(    NNU%!+%!+%!+%!+$*$*   !!'61a888r4   c                `   | j         t          k    r|                     t          d||           n|                     t          d           d}t          }t                      }|                    |           | j         t          k    rL||H|t          t          dz	  d          }|dz  }|&|                                }|t          |          z  }| 
                    ||           | j         t          k    r |||                                z  }|||z  }|                     ||dd          S )Nz.Sending DISCONNECT reasonCode=%s properties=%szSending DISCONNECTr   rT  
identifierr   )r@  rO  r  r  r   r*   r   r   r  r   r  r  )rC   rw  r  r)   r%   r+   packed_propss          r5   rz  zClient._send_disconnect  sC   
 >V##NN>+[%%   
 NN>+?@@@g>V##%)?%!+J!O!J!J!JJ A% )#-??#4#4L$L(9(99$##F,<===>V##%*//+++)l*F!!'61a888r4   topics.Sequence[tuple[bytes, SubscribeOptions | int]]tuple[MQTTErrorCode, int]c                   d}| j         t          k    r+|d}n|                                }|t          |          z  }|D ]\  }}|dt          |          z   dz   z  }t          |dz  z  dz  }t                      }	|	                    |           |                     |	|           |                                 }
|		                    t          j        d|
                     | j         t          k    r|	|z  }	|D ]X\  }}|                     |	|           | j         t          k    r|	|                                z  }	C|	                    |           Y|                     t          d||
|           |                     ||	|
d          |
fS )Nr   r  r   rX   r  zSending SUBSCRIBE (d%d, m%d) %s)r@  rO  r  r   	SUBSCRIBEr*   r   r  rc  r   r  r  r  r  r  )rC   r	  r  r  r)   packed_subscribe_propertiesr  r   r%   r+   rk  r  s               r5   r  zClient._send_subscribe  s    >V##!.5++.8oo.?.?+$? @ @@ 	/ 	/DAqCFF
Q.sax(3.g##F,<===&&((	fk$	22333>V##11F 	! 	!DAqVQ'''~''!&&(("a    -	
 	
 	
 ""7FIqAA9MMr4   list[bytes]c                   d}| j         t          k    r+|d}n|                                }|t          |          z  }|D ]}|dt          |          z   z  }t          |dz  z  dz  }t                      }|                    |           |                     ||           |                                 }	|	                    t          j        d|	                     | j         t          k    r||z  }|D ]}|                     ||           | j         t          k    r |                     t          d||	||           n|                     t          d||	|           |                     |||	d          |	fS )Nr   r  rX   r  z$Sending UNSUBSCRIBE (d%d, m%d) %s %sz!Sending UNSUBSCRIBE (d%d, m%d) %sr   )r@  rO  r  r   UNSUBSCRIBEr*   r   r  rc  r   r  r  r  r  r  )
rC   r	  r  r  r)   packed_unsubscribe_propertiesr  r%   r+   rk  s
             r5   r  zClient._send_unsubscribeF  s    >V##!07--0:0A0A-$A B BB 	+ 	+ACFF
**S0g##F,<===&&((	fk$	22333>V##33F 	( 	(AVQ'''' >V##NN6    NN3   ""7FIqAA9MMr4   c                l    | j         t          k    r| j        t          k    r| j        S | j        S | j        S rB   )r@  rO  rN  rZ   r  rP  rK   s    r5   _check_clean_sessionzClient._check_clean_sessionw  s9    >V## $???11((&&r4   c                   | j         5  d| _        | j                                        D ]}d|_        | j        dk    s| j        | j        k     r|j        dk    rt          |_        <|j        dk    r$|j        t          k    rd|_
        t          |_        k|j        dk    rx|                                 r$|j        t          k    rd|_
        t          |_        |j        t          k    rt          |_        |j        t          k    rd|_
        t          |_        t          |_        	 d d d            d S # 1 swxY w Y   d S )Nr   r   Tr   )r}  ri  rf  valuesr  rh  r9   rg  r  re  r	  r  mqtt_ms_wait_for_pubcompmqtt_ms_resend_pubrelrf  rh  rC   ms     r5   _messages_reconnect_reset_outz$Client._messages_reconnect_reset_out  sv   $ 	- 	-&'D#'..00 - -.!33t7NQUQl7l7luzz"1!7&===$(AE"1!4466 
: w/99(,&5AGG w*BBB*?#$7.E#E#E,0AE*9,AGG1-	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   DD33D7:D7c                X   | j         5  |                                 r&t          j                    | _        	 d d d            d S | j                                        D ]4}d|_        |j        dk    r | j                            |j	                   45	 d d d            d S # 1 swxY w Y   d S )Nr   r   )
r~  r  rX  re  rg  r  r  r9   popr8   r  s     r5   _messages_reconnect_reset_inz#Client._messages_reconnect_reset_in  s   # 
	 
	((** $/$;$=$=!
	 
	 
	 
	 
	 
	 
	 
	 &--//  5A::%))!%0000 	
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	s   .BABB#&B#c                V    |                                   |                                  d S rB   )r  r  rK   s    r5   rD  z Client._messages_reconnect_reset  s,    **,,,))+++++r4   c                   |||dt          |          ||d}| j                            |           | j        1	 | j                            t
                     n# t          $ r Y nw xY w| j        N| j        G| j	        
                    d          r-| j	                                         |                                 S |                                  t          j        S )Nr   )r%   r8   r9   r-   r,   r+   r<   F)r   rZ  r   rD  rH   sockpair_datar   r  r  ry  acquirereleaserX  r  r   rm   )rC   r%   r+   r8   r9   r<   mpkts          r5   r  zClient._packet_queue  s     f++
 
 	%%% ?&$$]3333"   
 <D$B$J&..u55 )'//111(((((***--s   A 
A'&A'c                p   | j         d         dz  }|t          k    r|                                 S |t          k    r|                                 S |t
          k    r|                     d          S |t          k    r|                     d          S |t          k    r| 	                                S |t          k    r|                                 S |t          k    r|                                 S |t          k    r|                                 S |t           k    r |                                  t$          j        S |t(          k    r|                                 S |t,          k    r0| j        t0          k    r |                                  t$          j        S |                     t6          d|           t$          j        S )Nr%   r@  re  r  zError: Unrecognised command %s)rW  r  _handle_pingreqr  _handle_pingrespre  _handle_pubackcompr  rB  _handle_publishr  _handle_pubrecr  _handle_pubrelr   _handle_connackSUBACK_handle_subackr   rm   UNSUBACK_handle_unsubackr   r@  rO  _handle_disconnectr  rF  ro   )rC   cmds     r5   rY  zClient._packet_handle  s   oi(4/'>>'')))H__((***F]]**8444G^^**9555G^^'')))F]]&&(((F]]&&(((G^^'')))F]]!!! 11H__((***J4>V#;#;##%%% 11 NN<)I3OOO 22r4   c                    | j         d         dk    rt          j        S |                     t          d           |                                 S )Nr)   r   zReceived PINGREQ)rW  r   ro   r  r  r  rK   s    r5   r  zClient._handle_pingreq  sE    ?-.!33 22~'9:::""$$$r4   c                    | j         d         dk    rt          j        S d| _        |                     t
          d           t          j        S )Nr)   r   zReceived PINGRESP)rW  r   ro   ra  r  r  rm   rK   s    r5   r  zClient._handle_pingresp  sE    ?-.!33 22 ~':;;;--r4   c                r   | j         t          k    r| j        d         dk     rt          j        S n| j        d         dk    rt          j        S | j         t          k    rt          j        d| j        d         d d                   \  }}|dk    rt          t          dz	  d          }d }nt          t          dz	  |	          }t          t          dz	            }|                    | j        d         dd                     n4t          j        d| j        d                   \  }}t          |          }d }| j         t          k    r|t          k    rK| j        st          S |                     t          d
||           t           | _         |                                 S |t$          k    r| j        dk    r~| j        st          S |                     t          d||           t)          t+          j                    j        d                              d          | _        |                                 S |dk    rt2          j        | _        d | _        | j         t          k    r|                     t          d|||           n|                     t          d||           d| _        | j        5  | j        }d d d            n# 1 swxY w Y   |rai }|dz  |d<   | j         5  	 | j!        tD          j#        k    rc| j         t          k    r*tI          tJ          |          } || | j&        |||           ntI          tN          |          } || | j&        ||           n| j!        tD          j(        k    r_tI          tR          |          }tU          |d         dk              }|t          tV          j                  } || | j&        |||           ntY          d          n;# tZ          $ r.}|                     t\          d|           | j/        s Y d }~nd }~ww xY wd d d            n# 1 swxY w Y   |dk    rct          j0        }	| j1        5  | j2        3                                D ]}
ti                      |
_5        |
j6        tn          k    r)| 8                                 t`          c cd d d            S |
j9        dk    r| j         5  | :                    |
j;        |
j<                            d          |
j=        |
j9        |
j>        |
j?        |
j@                  }	d d d            n# 1 swxY w Y   |	t          j0        k    r|	c cd d d            S n|
j9        dk    r|
j6        t          k    r| xjB        dz  c_B        t          |
_6        | j         5  | :                    |
j;        |
j<                            d          |
j=        |
j9        |
j>        |
j?        |
j@                  }	d d d            n# 1 swxY w Y   |	t          j0        k    r|	c cd d d            S nO|
j9        dk    rC|
j6        t          k    r| xjB        dz  c_B        t          |
_6        | j         5  | :                    |
j;        |
j<                            d          |
j=        |
j9        |
j>        |
j?        |
j@                  }	d d d            n# 1 swxY w Y   |	t          j0        k    r|	c cd d d            S n|
j6        t          k    ru| xjB        dz  c_B        t          |
_6        | j         5  | G                    |
j;                  }	d d d            n# 1 swxY w Y   |	t          j0        k    r|	c cd d d            S | 8                                 	 d d d            n# 1 swxY w Y   |	S |dk    r|dk     rt          jH        S t          j        S )Nr)   r   r  r+   r   rT  r   )aNamer  z=Received CONNACK (%s, %s), attempting downgrade to MQTT v3.1.r4   z:Received CONNACK (%s, %s), attempting to use non-empty CIDr4  r5  r6  r   z'Received CONNACK (%s, %s) properties=%szReceived CONNACK (%s, %s)Fzsession present)r^   r3  z"Caught exception in on_connect: %sr   r  r  )Ir@  rO  rW  r   ro   r  unpackr   r   r   r   r  r   r`  r  r  rQ  r  r   rT  r   rR  rS  r$   r   r   ru  rd  r_  r  r{  r  ry  rI  r   rJ  r   CallbackOnConnect_v1_mqtt5rA  CallbackOnConnect_v1_mqtt3rc  CallbackOnConnect_v2r]   r   r   r2  rF  r  rm   r}  rf  r  r   r  r  rh  rX  r9   rd  r8   r   r   r  r	  r  rg  ri  re  rf  r  r  r  rr   )rC   flagsresultreasonr  r  
flags_dictr  r  r   r  s              r5   r  zClient._handle_connack  sS
   >V##12Q66$66 7_/0A55 22>V##$mtx0!46 6OUF{{ $GqL8VWWW!

#GqLVDDD'155
!!$/(";ABB"?@@@@$mE4?83LMMOUF6v>>FJ>X%%9991 -,,"S6   ")~~'''???3..1 -,,"P6  
 #*$*,,*:B"G"G"G"N"Nv"V"V~~'''Q;;*<DK$(D!>V##NN I5RXZdf f f f NN ;UFL L L &+"! 	) 	)J	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)  '	J,1DLJ()( $ $#15G5PPP>V33)-.H*)U)UJ&JtT^,6
L L L L *..H*)U)UJ&J $dnj&J J J J37I7RRR%)*>
%K%K
(4,67H,IA,M) ) ) &-)3K4G)H)HJ"
  N)"&    ++MNNN    NN$&JCQ Q Q3     A$ $ $ $ $ $ $ $ $ $ $ $ $ $ $L Q;;/B( ;& ;&+2244 :& :&A"+++AKw.00)))///;& ;& ;& ;& ;& ;& ;& ;& uzz!4 	 	!%!3!3 ! !w 7 7 !	 ! ! !+,< "4 " "B	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 !???#%II';& ;& ;& ;& ;& ;& ;& ;&$ @!7o55 33q833&=AG!%!8 	" 	"%)%7%7$%E$%GNN7$;$;$%I$%E$%H$%E/0| &8 &" &"	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"  "]%CCC')		G;& ;& ;& ;& ;& ;& ;& ;&H !7o55 33q833&=AG!%!8 	" 	"%)%7%7$%E$%GNN7$;$;$%I$%E$%H$%E/0| &8 &" &"	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"  "]%CCC')		g;& ;& ;& ;& ;& ;& ;& ;&d  DW(=== 33q833&>AG!%!8 > >%)%6%6qu%=%=> > > > > > > > > > > > > > >!]%CCC')		u;& ;& ;& ;& ;& ;& ;& ;&v OO%%%%u:&;& ;& ;& ;& ;& ;& ;& ;& ;& ;& ;& ;& ;& ;& ;&z IaZZFQJJ 66 22s  (J<<K K P C;OP 
P#$PP PP  P$'P$A^.^ AT^T##^&T#'^
A ^
AW)^)W--^0W-1^A^AZ4(^4Z88^;Z8<^4^\:.^:\>>^\>^%^^^c                   t           dz	  }d x}}| j        d         dk    rzt          |          }|                    | j        d                    | j        d         dk    r:t	          |          }|                    | j        d         dd                    \  }}|                     t          d||           |                                  |                     dt          j
        ||	           d S )
NrT  r)   r   r+   rX   r   zReceived DISCONNECT %s %sT)r  r  r  r  )r   rW  r   r  r   r  r  r  r  r   rm   )rC   packet_type
reasonCoder  props	props_lens         r5   r  zClient._handle_disconnect  s    Ao"&&
Z?-.22#K00Jdoh788812Q66'44
#-#4#4OH-abb1$3 $3 y~'B!!	 	 	
 	#0!	 	 	
 	
 	
 	
 	
r4   c                   |                      t          d           dt          | j        d                   dz
   d}t	          j        || j        d                   \  }}| j        t          k    rDt          t          dz	            }|                    |          \  }}d ||d          D             }nMdd	t          |          z   }t	          j        ||          }d
 |D             }t          t          dz	            }| j
        5  | j        }	d d d            n# 1 swxY w Y   |	r%| j        5  	 | j        t          j        k    rc| j        t          k    r*t!          t"          |	          }	 |	| | j        |||           nwt!          t&          |	          }	 |	| | j        ||           nN| j        t          j        k    r*t!          t*          |	          }	 |	| | j        |||           nt-          d          n;# t.          $ r.}
|                      t0          d|
           | j        s Y d }
~
nd }
~
ww xY wd d d            d S # 1 swxY w Y   d S d S )NzReceived SUBACKr  r+   r   r   rT  c                @    g | ]}t          t          d z	  |          S rT  r  r   r  r   cs     r5   
<listcomp>z)Client._handle_suback.<locals>.<listcomp>  s)    ]]]Q:fka@@@]]]r4   !Bc                @    g | ]}t          t          d z	  |          S r  r  r  s     r5   r  z)Client._handle_suback.<locals>.<listcomp>  s)    VVVQ:fka@@@VVVr4   r3  z$Caught exception in on_subscribe: %s)r  r  r   rW  r  r  r@  rO  r   r  r{  r  ry  rI  r   rJ  r   CallbackOnSubscribe_v1_mqtt5rA  CallbackOnSubscribe_v1_mqtt3rc  CallbackOnSubscribe_v2r   r2  rF  r  )rC   pack_formatr8   r+   r  r  r  reasoncodesgranted_qosr  r  s              r5   r  zClient._handle_suback  s?   ~'8999@3tx899A=@@@k4?83LMMf>V###FaK00J)0088E9]]&QZQ[Q[J\]]]KK1cCKK/11K -V<<KVV+VVVK#FaK00J! 	- 	-,L	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-  	(  15G5PPP>V33+/0Ll+[+[L(L $dnc;
T T T T ,00Ll+[+[L(L $dnc;H H H H37I7RRR'+,BL'Q'Q$  N'&    ++MNNN    NN$&LcS S S3     3                 	 	sO   DD #D 1I3CG:9I:
H2$H-(I-H22II	Ic                   | j         d         }t                      }|dz  dz	  dk    |_        |dz  dz	  |_        |dz  dk    |_        dt          | j         d                   d	z
   d
}t          j        || j         d                   \  }}d| d
t          |          |z
   d
}t          j        ||          \  }}| j        t          k    rt          |          dk    rt          j        S 	 |                    d          }n# t          $ r d|}Y nw xY w||_        |j        dk    r3dt          |          d	z
   d
}t          j        ||          \  |_        }| j        t          k    rCt!          t"          dz	            |_        |j                            |          \  }}	||	d          }||_        | j        t          k    rN|                     t*          d|j        |j        |j        |j        ||j        t          |j                  	  	         nG|                     t*          d|j        |j        |j        |j        |t          |j                             t-                      |_        |j        dk    r!|                     |           t          j        S |j        dk    rB|                     |           | j        rt          j        S |                     |j                  S |j        d	k    rV|                     |j                  }
t:          |_        | j        5  || j         |j        <   d d d            n# 1 swxY w Y   |
S t          j        S )Nr%   r  rX   r   r  r   r  r+   r   r   r  r   zTOPIC WITH INVALID UTF-8: rT  zKReceived PUBLISH (d%d, q%d, r%d, m%d), '%s', properties=%s, ...  (%d bytes)z<Received PUBLISH (d%d, q%d, r%d, m%d), '%s', ...  (%d bytes))!rW  re   r	  r9   r  r   r  r  r@  rO  r   ro   r  UnicodeDecodeErrorr   r8   r   rB  r  r   r  r  r   r  _handle_on_messagerm   r>  r  r  mqtt_ms_wait_for_pubrelr  r~  rg  )rC   headerrl  r  slenr+   r   print_topicr  r  r   s              r5   r  zClient._handle_publish  s   +--!+1}* 4-A-@3tx899A=@@@{DOH4MNNv6$66Vt!3666 -V<<>V##E

a 22	A,,w//KK! 	A 	A 	A@u@@KKK	A ;??1s6{{Q111K$*M+v$F$F!W[&>V##!+GqL!9!9G&188@@E9IJJ'F >V##NN]W['.'+W/W_1E1E	    NNNW['.'+S11	   &KK;!##G,,, 11[A##G,,, 6$55((555[A""7;//B3GM' 9 918!'+.9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 I 22s$   -D DD L<<M M c                    | j         r6|dk    r|                     |          S |dk    r|                     |          S t          j        S )z
           send an acknowledgement for a given message id (stored in :py:attr:`message.mid <MQTTMessage.mid>`).
           only useful in QoS>=1 and ``manual_ack=True`` (option of `Client`)
        r   r   )r>  r  r  r   rm   )rC   r8   r9   s      r5   ackz
Client.ackE  sR    
  	/axx((---))#...--r4   onc                    || _         dS )a  
           The paho library normally acknowledges messages as soon as they are delivered to the caller.
           If manual_ack is turned on, then the caller MUST manually acknowledge every message once
           application processing is complete using `ack()`
        N)r>  )rC   r
  s     r5   manual_ack_setzClient.manual_ack_setR  s     r4   c                `   | j         t          k    r| j        d         dk     rt          j        S n| j        d         dk    rt          j        S t          j        d| j        d         d d                   \  }| j         t          k    r| j        d         dk    rt          t          dz	            }|                    | j        d         dd                     | j        d         dk    rBt          t          dz	            }|                    | j        d         dd                    \  }}| 
                    t          d|           | j        5  || j        v r| j                            |          }|                     |           | xj        dz  c_        | j        d	k    rQ| j        5  |                                 }d d d            n# 1 swxY w Y   |t          j        k    r|cd d d            S d d d            n# 1 swxY w Y   | j        rt          j        S |                     |          S )
Nr)   r   r  r+   rT  rX   zReceived PUBREL (Mid: %d)r   r   )r@  rO  rW  r   ro   r  r  r   r  r   r  r  r~  rg  r  r  ri  rh  r}  _update_inflightrm   r>  r  )rC   r8   r  r  r  r  rl  r   s           r5   r  zClient._handle_pubrel[  s   >V##12Q66$66 7_/0A55 22}T4?8#<RaR#@AA>V##12Q66'!44
!!$/(";ABB"?@@@?#56::!+FaK!8!8J'1'8'81!""5(7 (7$E9~'BCHHH# 	" 	"d''' +//44''000''1,''.220 5 5!22445 5 5 5 5 5 5 5 5 5 5 5 5 5 5];;;!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"&  	+ 11%%c***s7   AG='G<G=G	G=G	G==HHc           
        | j                                         D ]}| j        | j        k     r|j        dk    r|j        t          k    r| xj        dz  c_        |j        dk    rt          |_        n|j        dk    rt          |_        | 	                    |j
        |j                            d          |j        |j        |j        |j        |j                  }|t"          j        k    r|c S t"          j        c S t"          j        S )Nr   r   r   r   r  )rf  r  ri  rh  r9   r  rh  re  rf  rd  r8   r   r   r   r  r	  r  r   rm   )rC   r  r   s      r5   r  zClient._update_inflight  s    #**,, 	6 	6A&)DDD5199N!:!:++q0++uzz"9!"9++w//	#$< ,  B ];;;!			$5555--r4   c                   | j         t          k    r| j        d         dk     rt          j        S n| j        d         dk    rt          j        S t          j        d| j        d         d d                   \  }| j         t          k    r| j        d         dk    rt          t          dz	            }|                    | j        d         dd                     | j        d         dk    rBt          t          dz	            }|                    | j        d         dd                    \  }}| 
                    t          d|           | j        5  || j        v rM| j        |         }t          |_        t!                      |_        |                     |          cd d d            S 	 d d d            n# 1 swxY w Y   t          j        S )Nr)   r   r  r+   rT  rX   zReceived PUBREC (Mid: %d))r@  rO  rW  r   ro   r  r  r   r  r   r  r  r}  rf  r  r  r   r  r  rm   )rC   r8   r  r  r  r  msgs          r5   r  zClient._handle_pubrec  s   >V##12Q66$66 7_/0A55 22}T4?8#<RaR#@AA>V##12Q66'!44
!!$/(";ABB"?@@@?#56::!+FaK!8!8J'1'8'81!""5(7 (7$E9~'BCHHH$ 	. 	.d((((-4	 )((--	. 	. 	. 	. 	. 	. 	. 	.(	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. --s   A
F00F47F4c                D   | j         t          k    r| j        d         dk     rt          j        S n| j        d         dk    rt          j        S t          j        d| j        d         d d                   \  }| j         t          k    rY| j        d         dd          }t          t          dz	            }|                    |          \  }}d ||d          D             }ng }t          t          dz	            }| 	                    t          d|           | j        5  | j        }d d d            n# 1 swxY w Y   |rY| j        5  	 | j        t          j        k    r| j         t          k    rGt#          t$          |          }|}t'          |          dk    r|d	         } || | j        |||           nt#          t*          |          } || | j        |           ni| j        t          j        k    rEt#          t.          |          }|t          t0          j                  } || | j        |||           nt5          d
          n;# t6          $ r.}	| 	                    t8          d|	           | j        s Y d }	~	nd }	~	ww xY wd d d            n# 1 swxY w Y   t          j        S )Nr)   rT  r   r  r+   c                @    g | ]}t          t          d z	  |          S r  )r   r  r  s     r5   r  z+Client._handle_unsuback.<locals>.<listcomp>  s9           8q=Q777     r4   zReceived UNSUBACK (Mid: %d)r   r   r3  z&Caught exception in on_unsubscribe: %s)r@  rO  rW  r   ro   r  r  r   r  r  r  r{  r  ry  rI  r   rJ  r   CallbackOnUnsubscribe_v1_mqtt5r   rA  CallbackOnUnsubscribe_v1_mqtt3rc  CallbackOnUnsubscribe_v2r   r   r   r2  rF  r  rm   )
rC   r8   r+   r  r  r  reasoncodes_listr  r  r  s
             r5   r  zClient._handle_unsuback  sy   >V##12Q66$66 7_/0A55 22}T4?8#<RaR#@AA>V##_X.qrr2F#HM22J)0088E9   	

+     
  "#HM22J~'DcJJJ! 	1 	1!0N	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1  $	( # #"15G5PPP>V33-12PR`-a-aNIYK"#34499.>q.A*N $dnc:{T T T T .22PR`-a-aN*N4EEEE37I7RRR)-.F)W)W%-)3K4G)H)HJ&  N,&    ++MNNN    NN$&NPSU U U3     ?# # # # # # # # # # # # # # #J --sO   D//D36D3JC=IJ
I<$I72J7I<<JJJr  r  r  c                B   | j         5  | j        }d d d            n# 1 swxY w Y   |ru| j        5  	 | j        t          j        k    rw| j        t          k    r?t          t          |          }|r || | j
        ||           n || | j
        |d            nt          t          |          } || | j
        |           n| j        t          j        k    rft          t          |          }t          |          }|t          |          }|t!          t"          j                  } || | j
        |||           nt'          d          n;# t(          $ r.}|                     t,          d|           | j        s Y d }~nd }~ww xY wd d d            d S # 1 swxY w Y   d S d S )N)rc   r3  z%Caught exception in on_disconnect: %s)r{  r  ry  rI  r   rJ  r@  rO  r   CallbackOnDisconnect_v1_mqtt5rA  CallbackOnDisconnect_v1_mqtt3rc  CallbackOnDisconnect_v2rb   r   r   r   r   r   r2  r  rF  r  )rC   r  r  r  r  r  disconnect_flagsr  s           r5   r  zClient._do_on_disconnect  s    ! 	/ 	/ .M	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/  )	( ( ('15G5PPP>V33,01NP],^,^M1 Q -dDNFJ W W W W -dDNE4 P P P P,01NP],^,^M)M$FFFF37I7RRR(,-Dm(T(T+:=O, , ,( ">%QRW%X%XF%-)3K4J)K)KJ%  N,"&    ++MNNN    NN$&MsT T T3     I( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ()	 )	sG     FDE
	F

F$E=8F=FFFFreason_coder   r   c                6   | j         5  | j        }d d d            n# 1 swxY w Y   |r| j        5  	 | j        t          j        k    r(t          t          |          } || | j        |           nN| j        t          j	        k    r*t          t          |          } || | j        |||           nt          d          n;# t          $ r.}|                     t          d|           | j        s Y d }~nd }~ww xY wd d d            n# 1 swxY w Y   | j                            |          }|j                                         |j        dk    rA| xj        dz  c_        | j        dk    r&|                                 }|t0          j        k    r|S t0          j        S )Nr3  r_  r   r   )r{  r  ry  rI  r   rJ  r   rb  rA  rc  rd  r   r2  r  rF  r  rf  r  r<   r   r9   ri  rh  r  r   rm   )rC   r8   r  r  r  r  r  r   s           r5   _do_on_publishzClient._do_on_publish.  sZ   ! 	) 	)J	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)  	(  15G5PPP%)*>
%K%K
"
4====37I7RRR%)*>
%K%K
"
  N'&    ++MNNN    NN$&JCQ Q Q3     %              0  $$S))""$$$7Q;;##q(##*Q..**,,777I--sG     DBB>=D>
C6$C1,D1C66DD	D	r  &Literal['PUBACK'] | Literal['PUBCOMP']c                \   | j         t          k    r| j        d         dk     rt          j        S n| j        d         dk    rt          j        S |dk    rt
          nt          }|j        dz	  }t          j	        d| j        d         d d                   \  }t          |          }t          |          }| j         t          k    ru| j        d         dk    rd|	                    | j        d         dd                     | j        d         dk    r+|	                    | j        d         dd                    \  }}|                     t          d||           | j        5  || j        v r%|                     |||          }	|	cd d d            S 	 d d d            n# 1 swxY w Y   t          j        S )	Nr)   r   re  rT  r  r+   rX   zReceived %s (Mid: %d))r@  rO  rW  r   ro   re  r  r  r  r  r   r   r  r  r}  rf  r  rm   )
rC   r  packet_type_enumr  r8   r  r  r  r  r   s
             r5   r  zClient._handle_pubackcompU  s    >V##12Q66$66 7_/0A55 22%(H__66'&,1}T4?8#<RaR#@AA,,
,,
>V##12Q66!!$/(";ABB"?@@@?#56::'1'8'81!""5(7 (7$E9~'>SIII$ 	 	d(((((j*EE		 	 	 	 	 	 	 	(	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 --s   "FFFrl  re   c           	        	 |j         }n# t          $ r d }Y nw xY wg }| j        5  |,t          | j                            |j                             }t          |          dk    r| j        }nd }d d d            n# 1 swxY w Y   |D ]v}| j        5  	  || | j	        |           nA# t          $ r4}|                     t          d|j        |           | j        s Y d }~nd }~ww xY wd d d            n# 1 swxY w Y   w|rq| j        5  	  || | j	        |           n;# t          $ r.}|                     t          d|           | j        s Y d }~nd }~ww xY wd d d            d S # 1 swxY w Y   d S d S )Nr   z9Caught exception in user defined callback function %s: %sz"Caught exception in on_message: %s)r   r  r{  r  rr  r   r   r  ry  rA  r2  r  rF  r/   r  )rC   rl  r   on_message_callbacksr  rH  r  s          r5   r  zClient._handle_on_messages  s   	MEE! 	 	 	EEE	  "! 	" 	" '+D,E,P,PQXQ^,_,_'`'`$'((A--!_

!
	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" - 	 	H(  
HT4>7;;;;    NN$S )	    3                     	(  JtT^W====    NN$&JCQ Q Q3                      	 	s   
 AA==BBC5B('C5(
C&2*C!C5!C&&C55C9	<C9	
E'DE'
E)$EE'EE''E+.E+c                &   | j         5  | j        }d d d            n# 1 swxY w Y   |rh| j        5  	  || | j                   n3# t          $ r&}|                     t          d|           Y d }~nd }~ww xY wd d d            d S # 1 swxY w Y   d S d S )Nz'Caught exception in on_connect_fail: %s)r{  r  ry  rA  r2  r  rF  )rC   r  r  s      r5   r  zClient._handle_on_connect_fail  s   ! 	3 	3"2O	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3  	V( V VV#OD$.9999  V V VNN$&OQTV V V V V V V VVV V V V V V V V V V V V V V V V V V	V 	VsF     BAB
A4A/*B/A44BBBc                Z    	 |                      d           d | _        d S # d | _        w xY w)NT)r  )r  r  rK   s    r5   r  zClient._thread_main  s<    	 T:::DLLL4DLs   ! 	*c                   t                      }| j        5  | j        | j        | _        n"t	          | j        dz  | j                  | _        || j        z   }d d d            n# 1 swxY w Y   ||z
  }| j        t          j        t          j	        fvrn| j
        sk|dk    rgt          j        t	          |d                     |t                      z
  }| j        t          j        t          j	        fvr| j
        s|dk    _d S d S d S d S d S d S )Nr   r   r   )r   r  r_  r]  minr^  rd  r   rS  rT  r  timesleep)rC   r  target_time	remainings       r5   r  zClient._reconnect_wait  sm   kk( 		6 		6$,(,(A%%(+)A--) )%
  55K		6 		6 		6 		6 		6 		6 		6 		6 		6 		6 		6 		6 		6 		6 		6  #%	{#3#IK[Kp"qqq. rMMJs9a(()))#ikk1I {#3#IK[Kp"qqq. rMMMM rqqqqq!M rqs   AA##A'*A'c                *   d
d}t          | t                    r2 ||                     d          |                     d                    S t          | t          t          f          r+t          |           dk    o || d         | d                   S d	S )Nr@   rP   c                b    t           d uo&| t           j        t           j        t           j        hv o|S rB   )r  HTTPSOCKS4SOCKS5)r  as     r5   checkz%Client._proxy_is_valid.<locals>.check  s4    % H%*elELAAHFGIr4   
proxy_type
proxy_addrr  r   r   Fr   )r   r  getr  r  r   )rz  r3  s     r5   r  zClient._proxy_is_valid  s    	I 	I 	I 	I a 	5|,,aeeL.A.ABBBD%=)) 	q66Q;4551qt#4#445r4   dict[str, Any] | Nonec                   t           d S |                     | j                  r| j        S t          t          j        d          r$t          j                            | j                  st          j                                        }d|v rst          j	        
                    |d                   }|j        dk    rt           j        |j        |j        d}|S |j        dk    rt           j        |j        |j        d}|S t          j                    }|                     |          rd}t#          t%          ||                    S d S )Nproxy_bypassmqtthttp)r4  r5  
proxy_portr  )r4  r5  r<  
proxy_rdnsproxy_usernameproxy_password)r  r  rw  r=  urllibrequestr9  rs  
getproxiesparseurlparseschemer/  hostnamer   r1  get_default_proxyr  zip)rC   env_proxiespartsproxysocks_default
proxy_keyss         r5   
_get_proxyzClient._get_proxy  sA   =4 ,, 	;
 77 	!++DJ77	! .3355K$$--k&.ABB<6))&+j&+n&+j E
 !L\W,,&+l&+n&+j E
 !L /11.. 	8LJJ66777 tr4   c                L   | j         dk    r|                                 }n|                                 }| j        r|                     |          }| j         dk    rH|                    | j                   t          || j        | j	        | j        | j
        | j                  S |S )Nr-  r/  )r   r  r   is_sslr  extra_headers)r?  _create_unix_socket_connection_create_socket_connectionr  _ssl_wrap_socket
settimeoutrE  _WebsocketWrapperrs  rt  r  r  r  s     r5   rG  zClient._create_socket  s    ?f$$6688DD1133D9 	/((..D?l**OODO,,,$ZZy)";    r4   _socket.socketc                    t          j         t           j        t           j                  }|                    | j                   |S rB   )r   r.  r   r   rs  )rC   unix_sockets     r5   rR  z%Client._create_unix_socket_connection  s4    mFNF4FGGDJ'''r4   c                    |                                  }| j        | j        f}| j        | j        f}|rt          j        |f| j        |d|S t          j        || j        |          S )N)r   source_address)	rN  rs  rt  ru  rv  r  create_connectionrF  r   )rC   rK  r6  sources       r5   rS  z Client._create_socket_connection  sx    !!
DJ'$do6 	h*4o9N_eooinooo+D$:O`fggggr4   tcp_sockssl.SSLSocketc                   | j         t          d          | j         }	 | j                             || j        d          }t          | j         dd          rd}n;# t          j        $ r  t          $ r | j                             |d          }Y nw xY w|                    | j	                   |
                                 |r,t          j        |                                | j                   |S )NzGImpossible condition. _ssl_context should never be None if _ssl is TrueF)server_hostnamedo_handshake_on_connectr  )rb  )r  r   r  wrap_socketrs  r  r  CertificateErrorrU  rE  do_handshakematch_hostnamegetpeercert)rC   r^  verify_hostssl_socks       r5   rT  zClient._ssl_wrap_socket"  s1   $Y   ,,	$(44 $
(- 5  H  t(*:EBB $# # 	 	 	 	 	 	(44(- 5  HHH	 	DO,,, 	C x3355tzBBBs   "A 5BB)r!  r   r"  r#  r$  r%  r&  r   r'  r   r(  r)  r*  rP   r+  rP   r@   rI   rT   r  )r  rj   r@   rI   rU   )r  r$   r@   rI   )r@   r)  )r  r  r@   rI   )r@   r   )r@   r   )r  r   r@   rI   )r@   r#  )r  r#  r@   rI   )r@   r  )r@   r  )r  r  r@   rI   )r  r$   r@   r:   )r  r:   r@   r$   )F)r  rP   r@   rI   )r   TN)r"  rj   r$  rP   r&  r   r@   rI   )r;  N)r  rj   r  r  r@   rI   rB   )r  r  r@   rI   )NNNNNNNN)r  r#  r  r#  r  r#  r  r  r  r  r  r#  r  r#  r  r  r@   rI   )r  rP   r@   rI   )r  r   r@   rI   )r  r  r@   rI   )r  rj   r   r$   r  r$   r  rj   r  r$   r  rY   r  r  r@   r   )r  r#  r  r$   r  rj   r  r$   r  rY   r  r  r@   r   )r  rj   r   r$   r  r$   r  rj   r  r$   r  rY   r  r  r@   rI   )r   r8  )r;  r$   r<  r$   r@   rI   )r@   r   )rK  )r   r   r@   r   )Nr   FN)r   rj   r   r^  r9   r$   r  rP   r  r  r@   r   )r  r#  r  r#  r@   rI   r   )NN)rw  rx  r  r  r@   r   )r   NN)
r   r|  r9   r$   r}  r~  r  r  r@   r  )r   r  r  r  r@   r  r   )r  r$   r@   r   )r  r$   r@   rI   )r  r$   r@   rd   )r&  r   r@   rI   )r@   r   )r   rj   r   r^  r9   r$   r  rP   r  r  r@   rI   )r@   r  )rK  F)r   r   r  rP   r@   r   )r@   r   )r@   r  )r  r  r@   rI   )r@   r  )r@   r  )r  r  r@   rI   )r@   r  )r@   r  )r  r  r@   rI   )r@   r  )r@   r  )r  r  r@   rI   )r@   r  )r@   r  )r  r  r@   rI   )r@   r  )r@   r   )r  r   r@   rI   )r@   r  )r@   r
  )r  r
  r@   rI   )r@   r  )r@   r  )r  r  r@   rI   )r@   r  )r@   r  )r  r  r@   rI   )r@   r   )r@   r%  )r  r%  r@   rI   )r@   r)  )r  r>   r@   rI   )r  r  r@   rI   )r   rj   rH  r  r@   rI   )r   rj   r@   r  )r   rj   r@   rI   )r   r   r@   r   )rg  r   rh  rj   ri  r   r@   rI   )r   r:   r@   rI   )r   r:   r@   r   )r8   r$   r@   r   )r+   r*   r)   r$   r@   r*   )r+   r*   r]  r  r@   rI   )r4   r   FFNN)r8   r$   r   r:   r   r   r9   r$   r  rP   r	  rP   r<   r;   r  r  r@   r   )r%   r$   r8   r$   r	  r$   r@   r   )r%   r$   r@   r   )r  r$   r@   r   )r	  r$   r  r  r  r  r@   r  )r	  r$   r  r  r  r  r@   r  )r%   r$   r+   r:   r8   r$   r9   r$   r<   r;   r@   r   )r8   r$   r9   r$   r@   r   )r
  rP   r@   rI   )
r  rP   r  r   r  rx  r  r  r@   rI   )r8   r$   r  r   r  r   r@   r   )r  r   r@   r   )rl  re   r@   rI   )r@   r7  )r@   r>   )r@   rW  )r^  rW  r@   r_  )r/   r0   r1   r`   r   rJ  r  r   r  r  r  r  r   r  r(  r'  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r	  r  r  r  rZ   r   r8  r  r>  r  rN  rM  rm  ro  rr  r  rv  r{  r  r  rV  rX  rQ  rY  r  r  r  r  r  r  r   r  r  r  r!  r  r  rE  r  r  r  r  r  r  r  r  r	  r  r  r  r  r  r$  r'  r.  rH  r2  r6  r  r:  r>  r  rB  rF  r  rJ  rM  rP  r  r  r  r  r  rc  staticmethodrb  r  ro  r  r  r  r  r  rd  r  r  r  r~  rI  rz  r  r  r  r  r  rD  r  rY  r  r  r  r  r  r  r	  r  r  r  r  r  r  r  r  r  r  r  r  r  rN  rG  rR  rS  rT  r3   r4   r5   rd   rd   w  s       c cN 4F3N "%)(0:?%) P) P) P) P) P)d       X 
[   [    X 
[   [    X 	  	  	  	     X            X % % % X% & & & & . . . X. _3 3 3 _3 . . . X. _3 3 3 _3 + + + X+ !	, 	, 	, "!	, ) ) ) X) * * *  * 	0 	0 	0 X	0 " " " X"    X ]   ]- - - -- - - -   	# 	# 	# 	# 	# "	: : : : : +/d d d d d4 *.< < < < <2  $#"+/"&"'++/i( i( i( i( i(V9 9 9 96% % % %@         (C(,*  *  *  *  * \ "(C(,.3 .3 .3 .3 .3f (C(,.= .= .= .= .=`) ) ) ) ):3 :3 :3 :3x# # # # #>F  F  F  F  F V  $(,l( l( l( l( l(^ <@& & & & &,( ( ( ( H H H HA A A A )-(,= = = = =0 +/(,PG PG PG PG PGf GK(E (E (E (E (ET. . . . .25 5 5 56) ) ) ). . . .@. . . .
   " " " "     $(,-+ -+ -+ -+ -+^" " " "    ',L L L L L\. . . .&. . . ." * * * X*    X( ]   ]    $ $ $ X$" ( ( ( (    2  2  2  X2 h $ $ $ $    % % % X%  ) ) ) )    "" "" "" X""H & & & &          X ( $ $ $ $    (  (  (  X( T $ $ $ $    #$ #$ #$ X#$J ( ( ( (    %# %# %# X%#N ' ' ' '    $ $ $ X$$ ( ( ( (       % % % X%$ ) ) ) )       . . . X.$ $2 2 2 %$2      $ 0 0 0 X0(  &4 4 4 '&4    )-    *6 6 6 6:   
 
 
 
    $h h h hTW. W. W. W.r
4 
4 
4 
4$ $ $ $L" " " " ; ; ; \; 2 2 2 \2   3 3 3 3? ? ? ?@ @ @ @   "    $''+(,MC MC MC MC MC^? ? ? ?C C C C; ; ; ;9 9 9 9g9 g9 g9 g9V )-(,$9 $9 $9 $9 $9T )-	(N (N (N (N (N\ )-	/N /N /N /N /Nb' ' ' '- - - -:   , , , , (,%. %. %. %. %.N3 3 3 3>% % % %. . . .l3 l3 l3 l3\
 
 
 
.0 0 0 0dH3 H3 H3 H3T. . . .   (+ (+ (+ (+T. . . .2. . . .6>. >. >. >.H %)(,3 3 3 3 3j%. %. %. %.N. . . .<' ' ' 'T
V 
V 
V 
V       2 2 2 2, 
 
 
 \
) ) ) )V   ,   
h h h h% % % % % %r4   c                      e Zd ZdZdZdZdZdZdZd+dZ	d,dZ
d-dZ	 d.d/dZd0dZd1dZd2d Zd1d!Zd1d"Zd2d#Zd2d$Zd,d%Zd3d&Zd3d'Zd4d)Zd*S )5rV  r   r   r   r  	   
   r   socket.socket | ssl.SSLSocketr  rj   r   r$   rP  rP   r  rQ  r  c                    d| _         || _        || _        || _        || _        || _        t                      | _        t                      | _        d| _	        d| _
        d| _        |                     |           d S r   )	connectedr  rs  rt  _socket_pathr*   _sendbuffer_readbuffer_requested_size_payload_head_readbuffer_head_do_handshake)rC   r   r  r   rP  r  rQ  s          r5   r   z_WebsocketWrapper.__init__Q  sx     	


$;;$;;  !=)))))r4   r@   rI   c                R    t                      | _        t                      | _        d S rB   )r*   rt  ru  rK   s    r5   r  z_WebsocketWrapper.__del__k  s     $;;$;;r4   c                L   t          j                    j        }t          j        |          }| j        rd}d}nd}d}|| j        k    r	| j         }n| j         d| j         }|dd| d| |                    d	          d
dd}t          |t                    r|                    |           nt          |          r ||          }d                    d| j         dd                    d |                                D                       dg                              d	          }| j                            |           d}d}		 	 | j                            d          }
n# t(          $ r d}
Y nw xY w| j                            |
           |
dk    rt/          | j                  dk    rdt1          | j                                                                      d          v rLdt1          | j                                                                      d          vrt5          d          d}	dt1          | j                                                                      d          v rd}| j                            d                              dd          d         }|                                                    d          }|                    d          |z   }t;          j        |                    d                    }t          j        |                                          }||k    rt5          d          d}nn'tA                      | _        n|
st5          d          ,|	r|st5          d          tA                      | _        d| _!        d S ) Ni  httpsP   r;  :	websocketUpgradez://r6  13r:  )Hostr  
ConnectionOriginzSec-WebSocket-KeyzSec-Websocket-VersionzSec-Websocket-Protocolz
zGET z	 HTTP/1.1c              3  *   K   | ]\  }}| d | V  dS ): Nr3   )r   ijs      r5   r   z2_WebsocketWrapper._do_handshake.<locals>.<genexpr>  s0      JJ11JJJJJJr4   FTr   r4      
r   s
   connectionr   s   upgradez2WebSocket handshake error, connection not upgradeds   sec-websocket-acceptz$258EAFA5-E914-47DA-95CA-C5AB0DC85B11r  z-WebSocket handshake error, invalid secret keyzWebSocket handshake error)"rR  rS  r:   base64	b64encoder  rt  rs  r  r   r  updater  r   rs  itemsr   rr  rH   rD   ConnectionResetErrorru  r   r   rj   r<  rg   r|  striphashlibsha1digestr*   rq  )rC   rQ  sec_websocket_keydefault_porthttp_schema	host_portwebsocket_headersr  
has_secrethas_upgraderZ  GUIDserver_hash_strserver_hashclient_hash_keyclient_hash_digestclient_hashs                    r5   ry  z_WebsocketWrapper._do_handshakeo  s    JLL.",->??9 	!L!KKL K4:%%:II:44
44I "#$4444!2!9!9&!A!A%)&,
 
 mT** 	A$$]3333m$$ 	A -.? @ @(4:(((KKJJ0A0G0G0I0IJJJJJ
   6&>>	 	 	&!!!
/	L|((++'    ##D))) u}}t'((1,,$D,<(=(=(C(C(E(E(L(LW(U(UUU%S1A-B-B-H-H-J-J-Q-QRY-Z-ZZZ": T#V #V V +/K /#d6F2G2G2M2M2O2O2V2VW^2_2___E*.*:*A*A#+% +%%*U4^^A+7&5&;&;&=&=&D&DW&M&M*;*B*B7*K*Kd*R-4\/:P:PQX:Y:Y-Z-Z*&,&67I7P7P7R7R&S&S&+55": O#Q #Q Q *.J  $-;;    L./JKKK_/	Lb  	H* 	H*+FGGG$;;s   E' 'E65E6opcoder]  r*   
do_maskingc                r   t                      }t          |          }t          t          j        d                    }|}|                    d|z             |dk     r|                    |dz  |z             n|dk     r4|                    |dz  dz             |t          j        d|          z  }nI|dk     r4|                    |dz  dz             |t          j        d	|          z  }nt          d
          |dk    r0t          |          D ]}||xx         ||dz           z  cc<   ||z   }||z   S )NrT  rV  ~   r  rs  r  l           rU  !QzMaximum payload size is 2^63r   )	r*   r   osurandomr   r  r  r   r   )	rC   r  r]  r  r  lengthmask_key	mask_flagr   s	            r5   _create_framez_WebsocketWrapper._create_frame  sO    TRZ]]++	 	fvo&&&C<<MM)q.612222e^^MM)q.3.///fk$///FF(((MM)q.3.///fk$///FF ;<<<>>v 3 3Ux	22d?D}r4   r  c                R   |t          | j                  | j        z
  z
  }|dk    rW| j                            |          }|st
          | j                            |           t          |          |k     rt          | xj        |z  c_        | j        | j        |z
  | j                 S r   )r   ru  rx  rr  rD   ConnectionAbortedErrorr   r   )rC   r  wanted_bytesr]  s       r5   _buffered_readz _WebsocketWrapper._buffered_read  s     T%5!6!69N!NO!<$$\22D .,, ''---4yy<''%%' 5 >t?T TUUr4   r:   c                   	 d| _         d}| j        }| j        |z   }|                     d          }|                     d          }|d         dz  }|d         dz  dk    }|d         dz  }	|	}
d }|	dk    r-|                     d          }t          j        d	|          \  }
n2|	dk    r,|                     d
          }t          j        d|          \  }
|r|                     d          }|}|
|k     r|
}|dk    rU|                     |          }|,t          ||          D ]}||xx         ||dz           z  cc<   |||         }|| _        nt                      }||
k    rt                      | _        d| _        |t          j	        k    r;| 
                    t          j	        |d          }| j                            |           |t          j        k    r;| 
                    t          j        |d          }| j                            |           |t          j        k    s|t          j        k    r|
dk    r|S t"          # t$          $ r d| _        Y dS w xY w)Nr   r4   r      rV  rU  r  r   r  r  r  rT  F)rx  rw  r  r  r  r   r*   ru  rV  OPCODE_CONNCLOSEr  rr  rH   OPCODE_PINGOPCODE_PONGOPCODE_BINARYOPCODE_CONTINUATIONr   r  rq  )rC   r  r  chunk_startindexchunk_endindexheader1header2r  maskbit
lengthbitspayload_lengthr  r  	readindexr   r   frames                    r5   
_recv_implz_WebsocketWrapper._recv_impl  s   N	$%D!F#1!/&8N))!,,G))!,,Gaj4'FqzD(T1G!!*t+J'NH T!!++A.."(-e"<"<t##++A.."(-e"<"<  2..q11 'I	))*	1}}--i88 '!&'7!C!C > >(519*== !1)!;<%.""#++ N**#,;; %&" .??? ..):GQH HEL%%e,,,.::: ..)5wC CEL%%e,,, +999VGXGl=l=l&**%% 	 	 	"DN33	s   H9I <I IIc                   t          | j                  dk    r[|                     t          j        t          |                    }| j                            |           t          |          | _        | j        	                    | j                  }| j        |d          | _        t          | j                  dk    r| j        S dS r   )
r   rt  r  rV  r  r*   r   rv  rr  rH   )rC   r]  r  r  s       r5   
_send_implz_WebsocketWrapper._send_implZ  s     t  A%%&&!/4B BE##E***#&t99D  ""4#344+FGG4t  A%%'' 1r4   c                ,    |                      |          S rB   r  rC   r  s     r5   rD   z_WebsocketWrapper.recvp      v&&&r4   c                ,    |                      |          S rB   r  r  s     r5   readz_WebsocketWrapper.reads  r  r4   c                ,    |                      |          S rB   r  rC   r]  s     r5   rH   z_WebsocketWrapper.sendv      t$$$r4   c                ,    |                      |          S rB   r  r  s     r5   writez_WebsocketWrapper.writey  r  r4   c                8    | j                                          d S rB   )rr  rL   rK   s    r5   rL   z_WebsocketWrapper.close|  s    r4   c                4    | j                                         S rB   )rr  rN   rK   s    r5   rN   z_WebsocketWrapper.fileno  s    |""$$$r4   c                F    | j         r| j                                        S dS r   )r  rr  rP  rK   s    r5   rP  z_WebsocketWrapper.pending  s)     9 	<''))) 1r4   rO   c                :    | j                             |           d S rB   )rr  rS   rR   s     r5   rS   z_WebsocketWrapper.setblocking  s      &&&&&r4   N)r   ro  r  rj   r   r$   rP  rP   r  rj   rQ  r  rT   )rQ  r  r@   rI   rj  )r  r$   r]  r*   r  r$   r@   r*   )r  r$   r@   r*   )r  r$   r@   r:   )r]  r:   r@   r$   rU   rV   )r/   r0   r1   r  OPCODE_TEXTr  r  r  r  r   r  ry  r  r  r  r  rD   r  rH   r  rL   rN   rP  rS   r3   r4   r5   rV  rV  I  sz       KMKK* * * *4' ' ' 'b b b bJ ?@    BV V V V&Q Q Q Qf   ,' ' ' '' ' ' '% % % %% % % %   % % % %   ' ' ' ' ' 'r4   rV  )rh   ri   r@   rj   )r   r   r@   rj   )r   r   r@   r   )r   r   r@   r   )r   r$   r   rj   r   r$   r@   rj   )r   rj   r   rj   r@   rP   )r@   r   )r   r   r@   r:   )r   r   r@   r   )r`   
__future__r   r  rX  errnor  r  r  platformrR  r   stringr  r   r)  urllib.parser@  urllib.requestrR  rK  typingr   r   r   r   r   r	   r
   r   r   r   r   paho.mqtt.packettypesr   enumsr   r   r   r   r   r   r   r   r   r   r   r  r   r  r   r   subscribeoptionsr   r   ImportErrortyping_extensionsr    r!   r#   r7   r>   r  r  	monotonicr   r  dns.resolverr&  r#  systemWSAEWOULDBLOCKEAGAINr   r  r   rB  re  r  r  r  r  r  r  r  r  r  r   AUTHMQTT_LOG_INFOMQTT_LOG_NOTICEMQTT_LOG_WARNINGrF  r  DEBUGINFOWARNINGERRORrk  r   r   r   r   r   r   MQTT_MS_INVALIDr  MQTT_MS_PUBLISHrg  MQTT_MS_WAIT_FOR_PUBACKre  MQTT_MS_WAIT_FOR_PUBRECrf  MQTT_MS_RESEND_PUBRELr  MQTT_MS_WAIT_FOR_PUBRELr  MQTT_MS_RESEND_PUBCOMPmqtt_ms_resend_pubcompMQTT_MS_WAIT_FOR_PUBCOMPr  MQTT_MS_SEND_PUBRECmqtt_ms_send_pubrecMQTT_MS_QUEUEDrh  r   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   rQ  r  rO  rG  rq  rZ   r2   r  rj   r:   r*   r$   r   r^  
HTTPHeaderWebSocketHeadersrP   rY   r]   rb   r  r  CallbackOnConnect_v1r  r  r  r  r  CallbackOnDisconnect_v1r  r"  r  r  r  rb  rd  r  r+  r  r  CallbackOnSubscribe_v1r  r  r  r  CallbackOnUnsubscribe_v1r  r  rr  r  rg   r~   r   r   r   r   ascii_lettersr   r   r   r   r   r   re   rd   rV  r3   r4   r5   <module>r     sK     # " " " " "         				                     o o o o o o o o o o o o o o o o o o o o o o o o o o - - - - - - ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^             " " " " " " 0 0 0 0 0 0 0 0 . . . . . .* * * *))))))))*  )0$$$$$$$ 0 0 0////////0/####### / / /......../    I   % % % % %Y % % %
 
 
 
 
X 
 
 
JJJJ   
CCCLLLL   EEEII   	IIIHH   HHH 8?	!!!FF\F  




						

!			%

#
 &*, $(W]GLglw7= / #.#O  &1&U #%0%S "(3(Y %!,!K  ..&> &> $: &> %< '@ "6 ,- 1 -!3 - 1 %; "5 "5 )%; &= +#7  1 -#7 "5 

%'		#(( 12  1 1 1 1 C	3t;<#s(^
:,
":;ZGH wqz)* 
 
 
 
 
: 
 
 
	 	 	 	 	j 	 	 	 &xd38nm&TVZ&Z[ %xd38njRWXbdhXhRi&jlp&pq 79SST 3j%PZ\`P`Ja bdh hi .0DDE  (C$!67  ((C)G)M N  ((Cz3PT?T9UW\]gim]mWn)oqu)u v  =?\ \] "Hc?JPUV`bfVfPg#hjn#no 46MMN (Cc2D89h];TAB 3 56 3 4d :; 3Z Ld RS .0DDE XsL94?@ '3U38_(Mt(ST '3T*=Mz(Z\`(`a ;=YYZ !8S#tJ7Gz[_O_I`"acg"gh 24JJK !)8S#*>*D!E !)8S#z5Q[]abl]mQmKn*oqu*u!v  !?A_!_` #XsCj9I5Q[]aQaKb$cei$ij 68PPQ  	 	 	 	 	 	 	 	%  %  %  % P5 5 5 5*@ @ @ @>C C C C4  44% % % % %    "   ,      $`# `# `# `# `# `# `# `#F+ + + + + + + +\P? P? P? P? P? P? P? P?d~C' C' C' C' C' C' C' C' C' C's~   B& &B43B4:C CCC C('C(D D%$D%)D. .D87D8<E EEE E('E(