
    h0                        S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJrJ	r	  SSK
Jr  SSKJr  SSKJr  SSKJr  SSKJr  SS	KJrJrJrJrJrJrJrJr  \R8                  (       a  SS
KJr  Sr " S S5      r " S S5      r g)z'A non-blocking TCP connection factory.
    N)Futurefuture_add_done_callback)IOLoop)IOStream)gen)Resolver)TimeoutError)AnyUnionDictTupleListCallableIteratorOptional)Setg333333?c            
          \ rS rSrSrS\\   S\\R                  \/\\
S4   4   SS4S jr\S\\   S\\\\R                  \4      \\\R                  \4      4   4S	 j5       r\S4S
\S\\\\R&                  4      SS4S jjrS\\\R                  \4      SS4S jrS\\\R                  \4      S\R                  S\SSSS4
S jrS
\SS4S jrSS jrSS jrS\\\R&                  4   SS4S jrSS jrSS jrSS jrSrg)
_Connector)   at  A stateless implementation of the "Happy Eyeballs" algorithm.

"Happy Eyeballs" is documented in RFC6555 as the recommended practice
for when both IPv4 and IPv6 addresses are available.

In this implementation, we partition the addresses by family, and
make the first connection attempt to whichever address was
returned first by ``getaddrinfo``.  If that connection fails or
times out, we begin a connection in parallel to the first address
of the other family.  If there are additional failures we retry
with other addresses, keeping one connection attempt per family
in flight at a time.

http://tools.ietf.org/html/rfc6555

addrinfoconnectFuture[IOStream]returnNc                    [         R                  " 5       U l        X l        [	        5       U l        S U l        S U l        S U l        [        U5      U l
        U R                  U5      u  U l        U l        [        5       U l        g N)r   currentio_loopr   r   futuretimeoutconnect_timeout
last_errorlen	remainingsplitprimary_addrssecondary_addrssetstreams)selfr   r   s      dC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\tornado/tcpclient.py__init___Connector.__init__;   sj     ~~' H 	 #X37::h3G0D0u    c                     / n/ nU S   S   nU  H0  u  pEXC:X  a  UR                  XE45        M  UR                  XE45        M2     X4$ )aT  Partition the ``addrinfo`` list by address family.

Returns two lists.  The first list contains the first entry from
``addrinfo`` and all others with the same family, and the
second list contains all other addresses (normally one list will
be AF_INET and the other AF_INET6, although non-standard resolvers
may return additional families).
r   )append)r   primary	secondary
primary_afafaddrs         r*   r$   _Connector.splitO   sV     	a[^
 HBz*  ",	 !
 !!r-   r   r    z2Future[Tuple[socket.AddressFamily, Any, IOStream]]c                     U R                  [        U R                  5      5        U R                  U5        Ub  U R	                  U5        U R
                  $ r   )try_connectiterr%   set_timeoutset_connect_timeoutr   )r)   r   r    s      r*   start_Connector.starth   sI    
 	d0012!&$$_5{{r-   addrsc           	          [        U5      u  p#U R                  X#5      u  pEU R                  R                  U5        [        U[        R                  " U R                  XU5      5        g ! [         ai    U R                  S:X  aV  U R                  R	                  5       (       d7  U R                  R                  U R                  =(       d    [        S5      5         g f = f)Nr   zconnection failed)nextStopIterationr#   r   doneset_exceptionr!   IOErrorr   r(   addr   	functoolspartialon_connect_done)r)   r=   r3   r4   streamr   s         r*   r7   _Connector.try_connects   s    
	E{HB b/  I%%d&:&:EtL	
  	 ~~"4;;+;+;+=+=))OOCw/B'C 	s   A* *A0CCr3   r4   r   c                    U =R                   S-  sl          UR                  5       nU R                  5         U R                  R	                  5       (       a  UR                  5         g U R                  R                  U5        U R                  R                  X#U45        U R!                  5         g ! [         a  nU R                  R	                  5       (       a   S nAg X`l        U R                  U5        U R                  b5  U R                  R                  U R                  5        U R                  5          S nAg S nAff = f)N   )r#   result	Exceptionr   rA   r!   r7   r   r   remove_timeout
on_timeoutclear_timeoutscloser(   discard
set_resultclose_streams)r)   r=   r3   r4   r   rH   es          r*   rG   _Connector.on_connect_done   s     	!	]]_F 	;;LLNLL  (KK""Bf#56 )  	{{!!  OU#||' ++DLL9!	s   B0 0
E:D<AD<<Ec                     U R                   R                  U R                   R                  5       U-   U R                  5      U l        g r   )r   add_timeouttimerO   r   )r)   r   s     r*   r9   _Connector.set_timeout   s3    ||//LL')4??
r-   c                     S U l         U R                  R                  5       (       d%  U R                  [	        U R
                  5      5        g g r   )r   r   rA   r7   r8   r&   r)   s    r*   rO   _Connector.on_timeout   s:    {{!!T$"6"678 "r-   c                 j    U R                   b&  U R                  R                  U R                   5        g g r   )r   r   rN   r\   s    r*   clear_timeout_Connector.clear_timeout   s'    <<#LL''5 $r-   c                 X    U R                   R                  XR                  5      U l        g r   )r   rX   on_connect_timeoutr    )r)   r    s     r*   r:   _Connector.set_connect_timeout   s$      $||7744 
r-   c                     U R                   R                  5       (       d#  U R                   R                  [        5       5        U R	                  5         g r   )r   rA   rB   r	   rT   r\   s    r*   rb   _Connector.on_connect_timeout   s5    {{!!KK%%ln5r-   c                     U R                   b%  U R                  R                  U R                   5        U R                  b&  U R                  R                  U R                  5        g g r   )r   r   rN   r    r\   s    r*   rP   _Connector.clear_timeouts   sK    <<#LL''5+LL''(<(<= ,r-   c                 J    U R                    H  nUR                  5         M     g r   )r(   rQ   )r)   rH   s     r*   rT   _Connector.close_streams   s    llFLLN #r-   )
r   r    r   r   r!   r%   r#   r&   r(   r   r   N) __name__
__module____qualname____firstlineno____doc__r   r   r   socketAddressFamilyr   r+   staticmethodr$   _INITIAL_CONNECT_TIMEOUTfloatr   r   datetime	timedeltar;   r   r7   rG   r9   rO   r_   r:   rb   rP   rT   __static_attributes__ r-   r*   r   r   )   s   "u+ !!5)5;M1M+NN
 
( "u+"	U6''./0U6''./0	2
" "4 2FJ		 "%x/A/A(A"BC	 
>		
%0D0De0K*L!M 
RV 
$!f22E9:;!   ! 	!
 #! 
!@
5 
T 

9
6
$UH,>,>%>?
	

>r-   r   c                   \   \ rS rSrSrSS\\   SS4S jjrSS jr\	R                  SSSSS4S\S	\S
\	R                  S\\\\\4   \R$                  4      S\\   S\\   S\\   S\\\\R*                  4      S\4S jjr  SS\S
\	R                  S\S\\   S\\   S\\S4   4S jjrSrg)	TCPClient   zA non-blocking TCP connection factory.

.. versionchanged:: 5.0
   The ``io_loop`` argument (deprecated since version 4.1) has been removed.
Nresolverr   c                 R    Ub  Xl         SU l        g [        5       U l         SU l        g )NFT)r|   _own_resolverr   )r)   r|   s     r*   r+   TCPClient.__init__   s&    $M!&D$JDM!%Dr-   c                 \    U R                   (       a  U R                  R                  5         g g r   )r~   r|   rQ   r\   s    r*   rQ   TCPClient.close   s     MM! r-   hostportr3   ssl_optionsmax_buffer_size	source_ipsource_portr   c	           
      \  #    Ub  [        U[        R                  5      (       a'  [        R                  " 5       R                  5       U-   nOb[        U[        R                  5      (       a5  [        R                  " 5       R                  5       UR                  5       -   nO[        SU-  5      eUb9  [        R                  " XR                  R                  XU5      5      I Sh  vN n	O$U R                  R                  XU5      I Sh  vN n	[        U	[        R                   " U R"                  UUUS95      n
U
R%                  US9I Sh  vN u  p;nUbJ  Ub/  [        R                  " UUR'                  SXAS95      I Sh  vN nU$ UR'                  SXAS9I Sh  vN nU$  N N NZ N& N7f)a_  Connect to the given host and port.

Asynchronously returns an `.IOStream` (or `.SSLIOStream` if
``ssl_options`` is not None).

Using the ``source_ip`` kwarg, one can specify the source
IP address to use when establishing the connection.
In case the user needs to resolve and
use a specific interface, it has to be handled outside
of Tornado as this depends very much on the platform.

Raises `TimeoutError` if the input future does not complete before
``timeout``, which may be specified in any form allowed by
`.IOLoop.add_timeout` (i.e. a `datetime.timedelta` or an absolute time
relative to `.IOLoop.time`)

Similarly, when the user requires a certain source port, it can
be specified using the ``source_port`` arg.

.. versionchanged:: 4.5
   Added the ``source_ip`` and ``source_port`` arguments.

.. versionchanged:: 5.0
   Added the ``timeout`` argument.
NzUnsupported timeout %r)r   r   )r    F)r   server_hostname)
isinstancenumbersRealr   r   rY   ru   rv   total_seconds	TypeErrorr   with_timeoutr|   resolver   rE   rF   _create_streamr;   	start_tls)r)   r   r   r3   r   r   r   r   r   r   	connectorr4   rH   s                r*   r   TCPClient.connect   s    H '7<<00 ..*//1G;GX%7%788 ..*//1G4I4I4KK 87 BCC --..t2> H "]]224rBBH###'	
	 "+!II& """//$$; %      &//{  0    = C Js[   C"F,$F"%$F,	F$
AF,F&5F,F(F,F*F,$F,&F,(F,*F,r4   r   c                    [        U[        5      (       a  UOSnUnU(       a  U(       d  U[        R                  :X  a  SOSn[        R                  " U5      nU(       d  U(       a   UR	                  Xv45         [        XS9n	XR                  U5      4$ ! [
         a    UR                  5         e f = f! [
         a)  n
[        5       nUR                  U
5        W	U4s S n
A
$ S n
A
ff = f)Nr   z::1z	127.0.0.1)r   )r   intrp   AF_INET6bindOSErrorrQ   r   r   r   rB   )r)   r   r3   r4   r   r   source_port_bindsource_ip_bind
socket_objrH   rU   fus               r*   r   TCPClient._create_stream)  s     +5[#*F*F;A"I ')FOO&;UN ]]2&
~ BC
	0jJF >>$///    "  	BQ2:	s*   'B :	B4 B14
C'>C"C'"C')r~   r|   r   rj   )NN)rk   rl   rm   rn   ro   r   r   r+   rQ   rp   	AF_UNSPECstrr   rq   r   r   r
   ssl
SSLContextrt   ru   rv   r   r   r   r   rw   rx   r-   r*   rz   rz      sM   &(!3 &t &" $*#3#3GK)-#'%)>BJJ J   	J
 eDcNCNN$BCDJ "#J C=J c]J %x'9'9 9:;J 
Jb $(%)#0#0   #0 	#0
 C=#0 c]#0 
x++	,#0 #0r-   rz   )!ro   rE   rp   r   ru   r   typingtornado.concurrentr   r   tornado.ioloopr   tornado.iostreamr   tornador   tornado.netutilr   tornado.genr	   r
   r   r   r   r   r   r   r   TYPE_CHECKINGr   rs   r   rz   rx   r-   r*   <module>r      sd         
  ? ! %  $ $ N N N	 ^ ^BB0 B0r-   