o
    Uhf8                     @  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   R/var/www/html/status_management/venv/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)client_side)config)h2r8   H2Configurationr	   
connectionH2Connection)r   r8   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/   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_urlget_next_available_stream_idr0   r&   r(   r1   extendencode)r   rC   rD   rE   rG   rB   	authorityr   r   r   
putrequestK   s   




"zHTTP2Connection.putrequestheadervaluesc                 G  s.   |D ]}| j |d |df qd S )Nzutf-8)r1   appendrM   lower)r   rP   rQ   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   rA   r?   r@   )r   rB   rA   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   r[   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)statusrW   request_urlr[   )	bytearrayr/   r?   recvreceive_data
isinstancer9   eventsResponseReceivedr   rW   intdecodeaddDataReceivedr[   acknowledge_received_dataflow_controlled_lengthrV   StreamEndedrA   r@   closer^   rJ   r\   )r   r`   r[   rB   rX   received_datarf   eventrW   rP   rT   rA   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/   close_connectionrA   r?   r@   	Exceptionr.   r0   r1   r3   ro   )r   rB   r[   r4   r   r   ro      s   
	zHTTP2Connection.closer   )r&   r'   r(   r)   r*   r+   r   r   )r   r6   r   r   )FF)
rC   r'   rD   r'   rE   rF   rG   rF   r   r   )rP   r'   rQ   r'   r   r   )r[   r\   r   r   )r   r^   )r!   r"   r#   r   r.   r=   rO   rU   rZ   r]   rr   ro   __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 )r^   Fr`   rh   rW   r   ra   r'   r[   r\   decode_contentrF   r   r   c                   s(   t  j||dd ||d || _d| _d S )N   )r`   rW   versionreasonrw   ra   r   )r3   r   _datalength_remaining)r   r`   rW   ra   r[   rw   r4   r   r   r      s   

zHTTP2Response.__init__c                 C  s   | j S r   )r{   r   r   r   r   r[      s   zHTTP2Response.datac                 C     d S r   r   r   r   r   r   get_redirect_location      z#HTTP2Response.get_redirect_locationc                 C  r}   r   r   r   r   r   r   ro      r   zHTTP2Response.close)F)r`   rh   rW   r   ra   r'   r[   r\   rw   rF   r   r   )r   r\   ru   )	r!   r"   r#   r   propertyr[   r~   ro   rv   r   r   r4   r   r^      s    
r^   r   r   c                   C     t t_t tj_dgtjj_d S )Nr9   )	r%   r   ConnectionClsurllib3r;   r   utilssl_ALPN_PROTOCOLSr   r   r   r   inject_into_urllib3   s   r   c                   C  r   )Nzhttp/1.1)	orig_HTTPSConnectionr   r   r   r;   r   r   r   r   r   r   r   r   extract_from_urllib3   s   r   ru   )
__future__r   r   typestyping	h2.configr9   h2.connection	h2.eventsurllib3.connectionr   urllib3.util.ssl_urllib3.responser   _collectionsr   r;   r   connectionpoolr   r   TypeVarr   Genericr	   r%   r^   r   r   r   r   r   r   <module>   s*    
 
"