Ë
    g^(hÆ   ã                   ó
  — d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dlm	Z	m
Z
 d dlmZmZmZmZ dgZdedeeef   fd„Zd	edee   fd
„Zdee   dedeeef   fd„Zdedefd„Zdeeeeef   f   ddfd„Z G d„ d«      Zy)é    N)Ú	timedelta)ÚEventÚThread)ÚAnyÚCallableÚOptionalÚUnionÚparse_rendezvous_endpointÚ
config_strÚreturnc                 ó   — i }| j                  «       } | s|S | j                  d«      }|D ]a  }|j                  dd«      ^}}|j                  «       }|st        d«      ‚|r|d   j                  «       }nd}|st        d|› d�«      ‚|||<   Œc |S )	z§Extract 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          úh/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/distributed/elastic/rendezvous/utils.pyÚ_parse_rendezvous_configr      s»   € ð  €Fà×!Ñ!Ó#€JÙØˆà×!Ñ! #Ó&€JØò ˆØ—x‘x  QÓ'ˆˆˆfà�i‰i‹kˆÙÜð7óð ñ Ø˜1‘I—O‘OÓ%‰EàˆEÙÜØ7¸°uÐ<ZÐ[óð ð ˆˆsŠð)ð* €Mó    Úport_strc                 óJ   — | r!t        j                  d| «      rt        | «      S y)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   € á”B—H‘H˜_¨hÔ7Ü�8‹}ÐØr   ÚendpointÚdefault_portc                 óŒ  — | �| j                  «       } | sd|fS | d   dk(  r| d   dk(  r	| gg ¢­^}}n| j                  dd«      ^}}t        |«      dkD  r|d   dk(  r|d   dk(  r|dd }t        |«      dk(  r$t        |d   «      }|�|dk\  rt	        d	| › d
�«      ‚|}t        j                  d|«      st	        d| › d�«      ‚||fS )a4  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Ò˜h r™l¨cÒ1Ø�m ‘mˆˆ‰tà—o‘o c¨1Ó-ˆˆˆtô ˆ4ƒy�1‚}˜˜a™ Cš¨D°©H¸ªOØ�A�bˆzˆä
ˆ4ƒy�A‚~Ü˜t A™wÓ'ˆØˆ<˜4 5š=ÜØ>¸x¸jð I'ð 'óð ð
 ˆä�8‰8�N DÔ)ÜØ7¸°zð B;ð ;ó
ð 	
ð
 �ˆ:Ðr   r-   c                 ó~  — | dk(  ry	 t        j                  | «      }|r|j                  ry	 t	        j
                  | dt        j                  t        j                  ¬«      }|D �cg c]
  }|d   d   ‘Œ }}t	        j                  «       }| |k(  ryt	        j
                  |dt        j                  t        j                  ¬«      }|D ]5  }|d   r
|d   | k(  r y|r|d   d   t        |«      k(  r y|d   d   |v sŒ5 y y# t        $ r d}Y Œñw xY w# t        t        j                  f$ r}g }Y d}~ŒÐd}~ww xY wc c}w )	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   sS  € ð ˆ{ÒØðÜ×#Ñ# DÓ)ˆñ �× Ò ØðÜ×+Ñ+Ø�$œf×0Ñ0¼×8KÑ8Kô
ˆð @NÖN¨^�N 1Ñ% aÓ(ÐN€LÐNä×"Ñ"Ó$€IØˆyÒØä×"Ñ"Ø�4œv×1Ñ1¼×9LÑ9Lô€Ið ò ˆ	à�QŠ<˜I a™L¨DÒ0Ùñ �I˜a‘L ‘O¤s¨4£yÒ0Ùð �Q‰<˜‰?˜lÒ*Ùðð øôI ò ØŠðûô œŸ™Ð(ò Ø�ûðüò Os.   ˆD ­5D Á&D:ÄDÄDÄD7Ä+D2Ä2D7Úsecondsc                 ó~   — t        | t        «      rt        j                  | Ž } | dk\  rt	        j
                  | «       yy)z×Suspend 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{®Gáz„?N)Ú
isinstanceÚtupleÚrandomÚuniformÚtimeÚsleep)rH   s    r   Ú_delayrP   ¨   s4   € ô �'œ5Ô!Ü—.‘. 'Ð*ˆà�$‚Ü�
‰
�7Õð r   c            
       óô   — e Zd ZU dZ G d„ d«      Zee   ed<   ee   ed<   ee	j                     ed<   eed<   ded	ed
   dededdf
d„Zedee   fd„«       Zdeddfd„Zdd„Zdd„Zedd„«       Zed„ «       Zy)Ú_PeriodicTimerzËRepresent a timer that periodically runs a specified function.

    Args:
        interval:
            The interval, in seconds, between each run.
        function:
            The function to run.
    c                   óZ   — e Zd ZU eed<   ed   ed<   eedf   ed<   ee	ef   ed<   e
ed<   y)	ú_PeriodicTimer._ContextÚinterval©.NÚfunction.ÚargsÚkwargsÚ
stop_eventN)Ú__name__Ú
__module__Ú__qualname__ÚfloatÚ__annotations__r   rK   r   Údictr>   r   © r   r   Ú_ContextrT   Ã   s4   … Ø‹Ø˜9Ñ%Ó%Ø�C˜�H‰oÓØ�S˜#�X‘ÓØÔr   rb   Ú_nameÚ_threadÚ
_finalizerÚ_ctxrU   rW   rV   rX   rY   r   Nc                 ó>  — d | _         | j                  «       | _        |j                  «       | j                  _        || j                  _        |xs d| j                  _        |xs i | j                  _        t        «       | j                  _	        d | _
        d | _        y )Nra   )rc   rb   rf   Útotal_secondsrU   rW   rX   rY   r   rZ   rd   re   )ÚselfrU   rW   rX   rY   s        r   Ú__init__z_PeriodicTimer.__init__Ñ   st   € ð ˆŒ
à—M‘M“OˆŒ	Ø%×3Ñ3Ó5ˆ�	‰	ÔØ%ˆ�	‰	ÔØš ˆ�	‰	ŒØ!š< Rˆ�	‰	ÔÜ$›wˆ�	‰	ÔàˆŒØˆ�r   c                 ó   — | j                   S )zGet the name of the timer.)rc   ©ri   s    r   Únamez_PeriodicTimer.nameä   s   € ð �z‰zÐr   rm   c                 ó@   — | j                   rt        d«      ‚|| _        y)z¨Set 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)rd   ÚRuntimeErrorrc   )ri   rm   s     r   Úset_namez_PeriodicTimer.set_nameé   s   € ð �<Š<ÜÐ?Ó@Ð@àˆ�
r   c                 ó€  — | j                   rt        d«      ‚t        | j                  | j                  xs d| j
                  fd¬«      | _         t        j                  | | j                  | j                   | j
                  j                  «      | _
        d| j                  _        | j                   j                  «        y)zStart the timer.ro   ÚPeriodicTimerT)Útargetrm   rX   ÚdaemonFN)rd   rp   r   Ú_runrc   rf   ÚweakrefÚfinalizeÚ_stop_threadrZ   re   ÚatexitÚstartrl   s    r   r{   z_PeriodicTimer.startô   s�   € à�<Š<ÜÐ?Ó@Ð@äØ—9‘9Ø—‘Ò.˜Ø—)‘)�Øô	
ˆŒô "×*Ñ*Ø�$×#Ñ# T§\¡\°4·9±9×3GÑ3Gó
ˆŒð "'ˆ�‰Ôà�‰×ÑÕr   c                 ó>   — | j                   r| j                  «        yy)z'Stop the timer at the next opportunity.N)re   rl   s    r   Úcancelz_PeriodicTimer.cancel  s   € à�?Š?Ø�O‰OÕð r   c                 óè   — | j                   j                  | j                  «      sM | j                  | j                  i | j
                  ¤Ž | j                   j                  | j                  «      sŒLy y ©N)rZ   ÚwaitrU   rW   rX   rY   )Úctxs    r   rv   z_PeriodicTimer._run  sK   € à—.‘.×%Ñ% c§l¡lÔ3ØˆC�L‰L˜#Ÿ(™(Ð1 c§j¡jÒ1ð —.‘.×%Ñ% c§l¡l×3r   c                 óD   — |j                  «        | j                  «        y r   )ÚsetÚjoin)ÚthreadrZ   s     r   ry   z_PeriodicTimer._stop_thread  s   € à�‰Ôà�‰�r   )r   N)r[   r\   r]   Ú__doc__rb   r   r>   r_   r   rw   rx   r   r   r   rj   Úpropertyrm   rq   r{   r}   Ústaticmethodrv   ry   ra   r   r   rR   rR   ·   sÞ   … ñ÷ñ ð �C‰=ÓØ�fÑÓØ˜×)Ñ)Ñ*Ó*ð ƒNðàðð ˜9Ñ%ðð ð	ð
 ðð 
óð& ð�h˜s‘mò ó ðð	˜Sð 	 Tó 	óó4ð
 ò2ó ð2ð ñó ñr   rR   )r5   rL   r   r8   rN   rw   Údatetimer   Ú	threadingr   r   Útypingr   r   r   r	   Ú__all__r>   r`   r   r!   r"   rK   r
   ÚboolrG   r^   rP   rR   ra   r   r   ú<module>rŽ      sÒ   ðó Û Û 	Û Û Û Ý ß #ß 1Ó 1ð 'Ð
'€ð#¨ð #°°c¸3°h±ó #ðL˜cð  h¨s¡mó ð.Ø�s‰mð.Ø+.ð.à
ˆ3�ˆ8�_ó.ðb1 Cð 1¨Dó 1ðh�E˜%  u¨e |Ñ!4Ð4Ñ5ð ¸$ó ÷eò er   