o
ai @ sF d dl Z d dlZd dlZd dlmZ d dlmZ dZG dd dZdS ) N)ProxySchemeUnsupported)sixi @ c @ s e Zd ZdZedd Z d:ddZdd Zd
d Zdd
Z d;ddZ
dddZ
d>ddZ d?ddZdd Zdd Zd@d"d#Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 ZdAd6d7Zd8d9 ZdS )BSSLTransportaL
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.
c C s$ t | dstjrtdtddS )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 /builddir/build/BUILDROOT/alt-python310-pip-21.3.1-5.el8.x86_64/opt/alt/python310/lib/python3.10/site-packages/pip/_vendor/urllib3/util/ssltransport.py$_validate_ssl_context_for_tls_in_tls s
z1SSLTransport._validate_ssl_context_for_tls_in_tlsNTc C sH t | _t | _|| _|| _|j| j| j|d| _| | jj dS )zV
Create an SSLTransport around socket using the provided ssl_context.
)server_hostnameN)
ssl MemoryBIOincomingoutgoingsuppress_ragged_eofssocketr sslobj_ssl_io_loopdo_handshake)selfr r r r r r r
__init__, s
zSSLTransport.__init__c C s | S Nr r r r r
__enter__? s zSSLTransport.__enter__c G s | d S r )close)r _r r r
__exit__B zSSLTransport.__exit__c C
| j S r )r filenor r r r
r E
zSSLTransport.fileno c C s | ||S r )_wrap_ssl_read)r lenbufferr r r
readH r zSSLTransport.readr c C s |dkrt d| |S )Nr z+non-zero flags not allowed in calls to recv)
ValueErrorr# )r r$ flagsr r r
recvK s
zSSLTransport.recvc C s> |dkrt d|r|d u rt|}n|d u rd}| ||S )Nr z0non-zero flags not allowed in calls to recv_intor" )r' r$ r&