
    8j                        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d0d#Zd1d&Zd2d'Zd3d)ZdS )4a  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   futasyncio.FuturereturnNonec                \    |                                  s|                     d           dS dS )z'Set a future to None if it is not done.N)done
set_result)r   s    M/home/user/adhan/venv/lib/python3.11/site-packages/zeroconf/_utils/asyncio.py_set_future_none_if_not_doner   *   s4    88:: t     futuresset[asyncio.Future]c                V    | D ]}t          |           |                                  dS )zResolve all futures to None.N)r   clear)r   r   s     r   _resolve_all_futures_to_noner   0   s3     * *$S))))MMOOOOOr   loopasyncio.AbstractEventLoop
future_settimeoutfloatc                n  K   |                                  }|                    |           |                     t          |          t          |          }	 | d{V  |                                 |                    |           dS # |                                 |                    |           w xY w)z/Wait for a future or timeout (in milliseconds).N)create_futureadd
call_laterr   r   canceldiscard)r   r   r   futurehandles        r   wait_for_future_set_or_timeoutr)   7   s       !!FNN6__.w779UW]^^F#6""""" 	6""""s   B	 	+B4r'   asyncio.Future[bool | None]c                t  K   t          j                    }|                    |t          |           }	 |  d{V  nO# t           j        $ r= t
          j        dk    r*t          j                    x}r|                                r Y nw xY w|	                                 dS # |	                                 w xY 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_timeoutr5   E   s      #%%D__W&BFKKF!   w&&G4H4J4J,JD&PTP_P_PaPa& 	s'   < B! A	BB! BB! !B7set[asyncio.Task]c                  K   t          j        d           d{V  t          d          D ]I}t          j        t
                    5  t          j        |           cddd           c S # 1 swxY w Y   Jt                      S )zReturn all tasks running.r   Nr   )r-   sleeprange
contextlibsuppressRuntimeError	all_tasksset)r   _s     r   _async_get_all_tasksr@   R   s      
-

 1XX + + .. 	+ 	+$T**	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+55Ls   A**A.	1A.	
wait_tasksc                L   K   t          j        | t                     d{V  dS )z6Wait for the event loop thread we started to shutdown.)r   N)r-   wait_TASK_AWAIT_TIMEOUT)rA   s    r   _wait_for_loop_tasksrE   ^   s4      
,z+>
?
?
??????????r   awr   c                *   K   |  d{V }| d{V  dS )z-Wait on an awaitable and the task it returns.N )rF   r4   s     r   await_awaitablerI   c   s,      888888D
JJJJJJJJJr   r   r   c                    	 t          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   )rF   r   r   exs       r   run_coro_with_timeoutrP   i   sl    '/D99@@g&&)??
 
 	
 * ' ' 'B&'s   <? A AA c                ^   t          t          j        t          |           |                               t
                              }|d |D             z  }|r:t          j        t          |          |                               t                     |                     | j	                   dS )z.Wait for pending tasks and stop an event loop.c                :    h | ]}|                                 |S rH   )r   ).0r4   s     r   	<setcomp>z shutdown_loop.<locals>.<setcomp>   s%    DDDt		DdDDDr   N)
r>   r-   rK   r@   rL   _GET_ALL_TASKS_TIMEOUTrE   _WAIT_FOR_LOOP_TASKS_TIMEOUTcall_soon_threadsafestop)r   pending_taskss     r   shutdown_looprZ   |   s    ()=d)C)CTJJQQRhii M DD}DDDDM 
()=m)L)LdSSZZ(	
 	
 	
 	di(((((r    asyncio.AbstractEventLoop | Nonec                     t          j        t                    5  t          j                    cddd           S # 1 swxY w Y   dS )z*Check if an event loop is already running.N)r:   r;   r<   r-   r.   rH   r   r   r.   r.      s~    		\	*	* * *'))* * * * * * * * * * * * * * * *4s   :>>)r   r   r   r   )r   r   r   r   )r   r   r   r   r   r    r   r   )r'   r*   r   r    r   r   )r   r   r   r6   )rA   r6   r   r   )rF   r   r   r   )rF   r   r   r   r   r    r   r   )r   r   r   r   )r   r[   ) __doc__
__future__r   r-   concurrent.futuresrM   r:   r0   collections.abcr   r   typingr   _exceptionsr   constr	   timer   rD   rU   rV   r   r   r)   r5   r@   rE   rI   rP   rZ   r.   rH   r   r   <module>re      s   , # " " " " "          



 0 0 0 0 0 0 0 0       * * * * * * * * * * * * # # # # # #           # # # #
 
 
 
	 	 	 	@ @ @ @
   ' ' ' '&
) 
) 
) 
)     r   