
    !)f8                       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y)    )annotationsN)BaseHTTPResponse   )HTTPHeaderDict)HTTPSConnection)HTTPSConnectionPoolTc                  8    e Zd ZdZddZddZ	 	 	 	 	 	 	 	 ddZy)	_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.
    c                D    t        j                         | _        || _        y N)	threadingRLocklock_obj)selfobjs     J/var/www/html/flask-app/venv/lib/python3.12/site-packages/urllib3/http2.py__init__z_LockedObject.__init__"   s    OO%		    c                N    | j                   j                          | j                  S r   )r   acquirer   r   s    r   	__enter__z_LockedObject.__enter__&   s    		yyr   c                8    | j                   j                          y r   )r   release)r   exc_typeexc_valexc_tbs       r   __exit__z_LockedObject.__exit__*   s     			r   N)r   r	   )returnr	   )r   ztype[BaseException] | Noner   zBaseException | Noner   ztypes.TracebackType | Noner!   None)__name__
__module____qualname____doc__r   r   r     r   r   r   r      s<    , & +	
 
r   r   c                       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 )HTTP2Connectionc                    | j                         | _        d | _        g | _        d|v sd|v rt	        d      t        |   ||fi | y )Nproxyproxy_configz$Proxies aren't supported with HTTP/2)_new_h2_conn_h2_conn
_h2_stream_h2_headersNotImplementedErrorsuperr   )r   hostportkwargs	__class__s       r   r   zHTTP2Connection.__init__4   sS     ))+&*68f& 8%&LMMt.v.r   c                    t         j                  j                  d      }t        t         j                  j                  |            S )NT)client_side)config)h2r9   H2Configurationr   
connectionH2Connection)r   r9   s     r   r-   zHTTP2Connection._new_h2_conn@   s6    **t*<R]]77v7FGGr   c                    t         |           | j                  5 }|j                          | j                  j                  |j                                d d d        y # 1 sw Y   y xY wr   )r2   connectr.   initiate_connectionsocksendalldata_to_send)r   h2_connr6   s     r   r?   zHTTP2Connection.connectD   sR    ]] 	6g'')IIg2245	6 	6 	6s   :AA(c           	        | j                   5 }|| _        |j                         | _        d| j                  v r!d| j                   d| j
                  xs d }n| j                   d| j
                  xs d }| j                  j                  dd|j                         fd|j                         fd|j                         ff       d d d        y # 1 sw Y   y xY w)	N:[z]:i  )s   :schemes   httpss   :methods
   :authoritys   :path)	r.   _request_urlget_next_available_stream_idr/   r3   r4   r0   extendencode)r   methodurl	skip_hostskip_accept_encodingrD   	authoritys          r   
putrequestzHTTP2Connection.putrequestK   s     ]] 	g #D%BBDDOdii		{"TYY-=#,>?	#yyk499+;*<=	##*1"I$4$4$67szz|,		 	 	s   B:CCc                    |D ]K  }| j                   j                  |j                  d      j                         |j                  d      f       M y )Nzutf-8)r0   appendrK   lower)r   headervaluesvalues       r   	putheaderzHTTP2Connection.putheaderd   sH     	E##w'--/g1FG	r   c                    | j                   5 }|j                  | j                  | j                  d       |j	                         x}r| j
                  j                  |       d d d        y # 1 sw Y   y xY w)NT)	stream_idheaders
end_stream)r.   send_headersr/   r0   rC   rA   rB   )r   rD   rC   s      r   
endheaderszHTTP2Connection.endheadersj   sn    ]] 	0g  //(( ! 
  '3355|5		!!,/	0 	0 	0s   AA,,A5c                    |sy t        d      )Nz Sending data isn't supported yet)r1   )r   datas     r   sendzHTTP2Connection.sendt   s    !"DEEr   c           	        d }t               }| j                  5 }d}|s}| j                  j                  d      x}r.|j	                  |      }|D ]  }t        |t        j                  j                        rnt               }|j                  D ]T  \  }	}
|	dk(  rt        |
j                               }%|j                  |	j                  d      |
j                  d             V t        |t        j                  j                        r6||j                  z  }|j!                  |j"                  |j$                         t        |t        j                  j&                        sd} |j)                         x}r| j                  j+                  |       |s}d d d        | j-                          |J t/        || j0                  t3        |            S # 1 sw Y   ?xY w)NFi  s   :statusasciiT)statusr[   request_urlr`   )	bytearrayr.   rA   recvreceive_data
isinstancer:   eventsResponseReceivedr   r[   intdecodeaddDataReceivedr`   acknowledge_received_dataflow_controlled_lengthrZ   StreamEndedrC   rB   closeHTTP2ResponserH   bytes)r   rd   r`   rD   r\   received_datarj   eventr[   rU   rW   rC   s               r   getresponsezHTTP2Connection.getresponsey   s    {]] 	4gJ $(IINN5$99=9$11-@F!' .%eRYY-G-GH&4&6G16 &#)Z#7-0-@F$+KK(.g(>W@U%&	& (ryy/E/EF EJJ.D#== % < <eoo (ryy/D/DE)-J%.( $+#7#7#99<9II%%l33 !	4< 	

!!))t	
 	
C	4 	4s   EG&4GG#c                D   | j                   5 }	 |j                          |j                         x}r| j                  j	                  |       d d d        | j                         | _         d | _        g | _        t        | )          y # t
        $ r Y Ew xY w# 1 sw Y   JxY wr   )r.   close_connectionrC   rA   rB   	Exceptionr-   r/   r0   r2   rs   )r   rD   r`   r6   s      r   rs   zHTTP2Connection.close   s    ]] 	g((*"//1141II%%d+		 ))+  	 	s(   B=B	BBBBBr   )r3   strr4   z
int | Noner5   z
typing.Anyr!   r"   )r!   z)_LockedObject[h2.connection.H2Connection]r!   r"   )FF)
rL   r|   rM   r|   rN   boolrO   r~   r!   r"   )rU   r|   rV   r|   r!   r"   )r`   ru   r!   r"   )r!   rt   )r#   r$   r%   r   r-   r?   rQ   rX   r^   ra   rx   rs   __classcell__r6   s   @r   r)   r)   3   s    ,0
/
/)
/<F
/	
/H6  %*  	
 # 
20F
+
	+
Z r   r)   c                  \     e Zd Z	 d	 	 	 	 	 	 	 	 	 	 	 d fdZedd       ZddZddZ xZS )	rt   c                L    t         |   ||dd ||       || _        d| _        y )N   )rd   r[   versionreasondecode_contentre   r   )r2   r   _datalength_remaining)r   rd   r[   re   r`   r   r6   s         r   r   zHTTP2Response.__init__   s:     	)# 	 		
 
 !r   c                    | j                   S r   )r   r   s    r   r`   zHTTP2Response.data   s    zzr   c                     y r   r'   r   s    r   get_redirect_locationz#HTTP2Response.get_redirect_location   s    r   c                     y r   r'   r   s    r   rs   zHTTP2Response.close   s    r   )F)rd   rl   r[   r   re   r|   r`   ru   r   r~   r!   r"   )r!   ru   r}   )	r#   r$   r%   r   propertyr`   r   rs   r   r   s   @r   rt   rt      se      %""  " 	"
 " " 
"*  r   rt   c                     t         t        _        t         t        j                  _        dgt        j                  j                  _        y )Nr:   )	r)   r   ConnectionClsurllib3r<   r   utilssl_ALPN_PROTOCOLSr'   r   r   inject_into_urllib3r      s/    (7%)8G& )-vGLL$r   c                     t         t        _        t         t        j                  _        dgt        j                  j                  _        y )Nzhttp/1.1)	orig_HTTPSConnectionr   r   r   r<   r   r   r   r   r'   r   r   extract_from_urllib3r      s-    (<%)=G&(2|GLL$r   r}   )
__future__r   r   typestyping	h2.configr:   h2.connection	h2.eventsurllib3.connectionr   urllib3.util.ssl_urllib3.responser   _collectionsr   r<   r   connectionpoolr   r   TypeVarr	   Genericr   r)   rt   r   r   r'   r   r   <module>r      s~    "         - ( ' /& FNN3FNN1% 6Ao AH$ D.4r   