
    	hC                         d dl Z ddlmZ  G d de          Z G d de          Zd Zd	 Zd
 Zd Z	d Z
d Zd Zd Z G d d          Z G d d          ZdS )    N   )PacketTypesc                       e Zd ZdS )MQTTExceptionN__name__
__module____qualname__     a/var/www/html/web-builder-api.evdpl.com/venv/lib/python3.11/site-packages/paho/mqtt/properties.pyr   r              Dr   r   c                       e Zd ZdS )MalformedPacketNr   r   r   r   r   r      r   r   r   c                 F    t          t          j        d|                     S )N!H	bytearraystructpacklengths    r   
writeInt16r          V[v..///r   c                 H    t          j        d| d d                   d         S )Nr      r   r   unpackbufs    r   	readInt16r!   #   !    =s2A2w''**r   c                 F    t          t          j        d|                     S )N!Lr   r   s    r   
writeInt32r%   (   r   r   c                 H    t          j        d| d d                   d         S )Nr$      r   r   r   s    r   	readInt32r(   -   r"   r   c                     t          | t                    st          | d          } t          t          |                     | z   S )Nutf-8)
isinstancebytesr   len)datas    r   writeUTFr/   2   s<    dE"" $T7##c$ii  4''r   c                    |dk    rt          |           }nt          d          |dz  }||k    rt          d          | dd|z                                d          }|D ]V}t          |          }|dk    r|dk    rt          d          |dk    rt          d	          |d
k    rt          d          W||dz   fS )Nr   z%Not enough data to read string lengthz Length delimited string too longr*   i   i  z,[MQTT-1.5.4-1] D800-DFFF found in UTF-8 datar   z'[MQTT-1.5.4-2] Null found in UTF-8 datai  z#[MQTT-1.5.4-3] U+FEFF in UTF-8 data)r!   r   decodeord)buffermaxlenr   r    cord_cs         r   readUTFr7   9   s    {{6""EFFF
aKF@AAA
1V8

#
#G
,
,C I IAF??u!"PQQQD==!"KLLLF??!"GHHH q=r   c                 @    t          t          |                     | z   S N)r   r-   )r3   s    r   
writeBytesr:   N   s    c&kk""V++r   c                 D    t          |           }| dd|z            |dz   fS )Nr   )r!   )r3   r   s     r   	readBytesr<   R   s+    vF!AfH*vax''r   c                   >    e Zd ZdZed             Zed             ZdS )VariableByteIntegerszh
    MQTT variable byte integer helper class.  Used
    in several places in MQTT v5.0 properties.

    c                     d| cxk    rdk    sn t          d| d          d}	 | dz  }| dz  } | dk    r|dz  }|t          |g          z  }| dk    rn0|S )z
          Convert an integer 0 <= x <= 268435455 into multi-byte format.
          Returns the buffer converted from the integer.
        r   zValue z must be in range 0-268435455r   r      )
ValueErrorr,   )xr3   digits      r   encodezVariableByteIntegers.encode^   s     A""""""""HaHHHIII	GE#IA1uueUGnn$FAvv	 r   c                 |    d}d}d}	 |dz  }| d         }| dd         } ||dz  |z  z  }|dz  dk    rn|dz  }2||fS )z
          Get the value of a multi-byte integer from a buffer
          Return the value, and the number of bytes used.

          [MQTT-1.5.5-1] the encoded value MUST use the minimum number of bytes necessary to represent the value
        r   r   N   rA   r   )r3   
multipliervaluer,   rD   s        r   r1   zVariableByteIntegers.decodeq   sw     
	QJE1IEABBZFeckZ//Es{a#J	 u~r   N)r   r	   r
   __doc__staticmethodrE   r1   r   r   r   r>   r>   W   sT            \$   \  r   r>   c                   `    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd ZdS )
Propertiesab  MQTT v5.0 properties class.

    See Properties.names for a list of accepted property names along with their numeric values.

    See Properties.properties for the data type of each property.

    Example of use::

        publish_properties = Properties(PacketTypes.PUBLISH)
        publish_properties.UserProperty = ("a", "2")
        publish_properties.UserProperty = ("c", "3")

    First the object is created with packet type as argument, no properties will be present at
    this point. Then properties are added as attributes, the name of which is the string property
    name without the spaces.

    c                 >   || _         g d| _        i dddddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.
| _        i d| j                            d/          t          j        t          j        gfd| j                            d0          t          j        t          j        gfd| j                            d1          t          j        t          j        gfd	| j                            d1          t          j        t          j        gfd| j                            d2          t          j        t          j        gfd| j                            d3          t          j        t          j        gfd| j                            d0          t          j        t          j	        t          j
        gfd| j                            d1          t          j	        gfd| j                            d4          t          j	        gfd| j                            d1          t          j        t          j	        t          j        gfd| j                            d2          t          j        t          j	        t          j        gfd| j                            d/          t          j        gfd| j                            d0          t          j        gfd| j                            d/          t          j        gfd| j                            d1          t          j	        gfd!| j                            d1          t          j	        t          j
        gfd#| j                            d1          t          j	        t          j        t          j        t          j        t          j        t          j        t          j        t          j
        t          j        g	f| j                            d4          t          j        t          j	        gf| j                            d4          t          j        t          j	        gf| j                            d4          t          j        gf| j                            d/          t          j	        gf| j                            d/          t          j	        gf| j                            d5          t          j        t          j	        t          j        t          j        t          j        t          j        t          j        t          j        t          j        t          j        t          j        t          j
        t          j        t          j        gf| j                            d0          t          j        t          j	        gf| j                            d/          t          j	        gf| j                            d/          t          j	        gf| j                            d/          t          j	        gfd6
| _        d S )7N)ByteTwo Byte IntegerFour Byte IntegerVariable Byte IntegerBinary DataUTF-8 Encoded StringUTF-8 String PairzPayload Format Indicatorr   zMessage Expiry Intervalr   zContent Type   zResponse Topic   zCorrelation Data	   zSubscription Identifier   zSession Expiry Interval   zAssigned Client Identifier   zServer Keep Alive   zAuthentication Method   zAuthentication Data   zRequest Problem Information   zWill Delay Interval   zRequest Response Information   zResponse Information   zServer Reference   zReason String   !   "   #   $   %   &   '   (   )   *   )
zReceive MaximumzTopic Alias MaximumzTopic AliaszMaximum QoSzRetain AvailablezUser PropertyzMaximum Packet SizezWildcard Subscription Availablez!Subscription Identifier AvailablezShared Subscription AvailablerO   rQ   rT   rS   rR   rP   rU   )
re   rf   rg   rh   ri   rj   rk   rl   rm   rn   )
packetTypetypesnamesindexr   PUBLISHWILLMESSAGE	SUBSCRIBECONNECTCONNACK
DISCONNECTAUTHPUBACKPUBRECPUBRELPUBCOMPSUBACKUNSUBACKUNSUBSCRIBE
properties)selfro   s     r   __init__zProperties.__init__   s   $R R R

&
%q
 A
 a	

 
 &r
 &r
 )"
  
 $R
 "2
 *2
 "2
 +B
 #B
  !
" R#
$  "#% "#%/113-/7
 
 

<0
 
  ((;+>@W*XY0
 
  !4558K[Md7ef	0

 
  !788;;NP[Pg:hi0
 
  !788;;NP[Pg:hi0
 
  //+2E{G^1_`0
 !!"9::%{'<=?0
 !!"566%{':K<RSU0
 !!"899K<O;PQ0
 !!"4558K7LM0
 !!"899%{':K<LMO0
  !!-00%{':K<LMO!0
$ !!&))%&(%0
( !!"5669P8QR)0
* !!&))K,?+@A+0
, !!"899K<O;PQ-0
. !!"899%{'=>@/0
2 !!"899%{'9;;M$k&9;;M&(>@PRS30
: !!"455%{':;=!!"455%{':;=!!"4558K7LM!!&))K,?+@A!!&))K,?+@A!!"566%{':%{'9$k&8+:M'););+?(+*:K<SUV !!"566%{':;=!!&))K,?+@A!!&))K,?+@A!!&))K,?+@A_0
 0
 0
r   c                 0    |                      |          dv S )N)rY   rj   )getIdentFromName)r   compressedNames     r   allowsMultiplezProperties.allowsMultiple   s    $$^44@@r   c                     d}| j                                         D ]+}||                    dd          k    r| j         |         } n,|S )N  )rq   keysreplace)r   r   resultnames       r   r   zProperties.getIdentFromName   sX    JOO%% 	 	Dc2!6!666D) 7 r   c                    |                     dd          }g d}||v rt                              | ||           d S |d | j                                        D             vr)t          d| j                                                   | j        | j        |                     |                   d         vr*t          d| dt          j
        | j                            t          |t                    s|d	v r|dk     s|d
k    rt          | d          |dv r|dk     s|d
k    rt          | d          |dv r|dk     s|dk    rt          | d          |dv r|dk    r|dk    rt          | d          |                     |          rFt          |t                    s|g}t          | |          rt                              | |          |z   }t                              | ||           d S )Nr   r   )ro   rp   rq   r   c                 :    g | ]}|                     d d          S )r   r   )r   ).0anames     r   
<listcomp>z*Properties.__setattr__.<locals>.<listcomp>  s&    RRRuEMM#r22RRRr   zProperty name must be one of r   z	Property z does not apply to packet type )ReceiveMaximum
TopicAliasi  z, property value must be in the range 1-65535)TopicAliasMaximumr   z, property value must be in the range 0-65535)MaximumPacketSizeSubscriptionIdentifierr@   z0 property value must be in the range 1-268435455)RequestResponseInformationRequestProblemInformationPayloadFormatIndicatorz property value must be 0 or 1)r   object__setattr__rq   r   r   ro   r   r   r   Namesr+   listr   hasattr__getattribute__)r   r   rI   privateVarss       r   r   zProperties.__setattr__   sa   ||C$$DDD;tT511111 RR
@Q@QRRRRR#GDJOO4E4EGGI I I dod6K6KD6Q6Q&RST&UUU#$y$y$yU`UfgkgvUw$y$yzzz eT** A;;;"QYY%%--'4(](](]^^^222"QYY%%--'4(](](]^^^LLL"QYY%)*;*;'4(a(a(abbbrrr"aZZEQJJ'???A A A ""4(( H!%.. $"GE4&& H"33D$??%GEtT511111r   c                     d}d}| j                                         D ]I}|                    dd          }t          | |          r!|s|dz  }|| dt	          | |           z  }d}J|dz  }|S )	N[Tr   r   z, z : F])rq   r   r   r   getattr)r   r3   firstr   r   s        r   __str__zProperties.__str__$  s    JOO%% 	 	D!\\#r22Nt^,,  #dNF^OOn0M0MOOO#r   c                    i }| j                                         D ]p}|                    dd          }t          | |          rHt	          | |          }|dk    r-t          |t                    r|                                ||<   k|||<   q|S )Nr   r   CorrelationData)rq   r   r   r   r   r+   r,   hex)r   r.   r   r   vals        r   jsonzProperties.json1  s    JOO%% 	/ 	/D!\\#r22Nt^,, /dN33!%666:c5;Q;Q6+.7799D((+.D(r   c                     d}| j                                         D ],}|                    dd          }t          | |          rd} n-|S )NTr   r   F)rq   r   r   r   )r   rcr   r   s       r   isEmptyzProperties.isEmpty=  s]    JOO%% 	 	D!\\#r22Nt^,,  	r   c                     | j                                         D ]8}|                    dd          }t          | |          rt	          | |           9d S )Nr   r   )rq   r   r   r   delattr)r   r   r   s      r   clearzProperties.clearF  s]    JOO%% 	. 	.D!\\#r22Nt^,, .n---	. 	.r   c                 D   d}|t                               |          z  }|| j                            d          k    r|t	          |g          z  }nM|| j                            d          k    r|t          |          z  }n|| j                            d          k    r|t          |          z  }n|| j                            d          k    r|t                               |          z  }n|| j                            d          k    r|t          |          z  }n}|| j                            d          k    r|t          |          z  }nL|| j                            d          k    r.|t          |d	                   t          |d
                   z   z  }|S )Nr   rO   rP   rQ   rR   rS   rT   rU   r   r   )	r>   rE   rp   rr   r,   r   r%   r:   r/   )r   
identifiertyperI   r3   s        r   writePropertyzProperties.writePropertyL  s   &--j9994:##F++++eUGnn$FFTZ%%&89999j'''FFTZ%%&9::::j'''FFTZ%%&=>>>>*11%888FFTZ%%m4444j'''FFTZ%%&<====huoo%FFTZ%%&9::::huQx((8E!H+=+===Fr   c           
         d}| j                                         D ]}|                    dd          }t          | |          r|                     |          }| j        |         d         }|                     |          r.t          | |          D ]}||                     |||          z  }||                     ||t          | |                    z  }t          
                    t          |                    |z   S )Nr   r   r   r   )rq   r   r   r   r   r   r   r   r   r>   rE   r-   )r   r3   r   r   r   	attr_typeprops          r   r   zProperties.pack_  s    JOO%% 	P 	PD!\\#r22Nt^,, 	P!22>BB
 OJ7:	&&~66 P 'n = = F F$"4"4Z5>#F #F FF d00Y18~1N1NP P PF#**3v;;77&@@r   c                    || j                             d          k    r|d         }d}nZ|| j                             d          k    rt          |          }d}n)|| j                             d          k    rt          |          }d}n|| j                             d          k    rt                              |          \  }}n|| j                             d	          k    rt          |          \  }}n|| j                             d
          k    rt          ||          \  }}nZ|| j                             d          k    r<t          ||          \  }}||d          }t          |||z
            \  }}||f}||z  }||fS )NrO   r   r   rP   r   rQ   r'   rR   rS   rT   rU   )rp   rr   r!   r(   r>   r1   r<   r7   )r   r3   r   propslenrI   valuelenvalue1	valuelen1s           r   readPropertyzProperties.readPropertyp  s   4:##F++++1IEHHTZ%%&89999f%%EHHTZ%%&9::::f%%EHHTZ%%&=>>>>299&AAOE88TZ%%m4444'//OE88TZ%%&<====%fh77OE88TZ%%&9::::%fh77OE8HII&F '80C D DFIFOE	!Hhr   c                 D    d }| j         D ]}| j         |         |k    r|}|S r9   )rq   )r   r   r   r   s       r   getNameFromIdentzProperties.getNameFromIdent  s5    J 	 	Dz$:--	r   c                 d   |                                   t                              |          \  }}||d          }|}|dk    rt                              |          \  }}||d          }||z  }| j        |         d         }|                     |||          \  }}	||	d          }||	z  }|                     |          }
|
                    dd          }|                     |          s(t          | |          rt          dt           d          t          | |
|           |dk    | ||z   fS )Nr   r   r   z
Property 'z' must not exist more than once)r   r>   r1   r   r   r   r   r   r   r   propertysetattr)r   r3   r   VBIlenpropslenleftr   VBIlen2r   rI   r   propnamer   s               r   r   zProperties.unpack  sg   

/66v>>&Q"6"="=# #JGHH%FG#L
3A6I"//	<1 1OE8HII&FH$L,,Z88H%--c266N&&~66 L74;X;X L#JJJJL L LD(E*** Q  X&&&r   N)r   r	   r
   rJ   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   rM      s         $S
 S
 S
jA A A  '2 '2 '2R  
 
 
  . . .  &A A A"  0  ' ' ' ' 'r   rM   )r   packettypesr   	Exceptionr   r   r   r!   r%   r(   r/   r7   r:   r<   r>   rM   r   r   r   <module>r      sS  "  $ $ $ $ $ $	 	 	 	 	I 	 	 		 	 	 	 	m 	 	 	0 0 0
+ + +
0 0 0
+ + +
( ( (  *, , ,( ( (
- - - - - - - -`^' ^' ^' ^' ^' ^' ^' ^' ^' ^'r   