
    hgz                         d Z ddlmZmZmZmZ ddlZddlmZ ddl	m
Z
 ej        efZdefdZddeeeedf         d	ee         dee         fd
Zded	edefdZdd	edee         defdZd	eeef         defdZdee         dee         fdZdS )z
The Utils methods.
    )IterableListOptionalUnionN)AnyKey)Keysreturnc                     t          j         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)free_socketports     X/var/www/fb-scrape/myenv/lib/python3.11/site-packages/selenium/webdriver/common/utils.py	free_portr       sp     -0BCCK%&&&q''))!,DK    hostr   c                    	 t          j        | d          }n# t           j        $ r Y dS w xY wd}|D ]Z\  }}}}}d}|rt          ||d                   }|r|t           j        k    r
|d         c S |r|s|t           j        k    r|d         }[|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   	addrinfosipfamily_sockaddrconnectables           r   find_connectable_ipr%   ,   s    (&tT22		?   tt 
B%.  !1a 	<(x{;;K 	6V^33A; 	r 	f&?&?!BIs    ++c                 P    d| v r|                      d          sd| |fz  S d| |fz  S )zJoins 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[%s]:%dz%s:%d)
startswith)r   r   s     r   join_host_portr*   R   s;     d{{4??3//{D$<''dD\!!r   	localhostc                     d}	 t          j        || fd          }d}n# t          $ r d}Y nw xY w|r|                                 n# |r|                                 w w xY w|S )zx
    Tries 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_exceptionsr   )r   r   socket_results       r   r   r   b   s     G*D$<;;%     	MMOOO  	MMOOOO	Ms!    A -A -A A c                     ddl m} 	 |                    d| z            }|                                dk    rdS dS # t          $ r Y dS w xY w)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:%s/status   TF)urllibr2   urlopengetcode	Exception)r   url_requestress      r   is_url_connectabler:   u   ss     .-----!!">"EFF;;==C45   uus   0< 
A
	A
valuec                    g }| D ]}t          |t                    r|                    |           -t          |t                    st          |t                    rJt          |          }t          t          |                    D ]}|                    ||                    t          t          |                    D ]}|                    ||                    |S )z7Processes the values that will be typed in the element.)
isinstancer   appendintfloatstrrangelen)r;   typingvalis       r   keys_to_typingrG      s    F 	& 	&c4   	&MM#S!! 	&ZU%;%; 	&c((C3s88__ & &c!f%%%%& 3s88__ & &c!f%%%%&Mr   )N)r+   )__doc__rD   r   r   r   r   r   selenium.typesr   selenium.webdriver.common.keysr   errorConnectionResetErrorr.   r?   r   rA   bytes	bytearrayr%   r*   boolr   r:   rG    r   r   <module>rQ      s  $  3 2 2 2 2 2 2 2 2 2 2 2  ! ! ! ! ! ! / / / / / / %l,@A 	3 	 	 	 	# #eC	4$?@ #QT #aijman # # # #L" "C "C " " " "   HSM D    &U38_     ((6* tCy      r   