
    |;3h%                        d Z ddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZ ddlmZ ddlmZmZ ddddddde
e   d	e	e
e      d
e	e   de	e   de	ej(                     de	e   dej                  fdZ	 	 	 ddej(                  deeeeef         ded	e	e
e      de	eej                        de	e   dej                  fdZ	 dde
e   dedee   fdZy)zBase implementation.    N)ListOptionalSequenceSetUnion   )
_staggered)AddrInfoTypeSocketFactoryType)local_addr_infoshappy_eyeballs_delay
interleaveloopsocket_factory
addr_infosr   r   r   r   r   returnc          	        K   |xst        j                         t        |       dk(  }||d}|r|st        | |      } d}g ||r"| D ]  }	 t	        |d       d{   } n| nzt               	 t        j                  fd| D        |       d{   \  }}	}	D ]9  }
|
|ust        j                  t              5  |
j                          ddd       ; d|D cg c]  }|D ]  }|  }}}	 |d   }t        |      dk(  r|t        |      t        fd|D              r|dj                  dj!                  d |D                    }t#        |t              r,|j$                  t        fd	|D              r9t        |      t#        |t
              rt        d
 |D              rt        |      t        |      |S 7 q# t
        t        f$ r Y w xY w7 P# 1 sw Y   RxY w# D ]E  }
|
|ust        j                  t              5  |
j                          ddd       ;# 1 sw Y   DxY w dw xY wc c}}w # d}dw xY ww)aM  
    Connect to a TCP server.

    Create a socket connection to a specified destination.  The
    destination is specified as a list of AddrInfoType tuples as
    returned from getaddrinfo().

    The arguments are, in order:

    * ``family``: the address family, e.g. ``socket.AF_INET`` or
        ``socket.AF_INET6``.
    * ``type``: the socket type, e.g. ``socket.SOCK_STREAM`` or
        ``socket.SOCK_DGRAM``.
    * ``proto``: the protocol, e.g. ``socket.IPPROTO_TCP`` or
        ``socket.IPPROTO_UDP``.
    * ``canonname``: the canonical name of the address, e.g.
        ``"www.python.org"``.
    * ``sockaddr``: the socket address

    This method is a coroutine which will try to establish the connection
    in the background. When successful, the coroutine returns a
    socket.

    The expected use case is to use this method in conjunction with
    loop.create_connection() to establish a connection to a server::

            socket = await start_connection(addr_infos)
            transport, protocol = await loop.create_connection(
                MyProtocol, sock=socket, ...)
    r   Nc           
   3   \   K   | ]#  }t        j                  t        |       % y wN)	functoolspartial_connect_sock).0addrinfocurrent_loop
exceptionsr   open_socketsr   s     U/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/aiohappyeyeballs/impl.py	<genexpr>z#start_connection.<locals>.<genexpr>X   s;       ! %%%$" ($&s   ),r   c              3   :   K   | ]  }t        |      k(    y wr   str)r   excmodels     r   r   z#start_connection.<locals>.<genexpr>~   s     CSs3x5(Cs   zMultiple exceptions: {}z, c              3   2   K   | ]  }t        |        y wr   r!   r   r#   s     r   r   z#start_connection.<locals>.<genexpr>   s     A3c#hAs   c              3   `   K   | ]%  }t        |t              xr |j                  k(   ' y wr   )
isinstanceOSErrorerrno)r   r#   first_errnos     r   r   z#start_connection.<locals>.<genexpr>   s1       #30MSYY+5MMs   +.c              3   <   K   | ]  }t        |t                y wr   )r(   RuntimeErrorr&   s     r   r   z#start_connection.<locals>.<genexpr>   s      G69JsL1Gs   )asyncioget_running_looplen_interleave_addrinfosr   r-   r)   setr	   staggered_race
contextlibsuppresscloser"   allformatjoinr(   r*   )r   r   r   r   r   r   single_addr_infosockr   _ssubr#   all_exceptionsfirst_exceptionmsgr   r   r+   r$   r   s    `   `          @@@@@r   start_connectionrB      s    N ! L //1:!+'J,>
**:zB
$(D;=J#'7" 	H* $"  	 ,/5	 )88 %/ %  JD!Q0 " "D=#,,W5 "	" ""  L|)3C#sC#C#CC!	,Q/O>"a'%% O,CNCC)) 066IIA.AA
 ow7"1"7"7K #1  &k377>3 G=KG D 's++ cl"
 Kc !'* 
4" " " "D=#,,W5 "	" " ""  L DB "NJs   A
I!G'G(G,I!;&H !G1"H *	I!4I!G4I!1II!CI I!GG.*I!-G..I!1H 4G>	9I!
II%H?	6	I?II	I!II!r   	addr_infor   c                   K   g }|j                  |       |\  }}}	}
}d}	 |	 ||      }nt        j                  |||	      }||j                  |       |j                  d       |G|D ]!  \  }}
}
}
}||k7  r	 |j	                  |        n" |r|j                         t        d|d      | j                  ||       d{    |dx}}S # t
        $ rU}d|d|j                  xs dj                          }t        |j                  |      }|j                  |       Y d}~d}~ww xY w7 k# t        t
        f$ ra}|j                  |       |H||j                  |       	 |j                           # t
        $ r}|j                  |        d}~ww xY w d}~w |H||j                  |       	 |j                           # t
        $ r}|j                  |        d}~ww xY w xY w# dx}}w xY ww)	aq  
    Create, bind and connect one socket.

    If open_sockets is passed, add the socket to the set of open sockets.
    Any failure caught here will remove the socket from the set and close it.

    Callers can use this set to close any sockets that are not the winner
    of all staggered tasks in the result there are runner up sockets aka
    multiple winners.
    N)familytypeprotoFz*error while attempting to bind on address z:  z&no matching local address with family=z found)appendsocketaddsetblockingbindr)   strerrorlowerr*   popsock_connectr-   remover6   )r   r   rC   r   r   r   my_exceptionsrE   type_rG   r<   addressr;   lfamilyladdrr#   rA   es                     r   r   r      sH    $ 9;Mm$'0$FE5!WD5*%!),D==U%HD#T"'+; U'Aq%f$
.IIe$U  !'++--!$KF9F"STTg.... &*)
]K  .##()2LL.B5578: 
 "#))S1C!((--. 	/'" 
S!'##D)

 	  $$Q' 		'##D)

 	  $$Q' 	%))
]s   G;AD4 <C9D4 D2D4 G;	D/AD*%D4 *D//D4 4G/&F*E;:F;	FFFFG/:G
G/	G+G&&G++G//G2 2G88G;	addrinfosfirst_address_family_countc                    t        j                         }| D ]$  }|d   }||vrg ||<   ||   j                  |       & t        |j	                               }g }|dkD  r%|j                  |d   d|dz
          |d   d|dz
  = |j                  d t        j                  j                  t        j                  |       D               |S )z-Interleave list of addrinfo tuples by family.r   r   Nc              3   $   K   | ]  }|| 
 y wr    )r   as     r   r   z(_interleave_addrinfos.<locals>.<genexpr>   s      = 	
s   )
collectionsOrderedDictrI   listvaluesextend	itertoolschainfrom_iterablezip_longest)rY   rZ   addrinfos_by_familyaddrrE   addrinfos_lists	reordereds          r   r1   r1      s     	!   1a,,*,'F#**40	1
 .5578O$&I!A%+,L.H1.LMNA?!;a!??@ ..y/D/Do/VW 
     )NNN)r   )__doc__r.   r_   r4   r   rd   rJ   typingr   r   r   r   r   rH   r	   typesr
   r   floatintAbstractEventLooprB   r)   r-   r   r1   r]   rl   r   <module>rs      sz          7 7  2 :>,0 $0426K&K x56K #5/	K
 K 7,,
-K ./K ]]Kd :>1526K*

#
#K*T% 5678K* K* x56	K*
 3v}}-.K* ./K* ]]K*^ JK%CF	,rl   