
    	h8-                       d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	m
Z
mZ ddlmZmZ ddlmZ ddlmZ d	d
lmZ ddlmZ er	 ddlmZmZmZ n# e$ r ddlmZmZmZ Y nw xY w	 ddlmZ n# e$ r	 ddlmZ Y nw xY w G d ded          Z G d ded          Z G d ded          Ze
e ej!        e"e#f         Z$e	eee$f                  Z%dFdZ&dGdZ'dHd&Z(d'd(d)d*dddej)        d+df
dId>Z*dddd'd(d)d*dddej)        d+dfdJdEZ+dS )Ka  
This module provides some helper functions to allow straightforward publishing
of messages in a one-shot manner. In other words, they are useful for the
situation where you have a single/multiple messages you want to publish to a
broker, then disconnect and nothing else is required.
    )annotationsN)Iterable)TYPE_CHECKINGAnyListTupleUnion)CallbackAPIVersionMQTTProtocolVersion)
Properties)
ReasonCode   )mqtt   )client)NotRequiredRequired	TypedDict)Literalc                  $    e Zd ZU ded<   ded<   dS )AuthParameterRequired[str]usernameNotRequired[str]passwordN__name__
__module____qualname____annotations__     ^/var/www/html/web-builder-api.evdpl.com/venv/lib/python3.11/site-packages/paho/mqtt/publish.pyr   r   /   s*         """"""r"   r   F)totalc                  L    e Zd ZU ded<   ded<   ded<   ded<   ded<   d	ed
<   dS )TLSParameterr   ca_certsr   certfilekeyfileNotRequired[int]tls_versionciphersNotRequired[bool]insecureNr   r!   r"   r#   r&   r&   4   sZ         """"!!!!%%%%!!!!######r"   r&   c                  8    e Zd ZU ded<   ded<   ded<   ded<   d	S )
MessageDictr   topiczNotRequired[paho.PayloadType]payloadr*   qosr-   retainNr   r!   r"   r#   r0   r0   =   sB         ....!!!!!!r"   r0   r   paho.Clientc                    | j                                         }t          |t                    r | j        di | dS t          |t
          t          f          r | j        |  dS t          d          )zInternal functionz&message must be a dict, tuple, or listNr!   )	_userdatapopleft
isinstancedictpublishtuplelist	TypeError)r   messages     r#   _do_publishr@   H   s     &&((G'4   B!!!!!!!	GeT]	+	+ B    @AAAr"   userdataMessagesListc                    |dk    r&t          |          dk    rt          |            dS dS t          j        t	          j        |                    )zInternal v5 callbackr   N)lenr@   r   MQTTExceptionpahoconnack_string)r   rA   flagsreason_code
propertiess        r#   _on_connectrK   U   sX    ax==1   !4[!A!ABBBr"   collections.deque[MessagesList]midintreason_codesr   rJ   r   returnNonec                v    t          |          dk    r|                                  dS t          |            dS )zInternal callbackr   N)rD   
disconnectr@   )r   rA   rM   rO   rJ   s        r#   _on_publishrT   ^   sA     8}}Fr"   	localhosti[   <   tcpmsgshostnamestrport	client_id	keepalivewillMessageDict | NoneauthAuthParameter | NonetlsTLSParameter | Noneprotocolr   	transportLiteral['tcp', 'websockets']
proxy_args
Any | Nonec                \   t          | t                    st          d          t          |           dk    rt	          d          t          j        t          j        |t          j
        |           ||	          }|                                 t          |_        t          |_        |
 |j        di |
 |rR|                    d          }|r,|                    d          }|                    ||           nt'          d          | |j        di | |et          |t*                    r;|                    d	d
          } |j        di | |r|                    |           n|                    |           |                    |||           |                                 dS )a  Publish multiple messages to a broker, then disconnect cleanly.

    This function creates an MQTT client, connects to a broker and publishes a
    list of messages. Once the messages have been delivered, it disconnects
    cleanly from the broker.

    :param msgs: a list of messages to publish. Each message is either a dict or a
           tuple.

           If a dict, only the topic must be present. Default values will be
           used for any missing arguments. The dict must be of the form:

           msg = {'topic':"<topic>", 'payload':"<payload>", 'qos':<qos>,
           'retain':<retain>}
           topic must be present and may not be empty.
           If payload is "", None or not present then a zero length payload
           will be published.
           If qos is not present, the default of 0 is used.
           If retain is not present, the default of False is used.

           If a tuple, then it must be of the form:
           ("<topic>", "<payload>", qos, retain)

    :param str hostname: the address of the broker to connect to.
               Defaults to localhost.

    :param int port: the port to connect to the broker on. Defaults to 1883.

    :param str client_id: the MQTT client id to use. If "" or None, the Paho library will
                generate a client id automatically.

    :param int keepalive: the keepalive timeout value for the client. Defaults to 60
                seconds.

    :param will: a dict containing will parameters for the client: will = {'topic':
           "<topic>", 'payload':"<payload">, 'qos':<qos>, 'retain':<retain>}.
           Topic is required, all other parameters are optional and will
           default to None, 0 and False respectively.
           Defaults to None, which indicates no will should be used.

    :param auth: a dict containing authentication parameters for the client:
           auth = {'username':"<username>", 'password':"<password>"}
           Username is required, password is optional and will default to None
           if not provided.
           Defaults to None, which indicates no authentication is to be used.

    :param tls: a dict containing TLS configuration parameters for the client:
          dict = {'ca_certs':"<ca_certs>", 'certfile':"<certfile>",
          'keyfile':"<keyfile>", 'tls_version':"<tls_version>",
          'ciphers':"<ciphers">, 'insecure':"<bool>"}
          ca_certs is required, all other parameters are optional and will
          default to None if not provided, which results in the client using
          the default behaviour - see the paho.mqtt.client documentation.
          Alternatively, tls input can be an SSLContext object, which will be
          processed using the tls_set_context method.
          Defaults to None, which indicates that TLS should not be used.

    :param str transport: set to "tcp" to use the default setting of transport which is
          raw TCP. Set to "websockets" to use WebSockets as the transport.

    :param proxy_args: a dictionary that will be given to the client.
    zmsgs must be an iterabler   zmsgs is empty)r]   rA   re   rf   Nr   r   z;The 'username' key was not found, this is required for authr.   Fr!   )r9   r   r>   rD   
ValueErrorrF   Clientr
   VERSION2collectionsdequeenable_loggerrT   
on_publishrK   
on_connect	proxy_setgetusername_pw_setKeyErrorwill_setr:   poptls_settls_insecure_settls_set_contextconnectloop_forever)rY   rZ   r\   r]   r^   r_   ra   rc   re   rf   rh   r   r   r   r.   s                  r#   multipler~   j   s   X dH%% 42333
4yyA~~)))[#"4((  F #F#F&&:&&& 088J'' 	0xx
++H""8X6666 / 0 0 0 $
c4   
	(wwz511HFN!!S!!! 2 ''111 ""3'''
NN8T9---
r"   r1   r2   paho.PayloadTyper3   r4   boolc                H    | |||d}t          |g||||||	|
|||           dS )a
  Publish a single message to a broker, then disconnect cleanly.

    This function creates an MQTT client, connects to a broker and publishes a
    single message. Once the message has been delivered, it disconnects cleanly
    from the broker.

    :param str topic: the only required argument must be the topic string to which the
            payload will be published.

    :param payload: the payload to be published. If "" or None, a zero length payload
              will be published.

    :param int qos: the qos to use when publishing,  default to 0.

    :param bool retain: set the message to be retained (True) or not (False).

    :param str hostname: the address of the broker to connect to.
               Defaults to localhost.

    :param int port: the port to connect to the broker on. Defaults to 1883.

    :param str client_id: the MQTT client id to use. If "" or None, the Paho library will
                generate a client id automatically.

    :param int keepalive: the keepalive timeout value for the client. Defaults to 60
                seconds.

    :param will: a dict containing will parameters for the client: will = {'topic':
           "<topic>", 'payload':"<payload">, 'qos':<qos>, 'retain':<retain>}.
           Topic is required, all other parameters are optional and will
           default to None, 0 and False respectively.
           Defaults to None, which indicates no will should be used.

    :param auth: a dict containing authentication parameters for the client:
           Username is required, password is optional and will default to None
           auth = {'username':"<username>", 'password':"<password>"}
           if not provided.
           Defaults to None, which indicates no authentication is to be used.

    :param tls: a dict containing TLS configuration parameters for the client:
          dict = {'ca_certs':"<ca_certs>", 'certfile':"<certfile>",
          'keyfile':"<keyfile>", 'tls_version':"<tls_version>",
          'ciphers':"<ciphers">, 'insecure':"<bool>"}
          ca_certs is required, all other parameters are optional and will
          default to None if not provided, which results in the client using
          the default behaviour - see the paho.mqtt.client documentation.
          Defaults to None, which indicates that TLS should not be used.
          Alternatively, tls input can be an SSLContext object, which will be
          processed using the tls_set_context method.

    :param transport: set to "tcp" to use the default setting of transport which is
          raw TCP. Set to "websockets" to use WebSockets as the transport.

    :param proxy_args: a dictionary that will be given to the client.
    )r1   r2   r3   r4   N)r~   )r1   r2   r3   r4   rZ   r\   r]   r^   r_   ra   rc   re   rf   rh   msgs                  r#   singler      sK    P !&fUUCcUHdIy$cy*. . . . .r"   )r   r5   )r   r5   rA   rB   )r   r5   rA   rL   rM   rN   rO   r   rJ   r   rP   rQ   )rY   rB   rZ   r[   r\   rN   r]   r[   r^   rN   r_   r`   ra   rb   rc   rd   re   r   rf   rg   rh   ri   rP   rQ   )r1   r[   r2   r   r3   rN   r4   r   rZ   r[   r\   rN   r]   r[   r^   rN   r_   r`   ra   rb   rc   rd   re   r   rf   rg   rh   ri   rP   rQ   ),__doc__
__future__r   rn   collections.abcr   typingr   r   r   r   r	   paho.mqtt.enumsr
   r   paho.mqtt.propertiesr   paho.mqtt.reasoncodesr   rV   r   r   rF   r   r   r   ImportErrortyping_extensionsr   r   r&   r0   r[   PayloadTyperN   r   MessageTuplerB   r@   rK   rT   MQTTv311r~   r   r!   r"   r#   <module>r      s#    # " " " " "     $ $ $ $ $ $ 9 9 9 9 9 9 9 9 9 9 9 9 9 9 C C C C C C C C + + + + + + , , , , , ,             #:G;;;;;;;;;;; G G GFFFFFFFFFFFFG.""""""" . . .--------.
# # # # #	 # # # #
$ $ $ $ $y $ $ $ $" " " " "iu " " " " d.T9:Lk<789L
B 
B 
B 
BC C C C	 	 	 	  #!%#$(M.3!z z z z z~ !%#!%#$(M.3!K. K. K. K. K. K. K.s$   
A A! A!%A, ,A:9A: