o
    2Zh8                     @  s   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dZG d	d
 d
eje ZG dd deZG dd deZdddZdddZdS )    )annotationsN)BaseHTTPResponse   )HTTPHeaderDict)HTTPSConnection)HTTPSConnectionPoolTc                   @  s.   e Zd ZdZdddZdddZd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                 C  s   t  | _|| _d S N)	threadingRLocklock_obj)selfr
    r   D/var/www/html/lang_env/lib/python3.10/site-packages/urllib3/http2.py__init__"   s   

z_LockedObject.__init__returnc                 C  s   | j   | jS r   )r   acquirer   r   r   r   r   	__enter__&   s   
z_LockedObject.__enter__exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbtypes.TracebackType | NoneNonec                 C  s   | j   d S r   )r   release)r   r   r   r   r   r   r   __exit__*   s   z_LockedObject.__exit__N)r
   r   )r   r   )r   r   r   r   r   r   r   r   )__name__
__module____qualname____doc__r   r   r    r   r   r   r   r	      s
    
	
r	   c                      s   e Zd Z	d(d) fd
dZd*ddZd+ fddZ		d,d-ddZd.ddZd+ddZd/d!d"Z	d0d$d%Z
d+ fd&d'Z  ZS )1HTTP2ConnectionNhoststrport
int | Nonekwargs
typing.Anyr   r   c                   sH   |   | _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(   r*   	__class__r   r   r   4   s   
zHTTP2Connection.__init__)_LockedObject[h2.connection.H2Connection]c                 C  s    t jjdd}tt jj|dS )NT)Zclient_side)config)h2r7   ZH2Configurationr	   
connectionZH2Connection)r   r7   r   r   r   r.   @   s   zHTTP2Connection._new_h2_connc                   sN   t    | j}|  | j|  W d    d S 1 s w   Y  d S r   )r3   connectr/   Zinitiate_connectionsocksendalldata_to_send)r   h2_connr4   r   r   r:   D   s
   
"zHTTP2Connection.connectFmethodurl	skip_hostboolskip_accept_encodingc              	   C  s   | j D}|| _| | _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 W d    d S 1 sJw   Y  d S )	N:[z]:i  )s   :schemes   httpss   :methods
   :authoritys   :path)	r/   _request_urlZget_next_available_stream_idr0   r&   r(   r1   extendencode)r   r?   r@   rA   rC   r>   	authorityr   r   r   
putrequestK   s   




"zHTTP2Connection.putrequestheadervaluesc                 G  s.   |D ]}| j |d |df qd S )Nzutf-8)r1   appendrH   lower)r   rK   rL   valuer   r   r   	putheaderd   s
   zHTTP2Connection.putheaderc                 C  sh   | j '}|j| j| jdd |  }r"| j| W d    d S W d    d S 1 s-w   Y  d S )NT)	stream_idheaders
end_stream)r/   send_headersr0   r1   r=   r;   r<   )r   r>   r=   r   r   r   
endheadersj   s   "zHTTP2Connection.endheadersdatabytesc                 C  s   |sd S t d)Nz Sending data isn't supported yet)r2   )r   rV   r   r   r   sendt   s   zHTTP2Connection.sendHTTP2Responsec              	   C  s2  d }t  }| jt}d}|su| jd }rg||}|D ]J}t|tjjrHt	 }|j
D ]\}	}
|	dkr:t|
 }q+||	d|
d q+qt|tjjr]||j7 }||j|j qt|tjjrfd}q|  }rs| j| |rW d    n1 sw   Y  |   |d usJ t||| jt|dS )NFi  s   :statusasciiT)statusrR   request_urlrV   )	bytearrayr/   r;   recvZreceive_data
isinstancer8   eventsZResponseReceivedr   rR   intdecodeaddZDataReceivedrV   Zacknowledge_received_dataZflow_controlled_lengthrQ   ZStreamEndedr=   r<   closerY   rF   rW   )r   r[   rV   r>   rS   Zreceived_datar`   eventrR   rK   rO   r=   r   r   r   getresponsey   sL   

zHTTP2Connection.getresponsec              	     s   | j $}z|  |  }r| j| W n	 ty   Y nw W d    n1 s*w   Y  |  | _ d | _g | _t	 
  d S r   )r/   Zclose_connectionr=   r;   r<   	Exceptionr.   r0   r1   r3   rd   )r   r>   rV   r4   r   r   rd      s   
	zHTTP2Connection.closer   )r&   r'   r(   r)   r*   r+   r   r   )r   r6   r   r   )FF)
r?   r'   r@   r'   rA   rB   rC   rB   r   r   )rK   r'   rL   r'   r   r   )rV   rW   r   r   )r   rY   )r!   r"   r#   r   r.   r:   rJ   rP   rU   rX   rf   rd   __classcell__r   r   r4   r   r%   3   s    





-r%   c                      sD   e Zd Z	dd fddZedddZdddZdddZ  ZS )rY   Fr[   ra   rR   r   r\   r'   rV   rW   decode_contentrB   r   r   c                   s(   t  j||dd ||d || _d| _d S )N   )r[   rR   versionreasonrj   r\   r   )r3   r   _datalength_remaining)r   r[   rR   r\   rV   rj   r4   r   r   r      s   

zHTTP2Response.__init__c                 C  s   | j S r   )rn   r   r   r   r   rV      s   zHTTP2Response.datac                 C     d S r   r   r   r   r   r   get_redirect_location      z#HTTP2Response.get_redirect_locationc                 C  rp   r   r   r   r   r   r   rd      rr   zHTTP2Response.close)F)r[   ra   rR   r   r\   r'   rV   rW   rj   rB   r   r   )r   rW   rh   )	r!   r"   r#   r   propertyrV   rq   rd   ri   r   r   r4   r   rY      s    
rY   r   r   c                   C     t t_t tj_dgtjj_d S )Nr8   )	r%   r   ConnectionClsurllib3r9   r   utilssl_ALPN_PROTOCOLSr   r   r   r   inject_into_urllib3   s   rz   c                   C  rt   )Nzhttp/1.1)	orig_HTTPSConnectionr   ru   rv   r9   r   rw   rx   ry   r   r   r   r   extract_from_urllib3   s   r|   rh   )
__future__r   r   typestypingZ	h2.configr8   Zh2.connectionZ	h2.eventsZurllib3.connectionrv   Zurllib3.util.ssl_Zurllib3.responser   _collectionsr   r9   r   connectionpoolr   r{   TypeVarr   Genericr	   r%   rY   rz   r|   r   r   r   r   <module>   s*    
 
"