
    )Jf8                        d dl m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	Z
d dlZ
d dlmZ ddlmZ ddlmZ ddlmZ eZ ej        d          Z G d	 d
ej        e                   Z G d de          Z G d de          ZddZddZdS )    )annotationsN)BaseHTTPResponse   )HTTPHeaderDict)HTTPSConnection)HTTPSConnectionPoolTc                  *    e Zd ZdZddZddZddZdS )_LockedObjectaY  
    A wrapper class that hides a specific object behind a lock.

    The goal here is to provide a simple way to protect access to an object
    that cannot safely be simultaneously accessed from multiple threads. The
    intended use of this class is simple: take hold of it with a context
    manager, which returns the protected object.
    objr	   c                D    t          j                    | _        || _        d S N)	threadingRLocklock_obj)selfr   s     P/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/urllib3/http2.py__init__z_LockedObject.__init__"   s    O%%				    returnc                B    | j                                          | j        S r   )r   acquirer   r   s    r   	__enter__z_LockedObject.__enter__&   s    	yr   exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbtypes.TracebackType | NoneNonec                8    | j                                          d S r   )r   release)r   r   r   r    s       r   __exit__z_LockedObject.__exit__*   s     		r   N)r   r	   )r   r	   )r   r   r   r   r    r!   r   r"   )__name__
__module____qualname____doc__r   r   r%    r   r   r   r      sZ                    r   r   c                  r     e Zd Z	 dd  fd
Zd!dZd" fdZ	 	 d#d$dZd%dZd"dZd&dZ	d'dZ
d" fdZ xZS )(HTTP2ConnectionNhoststrport
int | Nonekwargs
typing.Anyr   r"   c                    |                                  | _        d | _        g | _        d|v sd|v rt	          d           t                      j        ||fi | d S )Nproxyproxy_configz$Proxies aren't supported with HTTP/2)_new_h2_conn_h2_conn
_h2_stream_h2_headersNotImplementedErrorsuperr   )r   r-   r/   r1   	__class__s       r   r   zHTTP2Connection.__init__4   sr     ))++&*68f& 8 8%&LMMMt..v.....r   )_LockedObject[h2.connection.H2Connection]c                    t           j                            d          }t          t           j                            |                    S )NT)client_side)config)h2r@   H2Configurationr   
connectionH2Connection)r   r@   s     r   r6   zHTTP2Connection._new_h2_conn@   s;    **t*<<R]77v7FFGGGr   c                   t                                                       | j        5 }|                                 | j                            |                                           d d d            d S # 1 swxY w Y   d S r   )r;   connectr7   initiate_connectionsocksendalldata_to_send)r   h2_connr<   s     r   rF   zHTTP2Connection.connectD   s    ] 	6g'')))Ig2244555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   AA77A;>A;Fmethodurl	skip_hostboolskip_accept_encodingc           	        | j         5 }|| _        |                                | _        d| j        v rd| j         d| j        pd }n| j         d| j        pd }| j                            dd|                                fd|                                fd|                                ff           d d d            d S # 1 swxY w Y   d S )	N:[z]:i  )s   :schemes   httpss   :methods
   :authoritys   :path)	r7   _request_urlget_next_available_stream_idr8   r-   r/   r9   extendencode)r   rL   rM   rN   rP   rK   	authoritys          r   
putrequestzHTTP2Connection.putrequestK   s(    ] 	g #D%BBDDDOdi?	??TY-=#??		#y==49+;==	##*1"I$4$4$6$67szz||,	  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   B,CCCheadervaluesc                    |D ]V}| j                             |                    d                                          |                    d          f           Wd S )Nzutf-8)r9   appendrW   lower)r   rZ   r[   values       r   	putheaderzHTTP2Connection.putheaderd   sg     	 	E##w''--//g1F1FG   	 	r   c                    | j         5 }|                    | j        | j        d           |                                x}r| j                            |           d d d            d S # 1 swxY w Y   d S )NT)	stream_idheaders
end_stream)r7   send_headersr8   r9   rJ   rH   rI   )r   rK   rJ   s      r   
endheaderszHTTP2Connection.endheadersj   s    ] 	0g  /( !   
  '33555| 0	!!,///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0s   AA((A,/A,databytesc                (    |sd S t          d          )Nz Sending data isn't supported yet)r:   )r   rg   s     r   sendzHTTP2Connection.sendt   s     	F!"DEEEr   HTTP2Responsec           	        d }t                      }| j        5 }d}|sv| j                            d          x}r&|                    |          }|D ]}t          |t          j        j                  rt                      }|j
        D ]i\  }	}
|	dk    r"t          |
                                          }-|                    |	                    d          |
                    d                     jt          |t          j        j                  r+||j        z  }|                    |j        |j                   t          |t          j        j                  rd}|                                x}r| j                            |           |vd d d            n# 1 swxY w Y   |                                  |J t/          ||| j        t3          |                    S )NFi  s   :statusasciiT)statusrc   request_urlrg   )	bytearrayr7   rH   recvreceive_data
isinstancerA   eventsResponseReceivedr   rc   intdecodeaddDataReceivedrg   acknowledge_received_dataflow_controlled_lengthrb   StreamEndedrJ   rI   closerk   rT   rh   )r   rn   rg   rK   rd   received_datart   eventrc   rZ   r_   rJ   s               r   getresponsezHTTP2Connection.getresponsey   s7    {{] 	4gJ  4$(INN5$9$99= .$11-@@F!' . .%eRY-GHH .&4&6&6G16 & &#)Z#7#7-0-@-@FF$+KK(.g(>(>W@U@U%& %& %& %&	& (ry/EFF . EJ.D#== % <eo    (ry/DEE .)-J#*#7#7#9#99< 4I%%l3333 ! 4	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4< 	

!!!)t	
 
 
 	
s   E<F  F$'F$c                   | j         5 }	 |                                 |                                x}r| j                            |           n# t
          $ r Y nw xY wd d d            n# 1 swxY w Y   |                                 | _         d | _        g | _        t                      
                                 d S r   )r7   close_connectionrJ   rH   rI   	Exceptionr6   r8   r9   r;   r}   )r   rK   rg   r<   s      r   r}   zHTTP2Connection.close   s    ] 	g((***"//1114 ,I%%d+++   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ))++s5   A,AAA,
AA,AA,,A03A0r   )r-   r.   r/   r0   r1   r2   r   r"   )r   r=   r   r"   )FF)
rL   r.   rM   r.   rN   rO   rP   rO   r   r"   )rZ   r.   r[   r.   r   r"   )rg   rh   r   r"   )r   rk   )r&   r'   r(   r   r6   rF   rY   r`   rf   rj   r   r}   __classcell__r<   s   @r   r,   r,   3   s       ,0
/ 
/ 
/ 
/ 
/ 
/ 
/H H H H6 6 6 6 6 6  %*    2   0 0 0 0F F F F
+
 +
 +
 +
Z         r   r,   c                  L     e Zd Z	 dd fdZedd            ZddZddZ xZS )rk   Frn   rv   rc   r   ro   r.   rg   rh   decode_contentrO   r   r"   c                r    t                                          ||dd ||           || _        d| _        d S )N   )rn   rc   versionreasonr   ro   r   )r;   r   _datalength_remaining)r   rn   rc   ro   rg   r   r<   s         r   r   zHTTP2Response.__init__   sO     	)# 	 		
 		
 		
 
 !r   c                    | j         S r   )r   r   s    r   rg   zHTTP2Response.data   s
    zr   c                    d S r   r*   r   s    r   get_redirect_locationz#HTTP2Response.get_redirect_location   s    tr   c                    d S r   r*   r   s    r   r}   zHTTP2Response.close   s    r   )F)rn   rv   rc   r   ro   r.   rg   rh   r   rO   r   r"   )r   rh   r   )	r&   r'   r(   r   propertyrg   r   r}   r   r   s   @r   rk   rk      s          %" " " " " " "*    X          r   rk   r   r"   c                     t           t          _        t           t          j        _        dgt          j        j        _        d S )NrA   )	r,   r   ConnectionClsurllib3rC   r   utilssl_ALPN_PROTOCOLSr*   r   r   inject_into_urllib3r      s-    (7%)8G& )-vGL$$$r   c                     t           t          _        t           t          j        _        dgt          j        j        _        d S )Nzhttp/1.1)	orig_HTTPSConnectionr   r   r   rC   r   r   r   r   r*   r   r   extract_from_urllib3r      s+    (<%)=G&(2|GL$$$r   r   )
__future__r   r   typestyping	h2.configrA   h2.connection	h2.eventsurllib3.connectionr   urllib3.util.ssl_urllib3.responser   _collectionsr   rC   r   connectionpoolr   r   TypeVarr	   Genericr   r,   rk   r   r   r*   r   r   <module>r      s   " " " " " "                           - - - - - - ( ( ( ( ( ( ' ' ' ' ' ' / / / / / /& FN3    FN1%   6A A A A Ao A A AH    $   D. . . .4 4 4 4 4 4r   