a
    5ñ»j  ã                   @   sò   d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ejefZed	œd
d„Zdeeeedf ee ee dœdd„Zeeedœdd„Zdeee edœdd„Zeeef edœdd„Zee ee dœdd„ZdS )zThe Utils methods.é    N)ÚIterable)ÚList)ÚOptional)ÚUnion)ÚAnyKey)ÚKeys)Úreturnc                  C   s<   t   t jt j¡} |  d¡ |  d¡ |  ¡ d }|  ¡  |S )z%Determines a free port using sockets.)z	127.0.0.1r   é   é   )ÚsocketÚAF_INETÚSOCK_STREAMÚbindÚlistenÚgetsocknameÚclose)Zfree_socketÚport© r   úEE:\soccer\ml_env\Lib\site-packages\selenium/webdriver/common/utils.pyÚ	free_port   s    

r   )Úhostr   r   c                 C   sŽ   zt  | d¡}W n t jy&   Y dS 0 d}|D ]X\}}}}}d}|rTt||d ƒ}|rn|t jkrn|d   S |r0|s0|t jkr0|d }q0|S )a€  Resolve a hostname to an IP, preferring IPv4 addresses.

    We prefer IPv4 so that we don't change behavior from previous IPv4-only
    implementations, and because some drivers (e.g., FirefoxDriver) do not
    support IPv6 connections.

    If the optional port number is provided, only IPs that listen on the given
    port are considered.

    :Args:
        - host - A hostname.
        - port - Optional port number.

    :Returns:
        A single IP address, as a string. If any IPv4 address is found, one is
        returned. Otherwise, if any IPv6 address is found, one is returned. If
        neither, then None is returned.
    NTr   )r   ÚgetaddrinfoÚgaierrorÚis_connectabler   ÚAF_INET6)r   r   Z	addrinfosÚipÚfamilyÚ_ZsockaddrZconnectabler   r   r   Úfind_connectable_ip)   s    
r   c                 C   s0   d| v r"|   d¡s"d| › d|› �S | › d|› �S )zùJoins a hostname and port together.

    This is a minimal implementation intended to cope with IPv6 literals. For
    example, _join_host_port('::1', 80) == '[::1]:80'.

    :Args:
        - host - A hostname.
        - port - An integer port.
    ú:ú[z]:)Ú
startswith)r   r   r   r   r   Újoin_host_portN   s    
r"   Ú	localhost)r   r   r   c                 C   s    d}zdzt  || fd¡}d}W n ty4   d}Y n0 W |rœz| t j¡ W n ty^   Y n0 | ¡  n2|ršz| t j¡ W n ty�   Y n0 | ¡  0 |S )zsTries to connect to the server at port to see if it is running.

    :Args:
     - port - The port to connect.
    Nr
   TF)r   Úcreate_connectionÚ_is_connectable_exceptionsÚshutdownÚ	SHUT_RDWRÚ	Exceptionr   )r   r   Zsocket_Úresultr   r   r   r   ]   s&    
û
r   )r   r   c                 C   sF   ddl m} z | d| › d�¡}| ¡ dkW S  ty@   Y dS 0 dS )z¢Tries to connect to the HTTP server at /status path and specified port
    to see if it responds successfully.

    :Args:
     - port - The port to connect.
    r   )Úrequestzhttp://127.0.0.1:z/statuséÈ   FN)Úurllibr*   ÚurlopenÚgetcoder(   )r   Zurl_requestÚresr   r   r   Úis_url_connectables   s    r0   )Úvaluer   c                 C   sP   g }| D ]B}t |tƒr"| |¡ qt |ttfƒr@| t|ƒ¡ q| |¡ q|S )z7Processes the values that will be typed in the element.)Ú
isinstancer   ÚappendÚintÚfloatÚextendÚstr)r1   Ú
charactersÚvalr   r   r   Úkeys_to_typingƒ   s    
r:   )N)r#   )Ú__doc__r   Útypingr   r   r   r   Zselenium.typesr   Zselenium.webdriver.common.keysr   ÚerrorÚConnectionResetErrorr%   r4   r   r7   ÚbytesÚ	bytearrayr   r"   Úboolr   r0   r:   r   r   r   r   Ú<module>   s   

(%