
    ∋d!                        d dl mZ d dlZd dlZd dlmZ d dlmZ d'd(dZd)dZ	d*dZ
	 d+d,dZd+d-dZd'd.dZd*dZd*dZd*dZd/d#Z	 	 	 	 	 	 	 d0d1d%Z	 	 	 	 	 	 	 d0d2d&ZdS )3    )annotationsN)registry)get_ip_interfaceFaddrstrstrictboolreturntuple[str, str]c                   t          | t                    st          d| j        j        z            |                     d          \  }}}|r|sd| z  }t          |          |st          j        	                    d          }||fS )z
    Split address into its scheme and scheme-dependent location string.

    >>> parse_address('tcp://127.0.0.1')
    ('tcp', '127.0.0.1')

    If strict is set to true the address must have a scheme.
    zexpected str, got %r://zKInvalid url scheme. Must include protocol like tcp://localhost:8000. Got %szdistributed.comm.default-scheme)

isinstancer   	TypeError	__class____name__
rpartition
ValueErrordaskconfigget)r   r   schemeseplocmsgs         ;lib/python3.11/site-packages/distributed/comm/addressing.pyparse_addressr      s     dC   J.1HHIIIu--FC c  	
 oo D!BCC3;    r   r   c                    |  d| S )zb
    Undo parse_address().

    >>> unparse_address('tcp', '127.0.0.1')
    'tcp://127.0.0.1'
    r    )r   r   s     r   unparse_addressr    #   s     r   c                .    t          t          |            S )z
    Canonicalize address, adding a default scheme if necessary.

    >>> normalize_address('tls://[::1]')
    'tls://[::1]'
    >>> normalize_address('[::1]')
    'tcp://[::1]'
    )r    r   )r   s    r   normalize_addressr"   -   s     M$//00r   addressstr | tuple[str, int]default_portstr | int | Nonetuple[str, int]c                    t           t                    r S  fd} fd}d v r                     d          \  }                      d          rd dd                             d          \  }}}|s
 |             |s |            }n`|                    d          s
 |             |dd         }n6                     d          \  }}}|s|} |            }nd|v r
 |             |t          |          fS )	zB
    Parse an endpoint address given in the form "host:port".
    c                 *    t          d d          )Nzinvalid address z'; maybe: ipv6 needs brackets like [::1]r   )r#   s   r   _failzparse_host_port.<locals>._failB   s#    QwQQQ
 
 	
r   c                 0    t          d           S )Nzmissing port number in address r*   )r#   r%   s   r   _defaultz!parse_host_port.<locals>._defaultG   s&    JwJJKKKr   r   [   N]:)r   tuplesplit
startswith	partitionr   int)	r#   r%   r+   r-   _hostr   tailports	   ``       r   parse_host_portr;   9   s^    '5!! 
 
 
 
 

     
 ]]5))
7#  "!""+//44c4 	EGGG 	8::DD??3'' 8DD ",,S11c4 	D8::DDD[[EGGGT?r   r8   r:   
int | Nonec                V    d| v r|                      d          sd|  d} ||  d| S | S )z!
    Undo parse_host_port().
    r1   r.   r0   )r4   )r8   r:   s     r   unparse_host_portr>   f   sI     d{{4??3//{4{{{r   c                    t          | |          \  }}t          j        |          }	 |                    |          S # t          $ r t          d|           w xY w)a[  
    Get a (host, port) tuple out of the given address.
    For definition of strict check parse_address
    ValueError is raised if the address scheme doesn't allow extracting
    the requested information.

    >>> get_address_host_port('tcp://1.2.3.4:80')
    ('1.2.3.4', 80)
    >>> get_address_host_port('tcp://[::1]:80')
    ('::1', 80)
    )r   z4don't know how to extract host and port for address )r   r   get_backendget_address_host_portNotImplementedErrorr   )r   r   r   r   backends        r   rA   rA   r   s{      V444KFC"6**G
,,S111 
 
 
K4KK
 
 	

s	   ? Ac                x    t          |           \  }}t          j        |          }|                    |          S )a  
    Return a hostname / IP address identifying the machine this address
    is located on.

    In contrast to get_address_host_port(), this function should always
    succeed for well-formed addresses.

    >>> get_address_host('tcp://1.2.3.4:80')
    '1.2.3.4'
    )r   r   r@   get_address_hostr   r   r   rC   s       r   rE   rE      s9      %%KFC"6**G##C(((r   c                    t          |           \  }}t          j        |          }t          ||                    |                    S )ah  
    Get a local listening address suitable for reaching *addr*.

    For instance, trying to reach an external TCP address will return
    a local TCP address that's routable to that external address.

    >>> get_local_address_for('tcp://8.8.8.8:1234')
    'tcp://192.168.1.68'
    >>> get_local_address_for('tcp://127.0.0.1:1234')
    'tcp://127.0.0.1'
    )r   r   r@   r    get_local_address_forrF   s       r   rH   rH      sC      %%KFC"6**G67#@#@#E#EFFFr   c                    t          |           \  }}t          j        |          }t          ||                    |                    S )a  
    Apply scheme-specific address resolution to *addr*, replacing
    all symbolic references with concrete location specifiers.

    In practice, this can mean hostnames are resolved to IP addresses.

    >>> resolve_address('tcp://localhost:8786')
    'tcp://127.0.0.1:8786'
    )r   r   r@   r    resolve_addressrF   s       r   rJ   rJ      sC      %%KFC"6**G67#:#:3#?#?@@@r   host_arg
str | Noneport_argr6   c                    t          | pd          \  }}t          |||n|          \  }}|dk    r*|r(|t          |          k    rt          d|  d|           t	          ||          }t          ||          }|S )zF
    Process the *host* and *port* CLI options.
    Return a URI.
     Nr   z)port number given twice in options: host z
 and port )r   r;   r6   r   r>   r    )rK   rM   r%   r   r   r8   r:   r   s           r   uri_from_host_portrP      s      B//KFC -XX< JD$
 qyyXy$#h--"7"733 3(03 3
 
 	

 D$
'
'C63''DKr   listc           
         d }t          d | |||fD                       r)fdt          t          || |||f           D             S t          | |||          gS )a  Get a list of addresses if the inputs are lists

    This is like ``address_from_user_args`` except that it also accepts lists
    for some of the arguments.  If these arguments are lists then it will map
    over them accordingly.

    Examples
    --------
    >>> addresses_from_user_args(host="127.0.0.1", protocol=["inproc", "tcp"])
    ["inproc://127.0.0.1:", "tcp://127.0.0.1:"]
    c                f    t          | t          t          f          r| S t          j        |           S N)r   r2   rQ   	itertoolsrepeat)objs    r   listifyz)addresses_from_user_args.<locals>.listify   s.    cE4=)) 	)J#C(((r   c              3  N   K   | ] }t          |t          t          f          V  !d S rT   )r   r2   rQ   ).0xs     r   	<genexpr>z+addresses_from_user_args.<locals>.<genexpr>   s0      
S
SA:a%''
S
S
S
S
S
Sr   c                F    g | ]\  }}}}t          ||||           S ))r8   r:   	interfaceprotocolpeersecurityr%   )address_from_user_args)rZ   hpiprr%   r`   ra   s        r   
<listcomp>z,addresses_from_user_args.<locals>.<listcomp>   sW     
 
 
 1a #!)  
 
 
r   )anyzipmaprb   )r8   r:   r^   r_   r`   ra   r%   rX   s       ``` r   addresses_from_user_argsrk      s    *) ) ) 
S
S$i1R
S
S
SSS 

 
 
 
 
 
  #C$i1R$S$ST
 
 
 	
 #dIxx 
 	
r   c                   |r|j         r|sd}|r.|                    d          r|                    d          \  }}}|dk    r| s|s|rt          d          dS |r"| rt          d||           t	          |          } |r| rd| vr|dz   | z   } | s|rt          | ||          }nd}|r!|dz   |                    d          d         z   }|S )	z?Get an address to listen on from common user provided argumentstlsr   inplacez=Can not specify inproc protocol and host or port or interfacez	inproc://z'Can not specify both interface and hostrO   )require_encryptionendswithr   r   r   rP   r3   )	r8   r:   r^   r_   r`   ra   r%   r7   r   s	            r   rb   rb     sB     H/   4H%%e,, 4!,,U33!Q9 	4 	9 	O   ; / 	/F	SWXXX#I..D 'D 'U$..%$& t !$l;; 8%$**U"3"3B"77Kr   )F)r   r   r   r	   r
   r   )r   r   r   r   r
   r   )r   r   r
   r   rT   )r#   r$   r%   r&   r
   r'   )r8   r   r:   r<   r
   r   )r   r   r   r	   r
   r'   )rK   rL   rM   rL   r%   r6   r
   r   )NNNNNNr   )r
   rQ   )r
   r   )
__future__r   rU   r   distributed.commr   distributed.utilsr   r   r    r"   r;   r>   rA   rE   rH   rJ   rP   rk   rb   r   r   r   <module>ru      s   " " " " " "      % % % % % % . . . . . .    0   	1 	1 	1 	1 FJ* * * * *Z	 	 	 	 	
 
 
 
 
,) ) ) ) G G G G"A A A A   < 
		-
 -
 -
 -
 -
b 
		* * * * * * *r   