
    [Th                         S SK r S SKrS SKrS SKrS SKrS SKrS SKJr  S SKJ	r	J
r
  S SKJrJrJrJr  S/rS\S\\\4   4S jrS	\S\\   4S
 jrS\\   S\S\\\4   4S jrS\S\4S jrS\\\\\4   4   SS4S jr " S S5      rg)    N)	timedelta)EventThread)AnyCallableOptionalUnionparse_rendezvous_endpoint
config_strreturnc                 H   0 nU R                  5       n U (       d  U$ U R                  S5      nU Ho  nUR                  SS5      tpEUR                  5       nU(       d  [        S5      eU(       a  US   R                  5       nOSnU(       d  [        SU S35      eXaU'   Mq     U$ )	zExtract key-value pairs from a rendezvous configuration string.

Args:
    config_str:
        A string in format <key1>=<value1>,...,<keyN>=<valueN>.
,=   zZThe rendezvous configuration string must be in format <key1>=<value1>,...,<keyN>=<valueN>.r   Nz%The rendezvous configuration option 'z' must have a value specified.)stripsplit
ValueError)r   config
key_valueskvkeyvaluesvalues          b/var/www/auris/envauris/lib/python3.13/site-packages/torch/distributed/elastic/rendezvous/utils.py_parse_rendezvous_configr      s      F!!#J!!#&JxxQ'iik7  1IOO%EE7u<Z[  s) * M    port_strc                 `    U (       a'  [         R                  " SU 5      (       a  [        U 5      $ g)z1Try to extract the port number from ``port_str``.z^[0-9]{1,5}$N)rematchint)r   s    r   _try_parse_portr"   <   s"    BHH_h778}r   endpointdefault_portc                    U b  U R                  5       n U (       d  SU4$ U S   S:X  a  U S   S:X  a  U // Q7tp#OU R                  SS5      tp#[        U5      S:  a  US   S:X  a  US   S:X  a  USS n[        U5      S:X  a'  [        US   5      nUb  US:  a  [	        S	U  S
35      eOUn[
        R                  " SU5      (       d  [	        SU  S35      eX$4$ )a  Extract the hostname and the port number from a rendezvous endpoint.

Args:
    endpoint:
        A string in format <hostname>[:<port>].
    default_port:
        The port number to use if the endpoint does not include one.

Returns:
    A tuple of hostname and port number.
	localhostr   []:r   i   z,The port number of the rendezvous endpoint 'z)' must be an integer between 0 and 65536.z^[\w\.:-]+$z)The hostname of the rendezvous endpoint 'zN' must be a dot-separated list of labels, an IPv4 address, or an IPv6 address.)r   rsplitlenr"   r   r   r    )r#   r$   hostrestports        r   r
   r
   C   s    >>#\** {chrlc1mmtooc1- 4y1}aCDHOAbz
4yA~tAw'<45=>xj I' '  ) 88ND))7z B; ;
 	

 :r   r-   c                    U S:X  a  g [         R                  " U 5      nU(       a  UR                  (       a  g [        R
                  " U S[        R                  [        R                  S9nU Vs/ s H
  oDS   S   PM     nn[        R                  " 5       nX:X  a  g[        R
                  " US[        R                  [        R                  S9nU HD  nUS   (       a  US   U :X  a    gU(       a  US   S   [        U5      :X  a    gUS   S   U;   d  MD    g   g! [         a    Sn GNf = f! [        [        R                  4 a  n/ n SnANSnAff = fs  snf )	a(  Indicate whether ``host`` matches the hostname of this machine.

This function compares ``host`` to the hostname as well as to the IP
addresses of this machine. Note that it may return a false negative if this
machine has CNAME records beyond its FQDN or IP addresses assigned to
secondary NICs.
r&   TN)protoflags   r      F)	ipaddress
ip_addressr   is_loopbacksocketgetaddrinfoIPPROTO_TCPAI_CANONNAMEgaierrorgethostnamestr)	r-   addrhost_addr_list_host_addr_infohost_ip_list	this_host	addr_list	addr_infos	            r   _matches_machine_hostnamerG   t   sK    {##D)   ++$f008K8K
 @NN~^1%a(~LN""$I""4v119L9LI 	Q<IaLD0 IaLOs4y0 Q<?l*  I   (  Os.   D 3D/ 0ED,+D,/E	EEsecondsc                     [        U [        5      (       a  [        R                  " U 6 n U S:  a  [        R
                  " U 5        gg)zSuspend the current thread for ``seconds``.

Args:
    seconds:
        Either the delay, in seconds, or a tuple of a lower and an upper
        bound within which a random delay will be picked.
g{Gz?N)
isinstancetuplerandomuniformtimesleep)rH   s    r   _delayrP      s7     '5!!..'*$

7 r   c            
          \ rS rSr% Sr " S S5      r\\   \S'   \\	   \S'   \\
R                     \S'   \\S'   S	\S
\S   S\S\SS4
S jr\S\\   4S j5       rS\SS4S jrSS jrSS jr\SS j5       r\S 5       rSrg)_PeriodicTimer   zRepresent a timer that periodically runs a specified function.

Args:
    interval:
        The interval, in seconds, between each run.
    function:
        The function to run.
c                   b    \ rS rSr% \\S'   \S   \S'   \\S4   \S'   \	\
\4   \S'   \\S'   S	rg
)_PeriodicTimer._Context   interval.Nfunction.argskwargs
stop_event N)__name__
__module____qualname____firstlineno__float__annotations__r   rK   r   dictr>   r   __static_attributes__r]   r   r   _ContextrU      s4    9%%CHoS#Xr   rf   _name_thread
_finalizer_ctxrW   rY   rX   rZ   r[   r   Nc                 P   S U l         U R                  5       U l        UR                  5       U R                  l        X R                  l        U=(       d    SU R                  l        U=(       d    0 U R                  l        [        5       U R                  l	        S U l
        S U l        g )Nr]   )rg   rf   rj   total_secondsrW   rY   rZ   r[   r   r\   rh   ri   )selfrW   rY   rZ   r[   s        r   __init___PeriodicTimer.__init__   sr     
MMO	%335		%				!<R		$w		r   c                     U R                   $ )zGet the name of the timer.)rg   rm   s    r   name_PeriodicTimer.name   s     zzr   rr   c                 H    U R                   (       a  [        S5      eXl        g)zSet the name of the timer.

The specified name will be assigned to the background thread and serves
for debugging and troubleshooting purposes.
The timer has already started.N)rh   RuntimeErrorrg   )rm   rr   s     r   set_name_PeriodicTimer.set_name   s     <<?@@
r   c                    U R                   (       a  [        S5      e[        U R                  U R                  =(       d    SU R
                  4SS9U l         [        R                  " X R                  U R                   U R
                  R                  5      U l
        SU R                  l        U R                   R                  5         g)zStart the timer.ru   PeriodicTimerT)targetrr   rZ   daemonFN)rh   rv   r   _runrg   rj   weakreffinalize_stop_threadr\   ri   atexitstartrq   s    r   r   _PeriodicTimer.start   s    <<?@@99.))	
 "**##T\\4993G3G
 "'r   c                 H    U R                   (       a  U R                  5         gg)z'Stop the timer at the next opportunity.N)ri   rq   s    r   cancel_PeriodicTimer.cancel  s    ??OO r   c                     U R                   R                  U R                  5      (       dS  U R                  " U R                  0 U R
                  D6  U R                   R                  U R                  5      (       d  MR  g g N)r\   waitrW   rY   rZ   r[   )ctxs    r   r}   _PeriodicTimer._run  sO    ..%%cll33LL#((1cjj1 ..%%cll33r   c                 D    UR                  5         U R                  5         g r   )setjoin)threadr\   s     r   r   _PeriodicTimer._stop_thread  s    r   )rj   ri   rg   rh   )r   N)r^   r_   r`   ra   __doc__rf   r   r>   rc   r   r~   r   r   r   r   rn   propertyrr   rw   r   r   staticmethodr}   r   re   r]   r   r   rR   rR      s      C=f))** N 9% 	
  
& hsm  	S 	T 	4
 2 2  r   rR   )r5   rL   r   r8   rN   r~   datetimer   	threadingr   r   typingr   r   r   r	   __all__r>   rd   r   r!   r"   rK   r
   boolrG   rb   rP   rR   r]   r   r   <module>r      s      	     # 1 1 '
'# #c3h #Lc hsm .sm.+..
38_.b1C 1D 1hE%ue|!445 $ e er   