
    Ng                        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 ddl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eef                           ded
e	e
e                  dej        f
dZ	 dde
e         dedee         fdZdS )zBase implementation.    N)ListOptionalSequenceUnion   )
_staggered)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 ||r7| D ]3}	 t	          |           d{V } n# t
          t          f$ r Y 0w xY wn-t          j        fd| D             |           d{V \  }}}|%d D             }		 |	d         }
t          |	          dk    r|
t          |
          t          fd|	D                       r|
d                    d                    d	 |	D                                 }t          |
t                    r3|
j        t          fd
|	D                       rt          |          n=t          |
t
                    r(t          d |	D                       rt          |          t          |          # d}	dw xY w|S )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   R   K   | ]!}t          j        t          |          V  "d S N)	functoolspartial_connect_sock).0addrinfocurrent_loop
exceptionsr   s     Q/var/www/html/ai-engine/env/lib/python3.11/site-packages/aiohappyeyeballs/impl.py	<genexpr>z#start_connection.<locals>.<genexpr>Z   sR          !!<XGW          c                     g | ]	}|D ]}|
S  r!   )r   subexcs      r   
<listcomp>z$start_connection.<locals>.<listcomp>d   s%    CCC#sCC#CCCCr   r   c              3   >   K   | ]}t          |          k    V  d S r   str)r   r#   models     r   r   z#start_connection.<locals>.<genexpr>l   s.      CCSs3xx5(CCCCCCr   zMultiple exceptions: {}z, c              3   4   K   | ]}t          |          V  d S r   r&   r   r#   s     r   r   z#start_connection.<locals>.<genexpr>q   s(      AA3c#hhAAAAAAr   c              3   X   K   | ]$}t          |t                    o
|j        k    V  %d S r   )
isinstanceOSErrorerrno)r   r#   first_errnos     r   r   z#start_connection.<locals>.<genexpr>w   sM         #300MSY+5M     r   c              3   @   K   | ]}t          |t                    V  d S r   )r,   RuntimeErrorr*   s     r   r   z#start_connection.<locals>.<genexpr>|   sE       G G69JsL11G G G G G Gr   )asyncioget_running_looplen_interleave_addrinfosr   r1   r-   r   staggered_racer'   allformatjoinr,   r.   )r   r   r   r   r   single_addr_infosockr   _all_exceptionsfirst_exceptionmsgr   r   r/   r(   s    `          @@@@r   start_connectionr@      s     L ! L 2/11:!+'J,>
 C* C*:zBB
$(D;=J#'7#" 	 	H* *h8H         '*    &4      !+	   !
 
 
 
 
 
 
 

a |CCCCC!	,Q/O>""a''%% O,,CCCCNCCCCC *)) 066IIAA.AAAAA 
 ow77 
,"1"7K    #1     8 &k3777	8
  >> ,3 G G=KG G G D D , 's+++ cll"!NJKs   A33BBDG Gr   	addr_infoc                   K   g }|                     |           |\  }}}}}	d}
	 t          j        |||          }
|
                    d           ||D ]\  }}}}}||k    r	 |
                    |            n# t          $ rS}d|d|j                                         }t	          |j        |          }|                     |           Y d}~d}~ww xY w|r|                                t	          d|d          | 	                    |
|	           d{V  |
dx}}S # t          t          f$ r[}|                     |           |
>	 |
                                 n(# t          $ r}|                     |            d}~ww xY w d}~w |
>	 |
                                 n(# t          $ r}|                     |            d}~ww xY w xY w# dx}}w xY 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_connectr1   close)r   r   rA   r   my_exceptionsrC   type_rE   r<   addressr;   lfamilyladdrr#   r?   es                   r   r   r      s      9;Mm$$$'0$FE5!WD,*}FeDDD'+; U U'Aq%f$$
.IIe$$$E . . .2#(2 2<--//2 2 
 "#)S11C!((--------. ! U'++---!"SF"S"S"STTTg.........& &*)
]]% '"   S!!!

   $$Q''' 	

   $$Q''' 	%))
]))))s   ?D' %A<:D' <
CA	CD' CA	D' 'G8FE%$F%
F
/FF

FGF+*G+
G5GGGG G	addrinfosfirst_address_family_countc                    t          j                    }| D ].}|d         }||vrg ||<   ||                             |           /t          |                                          }g }|dk    r4|                    |d         d|dz
                      |d         d|dz
  = |                    d t          j                            t          j	        |           D                        |S )z-Interleave list of addrinfo tuples by family.r   r   Nc              3      K   | ]}||V  	d S r   r!   )r   as     r   r   z(_interleave_addrinfos.<locals>.<genexpr>   s0        = 	
=== r   )
collectionsOrderedDictrF   listvaluesextend	itertoolschainfrom_iterablezip_longest)rU   rV   addrinfos_by_familyaddrrC   addrinfos_lists	reordereds          r   r5   r5      s#    	!!   1 1a,,,*,'F#**40000.557788O$&I!A%%+,L.H1.L,LMNNNA?!;a!??@  ..y/Do/VWW     
 r   r   )r   )__doc__r2   rZ   r   r_   rG   systypingr   r   r   r    r   typesr	   version_infoasyncio.futuresTimeoutErrorfuturesfloatintAbstractEventLoopr@   r-   r1   r   r5   r!   r   r   <module>rs      s                   



 2 2 2 2 2 2 2 2 2 2 2 2            i #*#7GO  :>,0 $04o o o&o x56o #5/	o
 o 7,
-o ]o o o ol :>	7* 7*

#7*T% 56787* 7* x56	7*
 ]7* 7* 7* 7*v JK %CF	,     r   