
    f jC                        d dl m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
 ddlmZmZ ddlmZmZmZmZ ddlmZmZmZ d	d
lmZ d	dlmZmZ  G d d          Z G d de          Z G d d          ZdS )    )annotationsN   )AutoBackend)SOCKET_OPTIONAsyncNetworkBackend)ConnectionNotAvailableUnsupportedProtocol)OriginProxyRequestResponse)
AsyncEventAsyncShieldCancellationAsyncThreadLock   )AsyncHTTPConnection)AsyncConnectionInterfaceAsyncRequestInterfacec                  :    e Zd ZddZddZdd	Z	 dddZddZd
S )AsyncPoolRequestrequestr   returnNonec                H    || _         d | _        t                      | _        d S N)r   
connectionr   _connection_acquired)selfr   s     sC:\Users\Terasoftware\OneDrive\Desktop\faahhh\fyndo\fyndo\venv\Lib\site-packages\httpcore/_async/connection_pool.py__init__zAsyncPoolRequest.__init__   s"    ;?$.LL!!!    r   AsyncConnectionInterface | Nonec                F    || _         | j                                         d S r   )r   r   set)r   r   s     r   assign_to_connectionz%AsyncPoolRequest.assign_to_connection   s$    $!%%'''''r!   c                :    d | _         t                      | _        d S r   )r   r   r   r   s    r   clear_connectionz!AsyncPoolRequest.clear_connection   s    $.LL!!!r!   Ntimeoutfloat | Noner   c                v   K   | j         !| j                            |           d {V  | j         J | j         S )Nr)   )r   r   wait)r   r)   s     r   wait_for_connectionz$AsyncPoolRequest.wait_for_connection   sU       ? 	B+000AAAAAAAAA***r!   boolc                    | j         d u S r   )r   r'   s    r   	is_queuedzAsyncPoolRequest.is_queued'   s    $&&r!   )r   r   r   r   )r   r"   r   r   r   r   r   )r)   r*   r   r   )r   r/   )__name__
__module____qualname__r    r%   r(   r.   r1    r!   r   r   r      s        1 1 1 1
( ( ( (1 1 1 1
 '+    ' ' ' ' ' 'r!   r   c                      e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 d7d8dZd9d"Zed:d$            Zd;d(Zd:d)Z	d<d+Z
d=d,Zd>d-Z	 	 	 d?d@d4ZdAd6ZdS )BAsyncConnectionPoolz5
    A connection pool for making HTTP requests.
    N
   TFr   ssl_contextssl.SSLContext | NoneproxyProxy | Nonemax_connections
int | Nonemax_keepalive_connectionskeepalive_expiryr*   http1r/   http2retriesintlocal_address
str | Noneudsnetwork_backendAsyncNetworkBackend | Nonesocket_options%typing.Iterable[SOCKET_OPTION] | Noner   r   c                   || _         || _        |t          j        n|| _        |t          j        n|| _        t          | j        | j                  | _        || _        || _        || _	        || _
        |	| _        |
| _        |t                      n|| _        || _        g | _        g | _        t%                      | _        dS )a  
        A connection pool for making HTTP requests.

        Parameters:
            ssl_context: An SSL context to use for verifying connections.
                If not specified, the default `httpcore.default_ssl_context()`
                will be used.
            max_connections: The maximum number of concurrent HTTP connections that
                the pool should allow. Any attempt to send a request on a pool that
                would exceed this amount will block until a connection is available.
            max_keepalive_connections: The maximum number of idle HTTP connections
                that will be maintained in the pool.
            keepalive_expiry: The duration in seconds that an idle HTTP connection
                may be maintained for before being expired from the pool.
            http1: A boolean indicating if HTTP/1.1 requests should be supported
                by the connection pool. Defaults to True.
            http2: A boolean indicating if HTTP/2 requests should be supported by
                the connection pool. Defaults to False.
            retries: The maximum number of retries when trying to establish a
                connection.
            local_address: Local address to connect from. Can also be used to connect
                using a particular address family. Using `local_address="0.0.0.0"`
                will connect using an `AF_INET` address (IPv4), while using
                `local_address="::"` will connect using an `AF_INET6` address (IPv6).
            uds: Path to a Unix Domain Socket to use instead of TCP sockets.
            network_backend: A backend instance to use for handling network I/O.
            socket_options: Socket options that have to be included
             in the TCP socket when the connection was established.
        N)_ssl_context_proxysysmaxsize_max_connections_max_keepalive_connectionsmin_keepalive_expiry_http1_http2_retries_local_address_udsr   _network_backend_socket_options_connections	_requestsr   _optional_thread_lock)r   r:   r<   r>   r@   rA   rB   rC   rD   rF   rH   rI   rK   s                r   r    zAsyncConnectionPool.__init__0   s    X (*GCKK 	
 )+CKK* 	'
 +.!4#B+
 +
' "2+	 -IKMMM/ 	  . =?13
 &5%6%6"""r!   originr
   r   c                   | j         | j         j        j        dv rKddlm}  || j         j        j        | j         j        || j        | j        | j	        | j
        | j                  S |j        dk    rDddlm}  || j         j        j        | j         j        | j         j        || j        | j                  S ddlm}  || j         j        j        | j         j        | j         j        || j        | j        | j	        | j
        | j        		  	        S t#          || j        | j        | j	        | j
        | j        | j        | j        | j        | j        

  
        S )N)s   socks5s   socks5hr   )AsyncSocks5Connection)proxy_origin
proxy_authremote_originr:   rA   rB   rC   rI   s   http)AsyncForwardHTTPConnection)rc   proxy_headersproxy_ssl_contextre   rA   rI   )AsyncTunnelHTTPConnection)	rc   rg   rh   re   r:   rA   rB   rC   rI   )
r`   r:   rA   rB   rC   rD   rF   rH   rI   rK   )rO   urlschemesocks_proxyrb   r`   authrN   rU   rV   rW   r[   
http_proxyrf   headersr:   ri   r   rX   rY   rZ   r\   )r   r`   rb   rf   ri   s        r   create_connectionz%AsyncConnectionPool.create_connection   s   ; %	{%)@@ >>>>>>,,!%!7#{/"( $ 1%)%;++$($9	 	 	 	 ') 
BBBBBB11!%!7"&+"5&*k&="(%)%;$($9    >=====,,![_3"k1"&+"9$ -!%!7kk $ 5
 
 
 
 #)!3++M-	 1/
 
 
 	
r!   list[AsyncConnectionInterface]c                *    t          | j                  S )a  
        Return a list of the connections currently in the pool.

        For example:

        ```python
        >>> pool.connections
        [
            <AsyncHTTPConnection ['https://example.com:443', HTTP/1.1, ACTIVE, Request Count: 6]>,
            <AsyncHTTPConnection ['https://example.com:443', HTTP/1.1, IDLE, Request Count: 9]> ,
            <AsyncHTTPConnection ['http://example.com:80', HTTP/1.1, IDLE, Request Count: 1]>,
        ]
        ```
        )listr]   r'   s    r   connectionszAsyncConnectionPool.connections   s      D%&&&r!   r   r   r   c           	       K   |j         j                                        }|dk    rt          d          |dvrt          d| d          |j                            di           }|                    dd          }| j        5  t          |          }| j        	                    |           ddd           n# 1 swxY w Y   	 	 | j        5  | 
                                }ddd           n# 1 swxY w Y   |                     |           d{V  |                    |
           d{V }	 |                    |j                   d{V }n%# t          $ r |                                 Y nw xY wn}# t"          $ rp}	| j        5  | j                            |           | 
                                }ddd           n# 1 swxY w Y   |                     |           d{V  |	dd}	~	ww xY wt'          |j        t*          j                  sJ t/          |j        |j        t5          |j        ||           |j                  S )z
        Send an HTTP request, and return an HTTP response.

        This is the core implementation that is called into by `.request()` or `.stream()`.
         z;Request URL is missing an 'http://' or 'https://' protocol.)httphttpswswssz)Request URL has an unsupported protocol 'z://'.r)   poolNTr,   )streampool_requestr{   )statusro   content
extensions)rj   rk   decoder	   r   getr_   r   r^   append_assign_requests_to_connections_close_connectionsr.   handle_async_requestr   r   r(   BaseExceptionremove
isinstancer|   typingAsyncIterabler   r~   ro   PoolByteStream)
r   r   rk   timeoutsr)   r}   closingr   responseexcs
             r   r   z(AsyncConnectionPool.handle_async_request   s      #**,,R< 	%M   77 	%IFIII   %)))R88,,vt,,' 	0 	0+G44LN!!,///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0
!	 / E E #BBDDGE E E E E E E E E E E E E E E --g666666666 $0#C#CG#C#T#TTTTTTT
%/%D%D$,& &            H  . 4 4 4
 !11333334,  	  	  	 + A A %%l333>>@@	A A A A A A A A A A A A A A A ))'2222222224	  (/6+?@@@@@?$"\    *
 
 
 	
s   *B;;B?B?E: C0$E: 0C44E: 7C48:E: 3 E E: E52E: 4E55E: :
G4G//G:G/G
	
G/G
	!G//G4c                   g }t          | j                  D ]}|                                r| j                            |           1|                                r0| j                            |           |                    |           u|                                rVt          d | j        D                       | j        k    r/| j                            |           |                    |           d | j	        D             }|D ]7}|j
        j        j        fd| j        D             }d | j        D             }|r|d         }|                    |           Xt          | j                  | j        k     rE|                               }| j                            |           |                    |           |r{|d         }| j                            |           |                    |           |                               }| j                            |           |                    |           9|S )aE  
        Manage the state of the connection pool, assigning incoming
        requests to connections as available.

        Called whenever a new request is added or removed from the pool.

        Any closing connections are returned, allowing the I/O for closing
        those connections to be handled seperately.
        c                6    g | ]}|                                 S r6   is_idle.0r   s     r   
<listcomp>zGAsyncConnectionPool._assign_requests_to_connections.<locals>.<listcomp>&  s$    RRR*++--RRRr!   c                :    g | ]}|                                 |S r6   r1   r   r   s     r   r   zGAsyncConnectionPool._assign_requests_to_connections.<locals>.<listcomp>.  s)    XXXwGDUDUDWDWX7XXXr!   c                f    g | ]-}|                               |                                +|.S r6   )can_handle_requestis_available)r   r   r`   s     r   r   zGAsyncConnectionPool._assign_requests_to_connections.<locals>.<listcomp>1  sT     % % %0088% >H=T=T=V=V%% % %r!   c                :    g | ]}|                                 |S r6   r   r   s     r   r   zGAsyncConnectionPool._assign_requests_to_connections.<locals>.<listcomp>6  s9          )*BTBTBVBV      r!   r   )rs   r]   	is_closedr   has_expiredr   r   lenrS   r^   r   rj   r`   r%   rR   rp   )r   closing_connectionsr   queued_requestsr}   available_connectionsidle_connectionsr`   s          @r   r   z3AsyncConnectionPool._assign_requests_to_connections  s    ! t011 	7 	7J##%% 7!((4444'')) 7!((444#**:6666""$$7RR@QRRRSS127 !((444#**:666 YX$.XXX+ "	> "	>L!)-4F% % % %"&"3% % %!
   -1->      % >215
11*====T&''$*?? >!33F;;
!((44411*====! >-a0
!((444#**:666!33F;;
!((44411*===""r!   r   c                   K   t                      5  |D ]}|                                 d {V  	 d d d            d S # 1 swxY w Y   d S r   )r   aclose)r   r   r   s      r   r   z&AsyncConnectionPool._close_connectionsU  s      $&& 	* 	*% * *
 ''))))))))))*	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s    ?AAc                   K   | j         5  t          | j                  }g | _        d d d            n# 1 swxY w Y   |                     |           d {V  d S r   )r_   rs   r]   r   )r   r   s     r   r   zAsyncConnectionPool.aclose[  s       ' 	# 	#"&t'8"9"9 "D	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# %%&9:::::::::::s   266c                
   K   | S r   r6   r'   s    r   
__aenter__zAsyncConnectionPool.__aenter__c  s      r!   exc_typetype[BaseException] | None	exc_valueBaseException | None	tracebacktypes.TracebackType | Nonec                >   K   |                                   d {V  d S r   )r   )r   r   r   r   s       r   	__aexit__zAsyncConnectionPool.__aexit__f  s.       kkmmr!   strc                   | j         j        }| j        5  d | j        D             }d | j        D             }|                    d          }|                    d          }|                    d          }|                    d          }d d d            n# 1 swxY w Y   d| d| d}d| d| d	}	d
| d| d|	 dS )Nc                6    g | ]}|                                 S r6   r   r   s     r   r   z0AsyncConnectionPool.__repr__.<locals>.<listcomp>q  s$     S S S!2!2!4!4 S S Sr!   c                6    g | ]}|                                 S r6   r   r   s     r   r   z0AsyncConnectionPool.__repr__.<locals>.<listcomp>r  s1     " " ")3
""$$" " "r!   FTz
Requests: z	 active, z queuedzConnections: z idle<z [z | z]>)	__class__r3   r_   r^   r]   count)
r   
class_namerequest_is_queuedconnection_is_idlenum_active_requestsnum_queued_requestsnum_active_connectionsnum_idle_connectionsrequests_infoconnection_infos
             r   __repr__zAsyncConnectionPool.__repr__n  si   ^,
' 		B 		B S SDN S S S" "7;7H" " " #4"9"9%"@"@"3"9"9$"?"?%7%=%=e%D%D"#5#;#;D#A#A 		B 		B 		B 		B 		B 		B 		B 		B 		B 		B 		B 		B 		B 		B 		B T,SS7JSSS 	 Y2XX=QXXX 	 G:FFFF?FFFFs   A7BBB)NNr9   NNTFr   NNNN)r:   r;   r<   r=   r>   r?   r@   r?   rA   r*   rB   r/   rC   r/   rD   rE   rF   rG   rH   rG   rI   rJ   rK   rL   r   r   )r`   r
   r   r   )r   rq   )r   r   r   r   )r   rq   r   r   r2   )r   r8   )NNN)r   r   r   r   r   r   r   r   )r   r   )r3   r4   r5   __doc__r    rp   propertyrt   r   r   r   r   r   r   r   r6   r!   r   r8   r8   +   sD         .2"&(04)-$(6:@DN7 N7 N7 N7 N7`3
 3
 3
 3
j ' ' ' X'"E
 E
 E
 E
NE# E# E# E#N* * * *; ; ; ;   
 04*.04	    G G G G G Gr!   r8   c                  &    e Zd Zdd	ZddZddZdS )r   r|   typing.AsyncIterable[bytes]r}   r   r{   r8   r   r   c                >    || _         || _        || _        d| _        d S )NF)_stream_pool_request_pool_closed)r   r|   r}   r{   s       r   r    zPoolByteStream.__init__  s%     )
r!   typing.AsyncIterator[bytes]c                  K   	 | j         2 3 d {V }|W V  6 d S # t          $ r"}|                                  d {V  |d d }~ww xY wr   )r   r   r   )r   partr   s      r   	__aiter__zPoolByteStream.__aiter__  s      	 "l       d




 +ll 	  	  	 ++--4	 s     
AAAc                  K   | j         sd| _         t                      5  t          | j        d          r| j                                         d {V  d d d            n# 1 swxY w Y   | j        j        5  | j        j                            | j	                   | j        
                                }d d d            n# 1 swxY w Y   | j                            |           d {V  d S d S )NTr   )r   r   hasattrr   r   r   r_   r^   r   r   r   r   )r   r   s     r   r   zPoolByteStream.aclose  s     | 
	9DL(** 0 04<22 0,--/////////0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 G G
$++D,>???*DDFFG G G G G G G G G G G G G G G *//88888888888
	9 
	9s#   5A  A$'A$7>CCCN)r|   r   r}   r   r{   r8   r   r   )r   r   r2   )r3   r4   r5   r    r   r   r6   r!   r   r   r     sP        	 	 	 	       9 9 9 9 9 9r!   r   )
__future__r   sslrP   typesr   _backends.autor   _backends.baser   r   _exceptionsr   r	   _modelsr
   r   r   r   _synchronizationr   r   r   r   r   
interfacesr   r   r   r8   r   r6   r!   r   <module>r      s   " " " " " " 



 



   ( ( ( ( ( ( ? ? ? ? ? ? ? ? E E E E E E E E 6 6 6 6 6 6 6 6 6 6 6 6 S S S S S S S S S S + + + + + + G G G G G G G G' ' ' ' ' ' ' '4WG WG WG WG WG/ WG WG WGt
9 9 9 9 9 9 9 9 9 9r!   