o
    ÒèFh8  ã                   @  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   úF/var/www/html/loop/nvenv/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sŽJ ‚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*    
 
"