o
    .jy                     @  s   d dl mZ d dlZd dlmZ d dlmZ d dlmZ	 ej
r7ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZmZmZmZ G dd dedZdS )    )annotationsN)ABCMeta)contextmanager)timeout   )HttpVersion)DirectStreamAccess)HTTPResponse)TrafficPolice)BaseSSLErrorProtocolErrorReadTimeoutErrorSSLErrorMustRedialErrorc                   @  s   e Zd ZdZd4ddZed5ddZed5d	d
Zed6ddZ	d7ddZ
ed8ddZed9ddZed:ddZed;ddZed<dd Zd=d$d%Zd4d&d'Zd>d)d*Zd?d-d.Zd@d1d2Zd3S )AExtensionFromHTTPzRepresent an extension that can be negotiated just after a "101 Switching Protocol" HTTP response.
    This will considerably ease downstream integration.returnNonec                 C  s   d | _ d | _d | _d S N)_dsa	_response_police_officerself r   [/home/thesage/.local/lib/python3.10/site-packages/urllib3/contrib/webextensions/protocol.py__init__   s   
zExtensionFromHTTP.__init__"typing.Generator[None, None, None]c              
   c  s    d}zzdV  W nh t y- } zd}| jr t| jdr | jjnd}t|dd|d}~w ty[ } z#dt|vr?t||d}| jrNt| jdrN| jjnd}t|dd|d}~w tt	fyq } z	t
d|||d}~ww d}W |s| jr|   dS dS dS |s| jr|   w w w )
        Catch low-level python exceptions, instead re-raising urllib3
        variants, so that low-level exceptions are not leaked in the
        high-level api.

        On unrecoverable issues, release the connection back to the pool.
        FNT_poolRead timed out.zread operation timed outConnection broken: )SocketTimeoutr   hasattrr   r   r   strr   OSErrorr   r   closer   
clean_exitepoolr   r   r   _read_error_catcher    sT   	






z%ExtensionFromHTTP._read_error_catcherc              
   c  s    d}z^zdV  W nF t y+ } z| jrt| jdr| jjnd}t|dd|d}~w ty; } zt||d}~w tyO } z	td|||d}~ww d}W |s^| jr`| 	  dS dS dS |sl| jrm| 	  w w w )r   FNr   r   r    T)
r!   r   r"   r   r   r   r   r$   r   r%   r&   r   r   r   _write_error_catcherV   s@   	




z&ExtensionFromHTTP._write_error_catcherdict[str, typing.Any]c                 C  s   i S )zIReturn prerequisites. Must be passed as additional parameters to urlopen.r   r   r   r   r   urlopen_kwargs      z ExtensionFromHTTP.urlopen_kwargsresponser	   c                 C  s:   |j du st|j dstd|j j| _|j| _|| _dS )zEThe HTTP server gave us the go-to start negotiating another protocol.Nr   zJAttempt to start an HTTP extension without direct I/O access to the stream)_fpr"   RuntimeErrorr   r   r   )r   r/   r   r   r   start   s   

zExtensionFromHTTP.startboolc                 C  s
   | j d u S r   )r   r   r   r   r   closed   s   
zExtensionFromHTTP.closedset[HttpVersion]c                   C     t )z3Hint about supported parent SVN for this extension.NotImplementedErrorr   r   r   r   supported_svn   r.   zExtensionFromHTTP.supported_svnr#   c                   C  r6   r   r7   r   r   r   r   implementation      z ExtensionFromHTTP.implementationset[str]c                   C  r6   )z%Recognized schemes for the extension.r7   r   r   r   r   supported_schemes   r.   z#ExtensionFromHTTP.supported_schemesschemec                 C  r6   )zJConvert the extension scheme to a known http scheme (either http or https)r7   )r>   r   r   r   scheme_to_http_scheme   r.   z'ExtensionFromHTTP.scheme_to_http_schemehttp_versionr   dict[str, str]c                 C  r6   )zHSpecific HTTP headers required (request) before the 101 status response.r7   )r   r@   r   r   r   headers   r;   zExtensionFromHTTP.headersc                 C  r6   )z"End/Notify close for sub protocol.r7   r   r   r   r   r%      r;   zExtensionFromHTTP.closestr | bytes | Nonec                 C  r6   )zUnpack the next received message/payload from remote. This call does read from the socket.
        If the method return None, it means that the remote closed the (extension) pipeline.
        r7   r   r   r   r   next_payload   s   zExtensionFromHTTP.next_payloadbufstr | bytesc                 C  r6   )zDispatch a buffer to remote.r7   )r   rE   r   r   r   send_payload   r;   zExtensionFromHTTP.send_payloadcallback+typing.Callable[[str | bytes | None], None]c                 C  r6   )zSet up a callback that will be invoked automatically once a payload is received.
        Meaning that you stop calling manually next_payload().r7   )r   rH   r   r   r   
on_payload   r.   zExtensionFromHTTP.on_payloadN)r   r   )r   r   )r   r,   )r/   r	   r   r   )r   r3   )r   r5   )r   r#   )r   r<   )r>   r#   r   r#   )r@   r   r   rA   )r   rC   )rE   rF   r   r   )rH   rI   r   r   )__name__
__module____qualname____doc__r   r   r*   r+   propertyr-   r2   r4   staticmethodr9   r:   r=   r?   rB   r%   rD   rG   rJ   r   r   r   r   r      s2    
5*




r   )	metaclass)
__future__r   typingabcr   
contextlibr   socketr   r!   TYPE_CHECKINGbackendr   backend._baser   r/   r	   util.traffic_policer
   
exceptionsr   r   r   r   r   r   r   r   r   r   <module>   s    	