o
    wOi                     @   s\   d dl Z d dlmZmZmZ dedeeef fddZdee dedeeef fd	d
ZdS )    N)DictOptionalTuple
config_strreturnc                 C   sT   i }| s|S |  d}|D ]}| dd^}}|s!td| d|d ||< q|S )z{
    Extracts key-value pairs from a configuration string that has the format
    <key1>=<value1>,...,<keyN>=<valueN>.
    ,=   zThe 'z+' rendezvous config has no value specified.r   )split
ValueError)r   config
key_valueskvkeyvalues r   Q/home/ubuntu/.local/lib/python3.10/site-packages/torchelastic/rendezvous/utils.py_parse_rendezvous_config   s   
r   endpointdefault_portc                 C   s   | sd|fS |  dd^}}t|dkr;td|d r#t|d }nd}|dks-|dkr:td|  d	|d  d
n|}td|sNtd|  d| d
||fS )z
    Extracts the hostname and the port number from an endpoint string that has
    the format <hostname>:<port>.

    If no hostname can be found, defaults to the loopback address 127.0.0.1.
    z	127.0.0.1:r	   z^[0-9]{1,5}$r   P   i   zThe rendezvous endpoint 'z' has an invalid port number 'z'.z^[\w\.:-]+$zThe rendezvous enpoint 'z' has an invalid hostname ')rsplitlenrematchintr   )r   r   hostnamerestportr   r   r   _parse_hostname_and_port   s$   	r    )	r   typingr   r   r   strr   r   r    r   r   r   r   <module>   s   
