
    ,hBI                       d dl mZ d dlZd dlmZmZ d dlmZmZ d dl	Z	d dl
mZmZmZmZ erd dlmZmZ d dlmZmZ d dlmZ ej,                  d	k  rd d
lmZmZ dZedd       Z	 	 	 	 ddZddZedd	 	 	 	 	 	 	 	 	 ddZy)    )annotationsN)contextmanagersuppress)TYPE_CHECKINGAny)SOCK_STREAM
SocketTypegetaddrinfosocket)	GeneratorMutableSequence)AddressFamily
SocketKind)AddressFormat)      )BaseExceptionGroupExceptionGroupg      ?c               #    K   t               } 	 |  g }| D ]  }	 |j                           t	        |      dk(  r|d   |rt        d|      y # t        $ r}|j                  |       Y d }~Wd }~ww xY w# g }| D ]:  }	 |j                          # t        $ r}|j                  |       Y d }~4d }~ww xY w t	        |      dk(  r|d   |rt        d|      w xY ww)N   r    )setcloseBaseExceptionappendlenr   )sockets_to_closeerrssockexcs       a/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/trio/_highlevel_open_tcp_stream.py	close_allr"   w   s     (+/$ 	!D!

	!
 t9>q'M$R.. 	 ! !C  !	 $ 	!D!

  !C  !	!
 t9>q'M$R.. sm   CA5 CA$C	A2A-(C-A22C5C>BC	B3	B.	)C.B3	3&CCc                    t        dt        |             D ];  }| |   d   | d   d   k7  s|dk7  r!| j                  d| j                  |              y  y )Nr   r   )ranger   insertpop)targetsis     r!    reorder_for_rfc_6555_section_5_4r)      sX     1c'l# 1:a=GAJqM) Avq'++a.1    c                n    t        | t              r| j                  d      n| } d| v rd|  d| S |  d| S )Nascii:[z]:)
isinstancebytesdecode)hostports     r!   format_host_portr4      sF    #-dE#:4;;wD
d{4&4&!!qr*   )happy_eyeballs_delaylocal_addressc          	     0  K   t        | t        t        f      st        d|       t        |t              st        d|      |t        }t        | |t               d{   }|sdt        | |       }t        |      t        |       g d	 	 	 	 	 	 	 	 d	fd}t               5 t        j                         4 d{   |D ]  \  }}}	}
}t        j                         }t         r ||||	f||       d{    j#                  ||||	f||       t        j$                  |      5  |j'                          d{    ddd        ddd      d{    ?t)              t)        |      k(  sJ dt        | |       d}t        |      t+        |      t        j,                        }j/                         |cddd       S 7 u7 7 7 # 1 sw Y   xY w7 # 1 d{  7  sw Y   xY w# 1 sw Y   yxY ww)
a  Connect to the given host and port over TCP.

    If the given ``host`` has multiple IP addresses associated with it, then
    we have a problem: which one do we use?

    One approach would be to attempt to connect to the first one, and then if
    that fails, attempt to connect to the second one ... until we've tried all
    of them. But the problem with this is that if the first IP address is
    unreachable (for example, because it's an IPv6 address and our network
    discards IPv6 packets), then we might end up waiting tens of seconds for
    the first connection attempt to timeout before we try the second address.

    Another approach would be to attempt to connect to all of the addresses at
    the same time, in parallel, and then use whichever connection succeeds
    first, abandoning the others. This would be fast, but create a lot of
    unnecessary load on the network and the remote server.

    This function strikes a balance between these two extremes: it works its
    way through the available addresses one at a time, like the first
    approach; but, if ``happy_eyeballs_delay`` seconds have passed and it's
    still waiting for an attempt to succeed or fail, then it gets impatient
    and starts the next connection attempt in parallel. As soon as any one
    connection attempt succeeds, all the other attempts are cancelled. This
    avoids unnecessary load because most connections will succeed after just
    one or two attempts, but if one of the addresses is unreachable then it
    doesn't slow us down too much.

    This is known as a "happy eyeballs" algorithm, and our particular variant
    is modelled after how Chrome connects to webservers; see `RFC 6555
    <https://tools.ietf.org/html/rfc6555>`__ for more details.

    Args:
      host (str or bytes): The host to connect to. Can be an IPv4 address,
          IPv6 address, or a hostname.

      port (int): The port to connect to.

      happy_eyeballs_delay (float or None): How many seconds to wait for each
          connection attempt to succeed or fail before getting impatient and
          starting another one in parallel. Set to `None` if you want
          to limit to only one connection attempt at a time (like
          :func:`socket.create_connection`). Default: 0.25 (250 ms).

      local_address (None or str): The local IP address or hostname to use as
          the source for outgoing connections. If ``None``, we let the OS pick
          the source IP.

          This is useful in some exotic networking configurations where your
          host has multiple IP addresses, and you want to force the use of a
          specific one.

          Note that if you pass an IPv4 ``local_address``, then you won't be
          able to connect to IPv6 hosts, and vice-versa. If you want to take
          advantage of this to force the use of IPv4 or IPv6 without
          specifying an exact source address, you can use the IPv4 wildcard
          address ``local_address="0.0.0.0"``, or the IPv6 wildcard address
          ``local_address="::"``.

    Returns:
      SocketStream: a :class:`~trio.abc.Stream` connected to the given server.

    Raises:
      OSError: if the connection fails.

    See also:
      open_ssl_over_tcp_stream

    zhost must be str or bytes, not zport must be int, not N)typez&no results found for hostname lookup: c                t  K   	 t        |  }j                  |       |t        t        t              5  |j                  t        j                   j                  t        j                   j                  d       d d d        	 |j                  df       d {    |j                  |       d {    |	j                  j                          y # 1 sw Y   [xY w7 F# t        $ r t        dd|      d w xY w7 N# t        $ r+}j                  |       |j                          Y d }~y d }~ww xY ww)Nr   r   zlocal_address=z% is incompatible with remote address )r   addr   OSErrorAttributeError
setsockopttrio
IPPROTO_IPIP_BIND_ADDRESS_NO_PORTbindconnectcancel_scopecancelr   r   )
socket_argssockaddrattempt_failedr   r    r6   nurseryopen_socketsoserrorswinning_sockets
        r!   attempt_connectz(open_tcp_stream.<locals>.attempt_connect)  s.    ?	!;'DT"(B g~6 OO..;; ))]A$6777 ,,x((( "N  '')'  8  !((9 ://7l<     )  	!
 OOC   	!s|   D8/D AC8D C  CC  D 0C?1 D D8CD C   C<<D 	D5
!D0+D80D55D8zall attempts to connect to z failed)rE   z%tuple[AddressFamily, SocketKind, int]rF   r   rG   z
trio.EventreturnNone)r/   strr0   
ValueErrorint	TypeErrorDEFAULT_DELAYr
   r   r4   r;   r)   r"   r>   open_nurseryEventr   
start_soonmove_on_afterwaitr   r   SocketStreamremove)r2   r3   r5   r6   r'   msgrL   address_familysocket_typeproto_addrrG   streamrH   rI   rJ   rK   s      `          @@@@r!   open_tcp_streamrb      s_    ^ dS%L):4(CDDdC 09::#,d==G
 67Gd7S6TUcl$W- !H )-NF!:F!F! #F! 
	F! F!P 
 $ $$& 	0 	0'?F 0;UAt "& !)'e<&   ""##[%8"	 ''(<= 0(--///0 0+0	0 	04 !x=CL00/0@t0L/MWUC#,N3$AA&&~6F/I$ $C >H	0 00 0-	0 	0 	0 	0$ $s   A H'G(AH3H
GH
6G5G"
0G57G&	G$G&	
G5H
%G3&A,H
HH
"G5$G&	&G0+G53H
5H	;G><H	H

HH)rM   z&Generator[set[SocketType], None, None])r'   z@MutableSequence[tuple[AddressFamily, SocketKind, int, str, Any]]rM   rN   )r2   str | bytesr3   z	int | strrM   rO   )
r2   rc   r3   rQ   r5   zfloat | Noner6   z
str | NonerM   ztrio.SocketStream)
__future__r   sys
contextlibr   r   typingr   r   r>   trio.socketr   r	   r
   r   collections.abcr   r   r   r   trio._socketr   version_infoexceptiongroupr   r   rS   r"   r)   r4   rb    r*   r!   <module>rn      s    " 
 / %  D D:0*gAx T / /"M	( @ *7 $\
\
\ '	\
 \ \r*   