
    |;i                        d Z ddlmZ ddlZddlZddlZddl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 d	ZdZdZddZddZ	 	 	 	 	 	 	 	 ddZddZddZddZddZddZddZddZy) 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)	Awaitable	Coroutine)Any   )EventLoopBlocked)_LOADED_SYSTEM_TIMEOUT   )millis_to_seconds   c                H    | j                         s| j                  d       yy)z'Set a future to None if it is not done.N)done
set_result)futs    J/home/ubuntu/myenv/lib/python3.12/site-packages/zeroconf/_utils/asyncio.py_set_future_none_if_not_doner   *   s    88:t     c                H    | D ]  }t        |        | j                          y)zResolve all futures to None.N)r   clear)futuresr   s     r   _resolve_all_futures_to_noner   0   s"     *$S)*MMOr   c                6  K   | j                         }|j                  |       | j                  t        |      t        |      }	 | d{    |j                          |j                  |       y7 &# |j                          |j                  |       w xY ww)z/Wait for a future or timeout (in milliseconds).N)create_futureadd
call_laterr   r   canceldiscard)loop
future_settimeoutfuturehandles        r   wait_for_future_set_or_timeoutr#   7   s|      !FNN6__.w79UW]^F#6" 	6"s0   ABA3 
A1A3 "B1A3 3#BBc                l  K   t        j                         }|j                  |t        |       }	 |  d{    |j                          y7 # t         j                  $ r= t
        j                  dk\  r't        j                         x}r|j                         r Y bw xY w# |j                          w xY ww)zWait for a future or timeout.N)r      )
asyncioget_running_loopr   r   CancelledErrorsysversion_infocurrent_task
cancellingr   )r!   r    r   r"   tasks        r   wait_future_or_timeoutr.   E   s     ##%D__W&BFKF
 	 	!! w&G4H4H4J,JD,JPTP_P_Pa 	sD   ,B4A A
A B4
A ABB BB B11B4c                  K   t        j                  d       d{    t        d      D ];  }t        j                  t
              5  t        j                  |       cddd       c S  t               S 7 W# 1 sw Y   SxY ww)zReturn all tasks running.r   Nr   )r&   sleeprange
contextlibsuppressRuntimeError	all_tasksset)r   _s     r   _async_get_all_tasksr8   R   sq     
--
 1X +  . 	+$$T*	+ 	++ 5L 
	+ 	+s'   BA3+BA5B5A>	:Bc                V   K   t        j                  | t               d{    y7 w)z6Wait for the event loop thread we started to shutdown.)r    N)r&   wait_TASK_AWAIT_TIMEOUT)
wait_taskss    r   _wait_for_loop_tasksr=   ^   s     
,,z+>
???s   )')c                <   K   |  d{   }| d{    y7 7 w)z-Wait on an awaitable and the task it returns.N )awr-   s     r   await_awaitablerA   c   s     8D
JJ s   	c                    	 t        j                  | |      j                  t        |      t        z         S # t
        j                  j                  $ r}t        |d}~ww xY w)aw  Run a coroutine with a timeout.

    The timeout should only be used as a safeguard to prevent
    the program from blocking forever. The timeout should
    never be expected to be reached during normal operation.

    While not expected during normal operations, the
    function raises `EventLoopBlocked` if the coroutine takes
    longer to complete than the timeout.
    N)	r&   run_coroutine_threadsaferesultr   r	   
concurrentr   TimeoutErrorr   )r@   r   r    exs       r   run_coro_with_timeoutrH   i   s[    '//D9@@g&)??
 	
 ** 'B&'s   47 A AA c                j   t        t        j                  t        |       |       j	                  t
                    }||D ch c]  }|j                         s| c}z  }|r2t        j                  t        |      |       j	                  t               | j                  | j                         yc c}w )z.Wait for pending tasks and stop an event loop.N)r6   r&   rC   r8   rD   _GET_ALL_TASKS_TIMEOUTr   r=   _WAIT_FOR_LOOP_TASKS_TIMEOUTcall_soon_threadsafestop)r   pending_tasksr-   s      r   shutdown_looprO   |   s    (()=d)CTJQQRhiM }Dt		dDDM(()=m)LdSZZ(	
 	dii( Es   B0B0c                     t        j                  t              5  t        j                         cddd       S # 1 sw Y   yxY w)z*Check if an event loop is already running.N)r2   r3   r4   r&   r'   r?   r   r   r'   r'      s4    			\	* *'')* * *s	   8A)r   zasyncio.FuturereturnNone)r   set[asyncio.Future]rQ   rR   )r   asyncio.AbstractEventLoopr   rS   r    floatrQ   rR   )r!   zasyncio.Future[bool | None]r    rU   rQ   rR   )r   rT   rQ   set[asyncio.Task])r<   rV   rQ   rR   )r@   r   rQ   rR   )r@   r   r   rT   r    rU   rQ   r   )r   rT   rQ   rR   )rQ   z asyncio.AbstractEventLoop | None) __doc__
__future__r   r&   concurrent.futuresrE   r2   r)   collections.abcr   r   typingr   _exceptionsr   constr	   timer   r;   rJ   rK   r   r   r#   r.   r8   r=   rA   rH   rO   r'   r?   r   r   <module>r_      s   , #    
 0  * * #     #
##1D#OT#	#
	@
'&
)r   