Your IP : 18.191.178.145


Current Path : /opt/alt/python37/lib/python3.7/site-packages/urllib3/util/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/urllib3/util/__pycache__/ssltransport.cpython-37.pyc

B

��`��@sFddlZddlZddlZddlmZddlmZdZGdd�d�ZdS)�N)�ProxySchemeUnsupported)�sixi@c@s�eZdZdZedd��Zd:dd�Zdd	�Zd
d�Zdd
�Z	d;dd�Z
d<dd�Zd=dd�Zd>dd�Z
d?dd�Zd@dd�Zdd�Zdd �ZdAd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�ZdBd6d7�Zd8d9�ZdS)C�SSLTransportaL
    The SSLTransport wraps an existing socket and establishes an SSL connection.

    Contrary to Python's implementation of SSLSocket, it allows you to chain
    multiple TLS connections together. It's particularly useful if you need to
    implement TLS within TLS.

    The class supports most of the socket API operations.
    cCs&t|d�s"tjrtd��ntd��dS)z�
        Raises a ProxySchemeUnsupported if the provided ssl_context can't be used
        for TLS in TLS.

        The only requirement is that the ssl_context provides the 'wrap_bio'
        methods.
        �wrap_biozKTLS in TLS requires SSLContext.wrap_bio() which isn't supported on Python 2zXTLS in TLS requires SSLContext.wrap_bio() which isn't available on non-native SSLContextN)�hasattrr�PY2r)�ssl_context�r	�J/opt/alt/python37/lib/python3.7/site-packages/urllib3/util/ssltransport.py�$_validate_ssl_context_for_tls_in_tlss

z1SSLTransport._validate_ssl_context_for_tls_in_tlsNTcCsHt��|_t��|_||_||_|j|j|j|d�|_|�|jj	�dS)zV
        Create an SSLTransport around socket using the provided ssl_context.
        )�server_hostnameN)
�sslZ	MemoryBIO�incoming�outgoing�suppress_ragged_eofs�socketr�sslobj�_ssl_io_loopZdo_handshake)�selfrrrrr	r	r
�__init__,s

zSSLTransport.__init__cCs|S)Nr	)rr	r	r
�	__enter__?szSSLTransport.__enter__cGs|��dS)N)�close)r�_r	r	r
�__exit__BszSSLTransport.__exit__cCs
|j��S)N)r�fileno)rr	r	r
rEszSSLTransport.fileno�cCs|�||�S)N)�_wrap_ssl_read)r�len�bufferr	r	r
�readHszSSLTransport.readrcCs|dkrtd��|�|�S)Nrz+non-zero flags not allowed in calls to recv)�
ValueErrorr)rr�flagsr	r	r
�recvKszSSLTransport.recvcCs>|dkrtd��|r&|dkr&t|�}n|dkr2d}|�||�S)Nrz0non-zero flags not allowed in calls to recv_intoi)r rr)rr�nbytesr!r	r	r
�	recv_intoPs
zSSLTransport.recv_intoc
Csr|dkrtd��d}t|��L}|�d��6}t|�}x&||krX|�||d��}||7}q4WWdQRXWdQRXdS)Nrz.non-zero flags not allowed in calls to sendall�B)r �
memoryview�castr�send)r�datar!�count�view�	byte_view�amount�vr	r	r
�sendallYs
zSSLTransport.sendallcCs$|dkrtd��|�|jj|�}|S)Nrz+non-zero flags not allowed in calls to send)r rr�write)rr)r!�responser	r	r
r(cszSSLTransport.send�rc
Cst|�dddhks td|f��d|k}d|kp4|}|sB|sBt�d|k}d}	|rZ|	d7}	|rf|	d7}	t�||	�}
|jjd7_|dkr�d}|d	kr�tj}|d	kr�|s�td
��|
S|r�|r�t�|
|
|�}n&|r�t�	|
|�}n|s�t�t�
|
|�}|r�|St�||||�}||_|S)a
        Python's httpclient uses makefile and buffered io when reading HTTP
        messages and we need to support it.

        This is unfortunately a copy and paste of socket.py makefile with small
        changes to point to the socket directly.
        r2�w�bz&invalid mode %r (only r, w, b allowed)��N���rz!unbuffered streams must be binary)
�setr �AssertionErrorr�SocketIO�_io_refs�io�DEFAULT_BUFFER_SIZE�BufferedRWPair�BufferedReader�BufferedWriter�
TextIOWrapper�mode)
rrB�	buffering�encoding�errors�newline�writing�reading�binary�rawmode�rawr�textr	r	r
�makefileis@
zSSLTransport.makefilecCs|�|jj�dS)N)rr�unwrap)rr	r	r
rN�szSSLTransport.unwrapcCs|j��dS)N)rr)rr	r	r
r�szSSLTransport.closeFcCs|j�|�S)N)r�getpeercert)rZbinary_formr	r	r
rO�szSSLTransport.getpeercertcCs
|j��S)N)r�version)rr	r	r
rP�szSSLTransport.versioncCs
|j��S)N)r�cipher)rr	r	r
rQ�szSSLTransport.ciphercCs
|j��S)N)r�selected_alpn_protocol)rr	r	r
rR�sz#SSLTransport.selected_alpn_protocolcCs
|j��S)N)r�selected_npn_protocol)rr	r	r
rS�sz"SSLTransport.selected_npn_protocolcCs
|j��S)N)r�shared_ciphers)rr	r	r
rT�szSSLTransport.shared_cipherscCs
|j��S)N)r�compression)rr	r	r
rU�szSSLTransport.compressioncCs|j�|�dS)N)r�
settimeout)r�valuer	r	r
rV�szSSLTransport.settimeoutcCs
|j��S)N)r�
gettimeout)rr	r	r
rX�szSSLTransport.gettimeoutcCs|j��dS)N)r�_decref_socketios)rr	r	r
rY�szSSLTransport._decref_socketiosc
CsTy|�|jj||�Stjk
rN}z|jtjkr<|jr<dS�Wdd}~XYnXdS)Nr)rrrr
�SSLError�errnoZ
SSL_ERROR_EOFr)rrr�er	r	r
r�szSSLTransport._wrap_ssl_readc
Gs�d}d}x�|r�d}y||�}Wn@tjk
r^}z |jtjtjfkrH|�|j}Wdd}~XYnX|j��}|j�|�|dkr�d}q
|tjkr
|j�	t
�}|r�|j�|�q
|j�
�q
W|S)z>Performs an I/O loop between incoming/outgoing and the socket.TNF)r
rZr[ZSSL_ERROR_WANT_READZSSL_ERROR_WANT_WRITErrrr/r"�
SSL_BLOCKSIZErr0Z	write_eof)r�func�argsZshould_loop�retr[r\�bufr	r	r
r�s(

zSSLTransport._ssl_io_loop)NT)rN)rr)Nr)r)r)r2NNNN)F)N)�__name__�
__module__�__qualname__�__doc__�staticmethodrrrrrrr"r$r/r(rMrNrrOrPrQrRrSrTrUrVrXrYrrr	r	r	r
rs4	



	



,

	r)	r<rr
Zurllib3.exceptionsrZurllib3.packagesrr]rr	r	r	r
�<module>s

?>