
    iaA                       % S r SSKJr  SSKrSSKrSSKJr  SSKJrJ	r	J
r
JrJrJrJrJr  SSKJr  SSKJr  SS	KJr  SS
KJrJrJrJrJrJrJrJrJrJ r J!r!J"r"J#r#  Sr$Sr%Sr&Sr'\(\RR                  \4r*0 r+S\,S'   \-r.\/r0 " S S5      r1g)a  Multicast DNS Service Discovery for Python, v0.14-wmcbrine
Copyright 2003 Paul Scott-Murphy, 2014 William McBrine

This module provides a framework for the use of DNS Service Discovery
using IP multicast.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
    )annotationsN)Any   )
DNSAddressDNSHinfoDNSNsec
DNSPointerDNSQuestion	DNSRecord
DNSServiceDNSText)IncomingDecodeError)log)current_time_millis)_FLAGS_QR_MASK_FLAGS_QR_QUERY_FLAGS_QR_RESPONSE	_FLAGS_TC_TYPE_A
_TYPE_AAAA_TYPE_CNAME_TYPE_HINFO
_TYPE_NSEC	_TYPE_PTR	_TYPE_SRV	_TYPE_TXT_TYPES         zdict[str, int | tuple]
_seen_logsc                     \ rS rSrSrSr   S         SS jjrSS jrSS jrSS jr	\
SS	 j5       r\
S S
 j5       r\
S!S j5       r\
S!S j5       r\
S!S j5       r\
S!S j5       rS"S jr\S#S j5       rS$S jrSS jrS%S jrS"S jrS"S jrS%S jrS&S jrS"S jr            S'S jrS(S jrS%S jrS)S jrSr g)*DNSIncomingG   z/Object representation of an incoming DNS packet)_answers	_data_len_did_read_others_has_qu_question_name_cache_num_additionals_num_answers_num_authorities_num_questions
_questionsdataflagsidnowoffsetscope_idsourcevalidviewNc                   SU l         SU l        Xl        Xl        [	        U5      U l        0 U l        / U l        / U l        SU l	        SU l
        SU l        SU l        SU l        SU l        SU l        U=(       d
    [!        5       U l        X l        X0l        SU l         U R+                  5         g! [,         a5    U R/                  SU R$                  U R                  U R                  5         gf = f)z/Constructor from string holding bytes of packetr   F?Received invalid packet from %s at offset %d while unpacking %rN)r0   r3   r/   r7   lenr&   r)   r.   r%   r1   r-   r+   r,   r*   r6   r'   r   r2   r5   r4   r(   _initial_parseDECODE_EXCEPTIONS_log_exception_debug)selfr/   r5   r4   r2   s        R/home/sebas/venvs/catt/lib/python3.13/site-packages/zeroconf/_protocol/incoming.py__init__DNSIncoming.__init__`   s     
		T13-/)+ ! !
 %/-/  %	!  	%%Q				s   B. .<C-,C-c                6    U R                   [        -  [        :H  $ )z Returns true if this is a query.)r0   r   r   r>   s    r?   is_queryDNSIncoming.is_query   s    

^+??    c                6    U R                   [        -  [        :H  $ )z#Returns true if this is a response.)r0   r   r   rC   s    r?   is_responseDNSIncoming.is_response   s    

^+0BBBrF   c                    U R                   $ )z.Returns true if any question is a QU question.)r(   rC   s    r?   has_qu_questionDNSIncoming.has_qu_question   s    $$$rF   c                6    U R                   [        -  [        :H  $ )z$Returns true if this is a truncated.)r0   r   rC   s    r?   	truncatedDNSIncoming.truncated   s     

Y&944rF   c                    U R                   $ )zQuestions in the packet.)r.   rC   s    r?   	questionsDNSIncoming.questions   s     rF   c                    U R                   $ )z"Number of questions in the packet.)r-   rC   s    r?   num_questionsDNSIncoming.num_questions   s     """rF   c                    U R                   $ )z Number of answers in the packet.)r+   rC   s    r?   num_answersDNSIncoming.num_answers   s        rF   c                    U R                   $ )z$Number of authorities in the packet.r,   rC   s    r?   num_authoritiesDNSIncoming.num_authorities        $$$rF   c                    U R                   $ )z$Number of additionals in the packet.)r*   rC   s    r?   num_additionalsDNSIncoming.num_additionals   r]   rF   c                    U R                  5         U R                  5         U R                  (       d  U R                  5         SU l        g)z6Parse the data needed to initialize the packet object.TN)_read_header_read_questionsr-   _read_othersr6   rC   s    r?   r;   DNSIncoming._initial_parse   s6    ""
rF   c                    Sn[         R                  " 5       n[        US   5      nU[        ;  a  U[        U'   Sn[        R
                  " U=(       d    S/SU06  g )NFr   TzException occurredexc_info)sysrg   strr!   r   debug)clslogger_datalog_exc_inforg   exc_strs        r?   r=    DNSIncoming._log_exception_debug   sQ    <<>hqk"*$"*JwL		K9$8#9R\RrF   c                   U R                   (       d   U R                  5         U R                  $ U R                  $ ! [         a@    U R                  SU R                  U R
                  U R                  5         U R                  $ f = f)zAnswers in the packet.r9   )r'   rd   r<   r=   r5   r3   r/   r%   rC   s    r?   answersDNSIncoming.answers   st    $$!!# }}t}} % ))UKKKKII	 }}s   ; <BBc                     U R                   S:  $ )z Returns true if this is a probe.r   rZ   rC   s    r?   is_probeDNSIncoming.is_probe   s    $$q((rF   c                F   SR                  SR                  SU R                   3SU R                   3SU R                   3SU R
                   3SU R                   3SU R                   3S	U R                   3S
U R                   3SU R                  5        3/	5      5      $ )Nz<DNSIncoming:{}>z, zid=zflags=z
truncated=zn_q=zn_ans=zn_auth=zn_add=z
questions=zanswers=)formatjoinr1   r0   rN   r-   r+   r,   r*   r.   rq   rC   s    r?   __repr__DNSIncoming.__repr__   s    !((II$''OTZZL)  014../0T../0d3345T2234  12t||~./

 	
rF   c                l   U R                   nU R                  nU =R                  S-  sl        X   S-  XS-      -  U l        XS-      S-  XS-      -  U l        XS-      S-  XS-      -  U l        XS-      S-  XS	-      -  U l        XS-      S-  XS
-      -  U l        XS-      S-  XS-      -  U l        g)zReads header portion of packet      r   r                  	   
      N)r7   r3   r1   r0   r-   r+   r,   r*   )r>   r7   r3   s      r?   rb   DNSIncoming._read_header   s    yyr,!#dA:&661*%*T1*-==
"A:.!3dA:6FF !,1D!4DD $aZ 0A 5aZ8H H $b[ 1Q 6rk9J JrF   c                   U R                   nU R                  n[        U R                  5       H  nU R	                  5       nU R
                  nU =R
                  S-  sl        X   S-  XS-      -  nXS-      S-  XS-      -  n[        R                  " [        5      nUR                  XFU5        UR                  (       a  SU l
        UR                  U5        M     g)z!Reads questions section of packetr   r}   r   r   r~   TN)r7   r.   ranger-   
_read_namer3   r
   __new__
_fast_inituniquer(   append)	r>   r7   rQ   _namer3   type_class_questions	            r?   rc   DNSIncoming._read_questions   s    yyOO	t**+A??$D[[FKK1KLA%aZ(88E1*%*T1*-==F"**;7HV4(,%X& ,rF   c                    U R                   U R                     nU =R                  S-  sl        U R                  U R                  U R                  U-    R                  SS5      nU =R                  U-  sl        U$ )z(Reads a character string from the packetr   utf-8replace)r7   r3   r/   decoder>   lengthinfos      r?   _read_character_string"DNSIncoming._read_character_string  s_    4;;'qyyt{{V';<CCGYWvrF   c                |    U R                   U R                  U R                  U-    nU =R                  U-  sl        U$ )z0Reads a string of a given length from the packet)r/   r3   r   s      r?   _read_stringDNSIncoming._read_string  s2    yyt{{V';<vrF   c                   SU l         U R                  nU R                  U R                  -   U R                  -   n[        U5       H  nU R                  5       nU R                  nU =R                  S-  sl        X   S-  XS-      -  nXS-      S-  XS-      -  nXS-      S-  XS	-      S
-  -  XS-      S-  -  XS-      -  nXS-      S-  XS-      -  n	U R                  U	-   n
Sn U R                  XFXxU	5      nUc  M  U R                  R!                  U5        M     g! [         aJ    Xl        [        R                  " SU[        R                  " Xf5      U R                  U R                  SS9   Nxf = f)zDReads the answers, authorities and additionals section of the
packetTr   r}   r   r   r~   r      r      r   r   r   NzTUnable to parse; skipping record for %s with type %s at offset %d while unpacking %r)rg   )r'   r7   r+   r,   r*   r   r   r3   _read_recordr<   r   rj   r   getr/   r%   r   )r>   r7   nr   domainr3   r   r   ttlr   endrecs               r?   rd   DNSIncoming._read_others  s    !%yy 5 558M8MMqA__&F[[FKK2K LA%aZ(88E1*%*T1*-==Fz"b(4
+;r+AADRSDTXYDYY\`jkak\llC1*%*T1*-==F++&CC''vFK $$S)9  %  "		jJJu,KKII!s   &DAE21E2c                   U[         :X  aJ  [        R                  " [        5      nUR                  XX4U R	                  S5      SU R
                  5        U$ U[        [        4;   aH  [        R                  " [        5      nUR                  XX4U R                  5       U R
                  5        U$ U[        :X  aI  [        R                  " [        5      nUR                  XX4U R	                  U5      U R
                  5        U$ U[        :X  a  U R                  n	U R                  n
U =R                  S-  sl        X   S-  XS-      -  nXS-      S-  XS-      -  nXS-      S-  XS-      -  n[        R                  " [        5      nUR                  UUUUUUUU R                  5       U R
                  5	        U$ U[         :X  aY  ["        R                  " ["        5      nUR                  UUUUU R%                  5       U R%                  5       U R
                  5        U$ U[&        :X  aV  [        R                  " [        5      nUR                  UUUUU R	                  S	5      U R(                  U R
                  5        U$ U[*        :X  ai  U R                  n[,        R                  " [,        5      nUR                  UUUUU R                  5       U R/                  UU-   5      U R
                  5        U$ U =R                  U-  sl        g)
z/Read known records types and skip unknown ones.r   Nr   r}   r   r   r~   r   r   )r   r   r   r   r   r2   r   r   r	   r   r   r   r   r7   r3   r   r   r   r   r   r4   r   r   _read_bitmap)r>   r   r   r   r   r   address_recpointer_rectext_recr7   r3   priorityweightportsrv_rec	hinfo_rec
name_startnsec_recs                     r?   r   DNSIncoming._read_record5  s    G$,,Z8K""6&t?P?PQR?SUY[_[c[cd[),,$,,Z8K""6&t?PRVRZRZ[Iw/HvD<M<Mf<UW[W_W_`OI99D[[FKK1K|q(4
+;;H1*%*T1*-==F
#q(4
+;;D ((4G!
 NK ((2I  ++-++- J$,,Z8K""!!"% JJw/H!!!*v"56 O 	vrF   c                   / nU R                   nU R                  U:  a  U R                  nUS-   nUS-   nX4   nX5   nXh-   n	[        U R                  Xi 5       HB  u  p[	        S5       H.  nUSU-	  -  (       d  M  UR                  XS-  -   U
S-  -   5        M0     MD     U =R                  SU-   -  sl        U R                  U:  a  M  U$ )z%Reads an NSEC bitmap from the packet.r   r   r}   r      )r7   r3   	enumerater/   r   r   )r>   r   rdtypesr7   r3   offset_plus_oneoffset_plus_twowindowbitmap_length
bitmap_endibytebits                r?   r   DNSIncoming._read_bitmap  s    yykkC[[F$qjO$qjO\F 1M(8J$TYY%JK 8Cts{++sc\'9AE'AB $ L KK1},,K kkC rF   c                   / n[        5       nU R                  nU R                  X1U5      U l        XR                  U'   SR	                  U5      S-   n[        U5      [        :  a"  [        SU S[         SU R                   35      eU$ )z$Reads a domain name from the packet..z	DNS name z exceeds maximum length of  from )	setr3   _decode_labels_at_offsetr)   rx   r:   MAX_NAME_LENGTHr   r5   )r>   labelsseen_pointersoriginal_offsetr   s        r?   r   DNSIncoming._read_name  s    "%%++33O][,2)xx#%t9&%D6!<_<MVTXT_T_S`a  rF   c                   U R                   nXR                  :  Ga  XA   nUS:X  a	  U[        -   $ US:  aG  U[        -   nUR                  U R                  XfU-    R                  SS5      5        U[        U-   -  nMp  US:  a  [        SU SU SU R                   35      eXAS	-      nUS
-  S-  U-   nUn	XR                  :  a  [        SU SU SU R                   35      eX:X  a  [        SU SU R                   35      eX;   a  [        SU SU R                   35      eU R                  R                  U	5      n
U
(       d3  / n
UR                  U	5        U R                  XU5        XR                  U	'   UR                  U
5        [        U5      [        :  a  [        SU SU R                   35      eU[        -   $ [        SU R                   35      e)Nr   @   r   r      zDNS compression type z is unknown at r   r   ?   r   zDNS compression pointer at z points to z beyond packet from z points to itself from z was seen again from z7Maximum dns labels reached while processing pointer at z1Corrupt packet received while decoding name from )r7   r&   DNS_COMPRESSION_HEADER_LENr   r/   r   r   r5   r)   r   addr   extendr:   MAX_DNS_LABELSDNS_COMPRESSION_POINTER_LEN)r>   offr   r   r7   r   	label_idx	link_datalinklink_py_intlinked_labelss              r?   r   $DNSIncoming._decode_labels_at_offset  s   yyNN"YF{777}"<<	dii	4FGNNwXabc1F::})+F8?3%vdkk][ 
 1WITMS(94DKnn$)1#k$G[\`\g\g[hi  {)1#6Mdkk][  +)1#6KDKK=Y  !,,00=M  "!!+.--d=Q0=  -MM-(6{^+)McURXY]YdYdXef  444!$UVZVaVaUb"cddrF   )NNN)
r/   bytesr5   ztuple[str, int] | Noner4   z
int | Noner2   zfloat | NonereturnNone)r   bool)r   zlist[DNSQuestion])r   int)r   r   )rl   r   r   r   )r   zlist[DNSRecord])r   ri   )r   _intr   r   )r   _strr   r   r   r   r   r   r   r   r   zDNSRecord | None)r   r   r   z	list[int])r   r   r   z	list[str]r   zset[int]r   r   )!__name__
__module____qualname____firstlineno____doc__	__slots__r@   rD   rH   rK   propertyrN   rQ   rT   rW   r[   r_   r;   classmethodr=   rq   rt   ry   rb   rc   r   r   rd   r   r   r   r   __static_attributes__ rF   r?   r#   r#   G   sh   9I2 *.# ## '# 	#
 # 
#J@C% 5 5   # # ! ! % % % % S S)
"K'""*HNN#'N15N<@NJNN	N`$0erF   r#   )2r   
__future__r   structrh   typingr   _dnsr   r   r   r	   r
   r   r   r   _exceptionsr   _loggerr   _utils.timer   constr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   
IndexErrorerrorr<   r!   __annotations__ri   r   r   r   r#   r   rF   r?   <module>r      s   , #  
 	 	 	 .  -       /BC  &(
" '

Ne NerF   