
    'h                        S r SSKrSSKJr  SSKJrJr  SSKJr  SSK	J
r
  \R                  \4rS\4S jrSS	\\\\S4   S
\\   S\\   4S jjrS	\S
\S\4S jrSS
\S	\\   S\4S jjrS
\\\4   S\4S jrS\\   S\\   4S jrg)zThe Utils methods.    N)Iterable)OptionalUnion)AnyKey)Keysreturnc                  T   Sn  [         R                   " [         R                  [         R                  5      n U R                  S5         U R                  5       S   n U R                  5         U$ ! [         ax    U (       a  U R                  5          [         R                   " [         R                  [         R                  5      n U R                  S5         N! [         a    [        S5      ef = ff = f! [         a  n[        SU S35      eSnAff = f! U R                  5         f = f)ziDetermines a free port using sockets.

First try IPv4, but use IPv6 if it can't bind (IPv6-only system).
N)z	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      h/var/www/home/psychics-availability/venv/lib/python3.13/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::; 	sC   AA/ 	C4 /!C1ACC--C14
D>DDD D'hostr   c                     [         R                  " U S5      nSnU H  u  n    pVSnU(       a  [        U[	        US   5      5      nU(       a$  U[         R
                  :X  a  [	        US   5      s  $ U(       d  M]  U(       a  Mf  U[         R                  :X  d  M|  [	        US   5      nM     U$ ! [         R                   a     gf = f)aL  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_connectablestrr   r   )r   r   	addrinfosipfamily_sockaddrconnectables           r   find_connectable_ipr'   9   s    &&&tT2	 
B%.!1a(s8A;/?@K6V^^3x{##;rrf&?Xa[!B &/ I ?? s   B- -CCc                 X    SU ;   a  U R                  S5      (       d  SU  SU 3$ U  SU 3$ )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]:)
startswith)r   r   s     r   join_host_portr,   ^   s=     d{4??3//4&4&!!V1TF    c                    Sn [         R                  " X4S5      nSnU(       a0   UR                  [         R                  5        UR                  5         U$ ! [         a    Sn NGf = f! [
         a     N0f = f! U(       aB   UR                  [         R                  5        O! [
         a     Of = fUR                  5         f f = f)zgTries 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_RDWRr   r   )r   r   socket_results       r   r   r   m   s     G**D<;   !1!12 MMOM &      !1!12 MMO sX   A A) A&#A9 %A&&A9 )
A65A69CB"!C"
B/,C.B//Cc                     SSK Jn   UR                  SU  S35      nUR                  5       S:H  $ ! [         a     gf = f)zTries 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   F)urllibr6   urlopengetcoder   )r   url_requestress      r   is_url_connectabler=      sI     .!!$5dV7"CD{{}## s   '0 
==valuec                    / nU  H|  n[        U[        5      (       a  UR                  [        U5      5        M4  [        U[        [
        45      (       a  UR                  [        U5      5        Mk  UR                  U5        M~     U$ )z7Processes the values that will be typed in the element.)
isinstancer   appendr    intfloatextend)r>   
charactersvals      r   keys_to_typingrG      si    Jc4  c#h'c5\**c#h'c"  r-   )N)	localhost)__doc__r   collections.abcr   typingr   r   selenium.typesr   selenium.webdriver.common.keysr   errorConnectionResetErrorr0   rB   r   r    bytes	bytearrayr'   r,   boolr   r=   listrG    r-   r   <module>rU      s   "   $ " ! /$ll,@A 3 8"eC	4$?@ "QT "aijman "J C C  HSM D ,U38_   (6* tCy r-   