
    fy                        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 ddlm	Z	m
Z
mZ ddlmZ ej                  dk  rddlZej                   ej"                  _        dddddd	ee   d
e
ee      de
e   de
e   de
ej(                     dej
                  fdZ	 ddej(                  de	e	e      ded
e
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)	staggered)ListOptionalSequence   )AddrInfoType)         )local_addr_infoshappy_eyeballs_delay
interleaveloop
addr_infosr   r   r   r   returnc                  K   |xst        j                         t        |       dk(  }||d}|r|st        | |      } d}g ||r | D ]  }	 t	        |       d{   } n1 n/t        j                  f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                    }|j                  t        fd
|D              rt        |      t        |      |S 7 # t
        $ r Y w xY w7 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   X   K   | ]!  }t        j                  t        |       # y wN)	functoolspartial_connect_sock).0addrinfocurrent_loop
exceptionsr   s     T/opt/lhia/ganansol/python/venv/lib/python3.12/site-packages/aiohappyeyeballs/impl.py	<genexpr>z#start_connection.<locals>.<genexpr>Y   s2        !!!<XGWs   '*)r   r   c              3   :   K   | ]  }t        |      k(    y wr   str)r   excmodels     r   r   z#start_connection.<locals>.<genexpr>l   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>q   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>v   s1       sG,Ik1IIs   +.)asyncioget_running_looplen_interleave_addrinfosr   r&   r   staggered_racer    allformatjoinr'   )r   r   r   r   r   single_addr_infosockr   _subr!   all_exceptionsfirst_exceptionmsgr   r   r(   r"   s    `            @@@@r   start_connectionr8      s    L ! L //1:!+'J,>
**:zB
$(D&(J#'7" 	H* *h8H  	 %33 !+	 !	
 	

a |)3C#sC#C#CC	,Q/O>"a'%% O,CNCC)) 066IIA.AA
 .33 -  "+s33cl"
 K_  	
 D2 "NJss   A
E/E#E$E(*E/EE/"E 2E/6BE& 
E/E	EE/EE/ E/&E,,E/r   	addr_infoc                   K   g }|j                  |       |\  }}}}}	d}
	 t        j                  |||      }
|
j                  d       |G|D ]!  \  }}}}}||k7  r	 |
j                  |        n" |r|j                         t	        d|d      | j                  |
|	       d{    |
dx}}S # t        $ rQ}d|d|j
                  j                          }t	        |j                  |      }|j                  |       Y d}~d}~ww xY w7 g# t        $ r)}|j                  |       |
|
j                           d}~w |
|
j                           xY w# dx}}w xY ww)z$Create, bind and connect one socket.N)familytypeprotoFz*error while attempting to bind on address z: z&no matching local address with family=z found)appendsocketsetblockingbindr&   strerrorlowerr'   popsock_connectclose)r   r   r9   r   my_exceptionsr;   type_r=   r3   addressr2   lfamilyladdrr!   r7   s                  r   r   r      s     $&Mm$'0$FE5!WD$*}}FeD'+; U'Aq%f$
.IIe$U  !'++--!$KF9F"STTg... &*)
]3  .##()2<<--/02 
 "#))S1C!((--. 	/ S!JJLJJL%))
]sk   E#<D B3/9D (D)D .E#3	D<ADD DD 	E$D??EE E  E#	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OrderedDictr>   listvaluesextend	itertoolschainfrom_iterablezip_longest)rL   rM   addrinfos_by_familyaddrr;   addrinfos_lists	reordereds          r   r,   r,      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 
     r   )r   )__doc__r)   rR   r   rW   r?   sysr   typingr   r   r   typesr   version_infoasyncio.futuresTimeoutErrorfuturesfloatintAbstractEventLoopr8   r&   r   r,   rP   r_   r   <module>rk      sJ         
  + + i #*#7#7GOO  :>,0 $04g&g x56g #5/	g
 g 7,,
-g ]]g\ :>	/*

#
#/*T']#/* /* x56	/*
 ]]/*f JK%CF	,r_   