
    >fh]              	       $   d 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
 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d
eeef   d	ee   dee   defdZdee
   dee   fdZy)zUtility functions.    N)Iterable)OptionalUnion)AnyKey)Keysreturnc                  f   d} 	 t        j                   t         j                  t         j                        } | j                  d       	 | j                         d   }	 | j                          |S # t        $ r | r| j                          	 t        j                   t         j                  t         j                        } | j                  d       n*# t        $ r | r| j                          t        d      w xY wY w xY w# t        $ r}t        d| d      d}~ww xY w# | j                          w xY w)zqDetermines a free port using sockets.

    First try IPv4, but use IPv6 if it can't bind (IPv6-only system).
    N)	127.0.0.1r   )z::1r   z5Can't find free port (Unable to bind to IPv4 or IPv6)   zCan't find free port: ())
socketAF_INETSOCK_STREAMbindOSErrorcloseAF_INET6RuntimeErrorgetsockname	Exception)free_socketportes      R/var/www/zara/venv/lib/python3.12/site-packages/selenium/webdriver/common/utils.py	free_portr      s   
 KXmmFNNF4F4FG)*++-a0 	K#  
X	X --9K9KLKZ( 	X!!#VWW	X )
X  ;4QCq9::; 	sO   AA. C> .C;
ACC;'C55C;:C;>	DDDD D0hostr   c                 V   	 t        j                  | d      }d}|D ]q  \  }}}}}d}|rt        |t	        |d               }|r#|t         j
                  k(  rt	        |d         c S |sM|rP|t         j                  k(  sdt	        |d         }s |S # t         j                  $ r Y yw xY w)as  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 - hostname
        - port - 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_connectablestrr   r   )r   r   	addrinfosipfamily_sockaddrconnectables           r   find_connectable_ipr(   =   s    &&&tT2	 
B%. "!1a(s8A;/?@K6V^^3x{##rf&?Xa[!B" I ?? s   B B('B(c                 J    d| v r| j                  d      sd|  d| S |  d| 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 - hostname or IP
        - port - port number
    :[z]:)
startswith)r   r   s     r   join_host_portr-   b   s:     d{4??3/4&4&!!V1TF    c                 t   d}	 t        j                  || fd      }d}|r0	 |j                  t         j                         |j                          |S # t        $ r d}Y Aw xY w# t
        $ r Y .w xY w# |rA	 |j                  t         j                         n# t
        $ r Y nw xY w|j                          w w xY w)zTries to connect to the server at port to see if it is running.

    :Args:
        - port - port number
        - host - hostname or IP
    Nr   TF)r   create_connection_is_connectable_exceptionsshutdown	SHUT_RDWRr   r   )r   r   socket_results       r   r    r    q   s     G**D$<;   !1!12 MMOM &      !1!12 MMO sX   A A# A A2 A  A2 #	A/.A/2B76BB7	B"B7!B""B7schemec                     	 t         j                  j                  | d| d|  d      5 }|j                         dk(  cddd       S # 1 sw Y   yxY w# t        $ r Y yw xY w)zSends a request to the HTTP server at the /status endpoint to see if it
    responds successfully.

    :Args:
        - port - port number
        - host - hostname or IP
        - scheme - URL scheme
    z://r*   z/status   NF)urllibrequesturlopengetcoder   )r   r   r6   ress       r   is_url_connectabler>      sb    ^^##vhc$qg$FG 	(3;;=C'	( 	( 	( s-   (A A	A AA A 	AAvaluec                     g }| D ]o  }t        |t              r|j                  t        |             .t        |t        t
        f      r|j                  t        |             _|j                  |       q |S )z7Processes the values that will be typed in the element.)
isinstancer   appendr!   intfloatextend)r?   
charactersvals      r   keys_to_typingrH      sh    J #c4 c#h'c5\*c#h'c"# r.   )N)	localhost)r
   http)__doc__r   urllib.requestr9   collections.abcr   typingr   r   selenium.typesr   selenium.webdriver.common.keysr   errorConnectionResetErrorr1   rC   r   r!   bytes	bytearrayr(   r-   boolr    r>   listrH    r.   r   <module>rX      s  $    $ " ! /$ll,@A 3 <"eC	4$?@ "QT "aijman "J C C  HSM D 2 &"
S/
3- SM 
	((6* tCy r.   