
    iI1                        S r SSKJr  SSKJr  SSKJrJrJr  SSK	J
r
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Jr  \\\\\4r\
\\\\\4   r\\\\\4   4   r\r\r \!r"\#r$S
r%SS jr& " S S5      r'g)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
    )annotations)Iterable)heapifyheappopheappush)Unioncast   )
DNSAddressDNSEntryDNSHinfoDNSNsec
DNSPointer	DNSRecord
DNSServiceDNSText)current_time_millis)_ONE_SECOND	_TYPE_PTRd   c                $    X   nX2	 U(       d  X	 gg)zSRemove a key from a DNSRecord cache

This function must be run in from event loop.
N )cachekeyrecordrecord_caches       F/home/sebas/venvs/catt/lib/python3.13/site-packages/zeroconf/_cache.py_remove_keyr   8   s    
 :LJ     c                      \ rS rSrS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#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))DNSCacheC   zA cache of DNS entries.c                <    0 U l         / U l        0 U l        0 U l        g N)r   _expire_heap_expirationsservice_cacheselfs    r   __init__DNSCache.__init__F   s!    *,
;=4624r   c                L   U R                   R                  UR                  5      =nc  0 =o R                   UR                  '   X;  =(       a    [        U[        5      (       + nXU'   UR
                  UR                  S-  -   nU R                  R                  U5      U:w  a%  [        U R                  XA45        X@R                  U'   [        U[        5      (       aH  UnU R                  R                  UR                  5      =nc  0 =o`R                  UR                  '   XVU'   U$ )zwAdds an entry.

Returns true if the entry was not already in the cache.

This function must be run in from event loop.
i  )r   getr   
isinstancer   createdttlr&   r   r%   r   r'   
server_key)r)   r   storenewwhenservice_recordservice_stores          r   
_async_addDNSCache._async_addO   s     ZZ^^FJJ//E8-//EJJvzz*!E*VW*E&Ef~~d!23  (D0T&&7(,f%fj))#N!%!3!3!7!78Q8Q!RR[PRR 2 2>3L3L M,:.)
r   c                P    SnU H  nU R                  U5      (       d  M  SnM     U$ )zAdd multiple records.

Returns true if any of the records were not in the cache.

This function must be run in from event loop.
FT)r7   )r)   entriesr3   entrys       r   async_add_recordsDNSCache.async_add_recordsm   s.     Eu%%  
r   c                    [        U[        5      (       a#  Un[        U R                  UR                  U5        [        U R
                  UR                  U5        U R                  R                  US5        g)zARemoves an entry.

This function must be run in from event loop.
N)	r.   r   r   r'   r1   r   r   r&   pop)r)   r   r5   s      r   _async_removeDNSCache._async_removez   sX    
 fj))#N**N,E,E~VDJJ

F3fd+r   c                8    U H  nU R                  U5        M     g)zHRemove multiple records.

This function must be run in from event loop.
N)r@   )r)   r:   r;   s      r   async_remove_recordsDNSCache.async_remove_records   s    
 Eu% r   c                   [        U R                  5      =n(       d  / $ / nU R                  (       aw  U R                  S   nUS   nXQ:  a  O][        U R                  5        US   nU R                  R	                  U5      U:X  a  UR                  U5        U R                  (       a  Mw  U[        :  ay  U[        U R                  5      S-  :  a]  U R                   Vs/ s H+  opR                  R	                  US   5      US   :X  d  M)  UPM-     snU l        [        U R                  5        U R                  U5        U$ s  snf )zPurge expired entries from the cache.

This function must be run in from event loop.

:param now: The current time in milliseconds.
r   r
      )	lenr%   r   r&   r-   append _MIN_SCHEDULED_RECORD_EXPIRATIONr   rC   )r)   nowexpire_heap_lenexpiredwhen_recordr4   r   r;   s           r   async_expireDNSCache.async_expire   s,    $'t'8'8#999I#%++A.Kq>DzD%%&
 !^F  $$V,4v& ( >>#d&7&7"81"<< $(#4#4!#4%8I8I8M8MeTUh8W[`ab[c8c#4!D D%%&!!'*!s   (D?	D?c                v    U R                   R                  UR                  5      nUc  gUR                  U5      $ )zGets a unique entry by key.  Will return None if there is no
matching entry.

This function is not threadsafe and must be called from
the event loop.
N)r   r-   r   )r)   r;   r2   s      r   async_get_uniqueDNSCache.async_get_unique   s1     

uyy)=yyr   c                    UR                  5       nU R                  R                  U5      n/ nUc  U$ UR                  5        H6  nX'R                  :X  d  M  X7R
                  :X  d  M%  UR                  U5        M8     U$ )zpGets all matching entries by details.

This function is not thread-safe and must be called from
the event loop.
)lowerr   r-   valuestypeclass_rH   )r)   nametype_rW   r   recordsmatchesr   s           r   async_all_by_detailsDNSCache.async_all_by_details   sg     jjl**..%#%?Nnn&F#--(?v& ' r   c                $    U R                  U5      $ )zReturns a dict of entries whose key matches the name.

This function is not threadsafe and must be called from
the event loop.
)entries_with_namer)   rX   s     r   async_entries_with_name DNSCache.async_entries_with_name   s     %%d++r   c                $    U R                  U5      $ )zReturns a dict of entries whose key matches the server.

This function is not threadsafe and must be called from
the event loop.
)entries_with_serverr`   s     r   async_entries_with_server"DNSCache.async_entries_with_server   s     ''--r   c                f   [        U[        5      (       a5  U R                  R                  UR                  0 5      R                  U5      $ [        [        U R                  R                  UR                  0 5      R                  5       5      5       H  nUR                  U5      (       d  M  Us  $    g)zFGets an entry by key.  Will return None if there is no
matching entry.N)	r.   _UNIQUE_RECORD_TYPESr   r-   r   reversedlistrU   __eq__)r)   r;   cached_entrys      r   r-   DNSCache.get   s     e122::>>%))R044U;;$T$**..B*G*N*N*P%QRL||L))## S r   c                    UR                  5       nU R                  R                  U5      nUc  g[        [	        UR                  5       5      5       H'  nX&R                  :X  d  M  X6R                  :X  d  M%  Us  $    g)a|  Gets the first matching entry by details. Returns None if no entries match.

Calling this function is not recommended as it will only
return one record even if there are multiple entries.

For example if there are multiple A or AAAA addresses this
function will return the last one that was added to the cache
which may not be the one you expect.

Use get_all_by_details instead.
N)rT   r   r-   ri   rj   rU   rV   rW   )r)   rX   rY   rW   r   rZ   rl   s          r   get_by_detailsDNSCache.get_by_details   sf     jjl**..%?$T'..*:%;<L)))f8K8K.K## = r   c                   UR                  5       nU R                  R                  U5      nUc  / $ [        UR	                  5       5       Vs/ s H'  obUR
                  :X  d  M  X6R                  :X  d  M%  UPM)     sn$ s  snf )z%Gets all matching entries by details.)rT   r   r-   rj   rU   rV   rW   )r)   rX   rY   rW   r   rZ   r;   s          r   get_all_by_detailsDNSCache.get_all_by_details  sf    jjl**..%?I#'(8#9l#9%ejj=PU[_k_kUk#9llls   A=#A=4A=c                    U R                   R                  UR                  5       5      =n(       a  [        UR	                  5       5      $ / $ )z8Returns a list of entries whose server matches the name.)r'   r-   rT   rj   rU   )r)   serverr:   s      r   rd   DNSCache.entries_with_server  s;    ((,,V\\^<<7<())	r   c                    U R                   R                  UR                  5       5      =n(       a  [        UR	                  5       5      $ / $ )z5Returns a list of entries whose key matches the name.)r   r-   rT   rj   rU   )r)   rX   r:   s      r   r_   DNSCache.entries_with_name  s7    jjnnTZZ\2272())	r   c                    [        5       n[        U R                  U5      5       HS  nUR                  [        :X  d  M  UR                  U5      (       a  M1  [        [        U5      R                  U:X  d  MQ  Us  $    g r$   )	r   ri   r_   rV   r   
is_expiredr	   r   alias)r)   rX   r{   rJ   r   s        r   !current_entry_with_name_and_alias*DNSCache.current_entry_with_name_and_alias  s`    !#t55d;<Fy())#..V,22e; = r   c                ,    [        U R                  5      $ )z1Return a copy of the list of current cache names.)rj   r   r(   s    r   namesDNSCache.names*  s    DJJr   c                    [        U5      nU HR  u  pVnU R                  XVU5       H6  nUR                  n	X9-
  [        :  d  M  X;  d  M$  U R	                  XS5        M8     MT     g )Nr
   )setr\   r/   r   _async_set_created_ttl)
r)   unique_typesanswersrJ   answers_rrsetrX   rY   rW   r   created_doubles
             r   1async_mark_unique_records_older_than_1s_to_expire:DNSCache.async_mark_unique_records_older_than_1s_to_expire.  s]     G#/D33DH!'(;6F<W//Q?	 I $0r   c                H    UR                  X#5        U R                  U5        g)z)Set the created time and ttl of a record.N)_set_created_ttlr7   )r)   r   rJ   r0   s       r   r   DNSCache._async_set_created_ttl@  s     	)r   )r&   r%   r   r'   N)returnNone)r   
_DNSRecordr   bool)r:   Iterable[DNSRecord]r   r   )r   r   r   r   )r:   r   r   r   )rJ   _floatr   list[DNSRecord])r;   _UniqueRecordsTyper   DNSRecord | None)rX   _strrY   _intrW   r   r   r   )rX   strr   r   )r;   r   r   r   )rX   r   rY   r   rW   r   r   r   )rX   r   rY   r   rW   r   r   r   )ru   r   r   r   )rX   r   r{   r   r   r   )r   z	list[str])r   zset[tuple[_str, _int, _int]]r   r   rJ   r   r   r   )r   r   rJ   r   r0   r   r   r   )__name__
__module____qualname____firstlineno____doc__r*   r7   r<   r@   rC   rN   rQ   r\   ra   re   r-   ro   rr   rd   r_   r|   r   r   r   __static_attributes__r   r   r   r!   r!   C   s    !5<	,&-^
  ,.*m	 @2@ %@ 	@
 
@$ r   r!   N)r   _DNSRecordCacheTyper   r   r   r   r   r   )(r   
__future__r   collections.abcr   heapqr   r   r   typingr   r	   _dnsr   r   r   r   r   r   r   r   _utils.timer   constr   r   rh   r   dictr   r   r   r   floatr   intr   rI   r   r!   r   r   r   <module>r      s   , # $ , , 	 	 	 - )"Hj':N :xWjPQ 3Y	%9 ::; 

	

 $'  B  B r   