
    ih                        S r SSKJr  SSKrSSKrSSKrSSKrSSKJrJ	r	  SSK
Jr  SSKJrJr  SSKJr  SS	KJr  \(       a  SS
KJr  SSKJr  SSKJrJr  S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
    )annotationsN)TYPE_CHECKINGcast   )RecordUpdate)get_running_looprun_coro_with_timeout)current_time_millis)_CACHE_CLEANUP_INTERVAL)Zeroconf)AsyncListener)_WrappedTransportmake_wrapped_transporti  c                      \ rS 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rg)AsyncEngine.   z*An engine wraps sockets in the event loop.)
_cleanup_timer_listen_socket_respond_sockets_setup_taskloop	protocolsreadersrunning_futuresenderszcc                    S U l         Xl        / U l        / U l        / U l        S U l        X l        X0l        S U l        S U l	        g N)
r   r   r   r   r   r   r   r   r   r   )selfzeroconflisten_socketrespond_socketss       G/home/sebas/venvs/catt/lib/python3.13/site-packages/zeroconf/_engine.py__init__AsyncEngine.__init__>   sI     7;	.00202BF+ /:>6:    c                    Xl         UR                  5       U l        U R                   R                  U R	                  U5      5      U l        g)Set up the instance.N)r   create_futurer   create_task_async_setupr   )r   r   loop_thread_readys      r#   setupAsyncEngine.setupO   s=     	"00299001B1BCT1UVr&   c                "  #    U R                  5         U R                  5       I Sh  vN   U R                  c   eU R                  R                  5       (       d  U R                  R	                  S5        U(       a  UR                  5         gg Nf7f)r(   NT)"_async_schedule_next_cache_cleanup_async_create_endpointsr   done
set_resultset)r   r,   s     r#   r+   AsyncEngine._async_setupY   sw     //1**,,,""...""''))**40!!# 	 	-s   $BBA'Bc           	       ^ #    T R                   c   eT R                   n/ n/ nT R                  (       a  UR                  T R                  5        T R                   H*  nXB;  a  UR                  U5        UR                  U5        M,     U H  nUR	                  U 4S jUS9I Sh  vN u  pVT R
                  R                  [        [        U5      5        T R                  R                  [        [        [        R                  U5      5      5        XC;   d  M  T R                  R                  [        [        [        R                  U5      5      5        M     g N7f)z%Create endpoints to send and receive.Nc                 .   > [        T R                  5      $ r   )r   r   r   s   r#   <lambda>5AsyncEngine._async_create_endpoints.<locals>.<lambda>r   s    dgg.r&   )sock)r   r   appendr   create_datagram_endpointr   r   r   r   r   asyncioDatagramTransportr   )r   r   reader_socketssender_socketss	transportprotocols   `      r#   r1   #AsyncEngine._async_create_endpointsc   s    yy$$$yy!!$"5"56&&A&%%a(!!!$ '
  A(,(E(E. )F ) #I NN!!$}h"?@LL 6tG<U<UW`7a bc"##$:4@Y@Y[d;e$fg  #s   B"E%E&A.EAEc           
        [        5       nU R                  R                  R                  U5        U R                  R                  R                  UU R                  R                  R                  U5       Vs/ s H  n[        X"5      PM     sn5        U R                  R                  R                  S5        U R                  5         gs  snf )zPeriodic cache cleanup.FN)
r
   r   question_historyasync_expirerecord_managerasync_updatescacher   async_updates_completer0   )r   nowrecords      r#   _async_cache_cleanup AsyncEngine._async_cache_cleanupz   s    !#  --c2,,8<8R8RSV8WX8Wf\&)8WX	
 	55e<//1 Ys   7C	
c                    U R                   nUc   eUR                  UR                  5       [        -   U R                  5      U l        g)z Schedule the next cache cleanup.N)r   call_attimer   rO   r   )r   r   s     r#   r0   .AsyncEngine._async_schedule_next_cache_cleanup   s=    yy"ll499;9P+PRVRkRklr&   c                  #    U R                   c   eU R                   I Sh  vN   U R                  5         [        R                  " S5      I Sh  vN   U R                  c   eU R                  R                  5         g N\ N07f)z/Cancel and wait for the cleanup task to finish.Nr   )r   _async_shutdownr>   sleepr   cancelr8   s    r#   _async_closeAsyncEngine._async_close   sp     +++mmA""...""$	 	s!   BA>-BB /B Bc                   U R                   c   eU R                  c   eU R                  R                  5       U l         [        R                  " U R
                  U R                  5       H  nUR                  R                  5         M     g)z Shutdown transports and sockets.N)	r   r   r)   	itertoolschainr   r   rC   close)r   wrapped_transports     r#   rV   AsyncEngine._async_shutdown   sj    ""...yy$$$"ii557!*t||!L''--/ "Mr&   c                   U R                   c   e[        5       U R                   :X  a  U R                  5         gU R                   R                  5       (       d  g[	        U R                  5       U R                   [        5        g)zClose from sync context.

While it is not expected during normal operation,
this function may raise EventLoopBlocked if the underlying
call to `_async_close` cannot be completed.
N)r   r   rV   
is_runningr	   rY   _CLOSE_TIMEOUTr8   s    r#   r^   AsyncEngine.close   sa     yy$$$*  "yy##%%d//1499nMr&   N)r    r   r!   zsocket.socket | Noner"   zlist[socket.socket]returnNone)r   zasyncio.AbstractEventLoopr,   threading.Event | Nonere   rf   )r,   rg   re   rf   )re   rf   )__name__
__module____qualname____firstlineno____doc__	__slots__r$   r-   r+   r1   rO   r0   rY   rV   r^   __static_attributes__ r&   r#   r   r   .   s    4I;; ,; -	;
 
;"W'W 2W 
	W$h.	2m%0Nr&   r   )rl   
__future__r   r>   r\   socket	threadingtypingr   r   _record_updater   _utils.asyncior   r	   _utils.timer
   constr   _corer   	_listenerr   
_transportr   r   rc   r   ro   r&   r#   <module>r{      sK   , #     & ( C , * % A|N |Nr&   