U `@sFddlZddlZddlZddlmZddlmZdZGdddZdS)N)ProxySchemeUnsupported)sixi@c@seZdZdZeddZd:ddZdd Zd d Zd d Z d;ddZ dddZ d?ddZd@ddZddZdd ZdAd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5ZdBd6d7Zd8d9ZdS)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|ds"tjrtdntddS)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)hasattrrZPY2r) ssl_contextrJ/opt/alt/python38/lib/python3.8/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 MemoryBIOincomingoutgoingsuppress_ragged_eofssocketrsslobj _ssl_io_loopZ do_handshake)selfrrr rrrr __init__,s  zSSLTransport.__init__cCs|SNrrrrr __enter__?szSSLTransport.__enter__cGs |dSr)close)r_rrr __exit__BszSSLTransport.__exit__cCs |jSr)rfilenorrrr rEszSSLTransport.filenocCs |||Sr)_wrap_ssl_read)rlenbufferrrr readHszSSLTransport.readrcCs|dkrtd||S)Nrz+non-zero flags not allowed in calls to recv) ValueErrorr)rrflagsrrr recvKszSSLTransport.recvcCs>|dkrtd|r&|dkr&t|}n |dkr2d}|||S)Nrz0non-zero flags not allowed in calls to recv_intor)r!rr )rrnbytesr"rrr recv_intoPs  zSSLTransport.recv_intoc Csn|dkrtdd}t|H}|d2}t|}||krV|||d}||7}q2W5QRXW5QRXdS)Nrz.non-zero flags not allowed in calls to sendallB)r! memoryviewcastrsend)rdatar"countZviewZ byte_viewZamountvrrr sendallYszSSLTransport.sendallcCs$|dkrtd||jj|}|S)Nrz+non-zero flags not allowed in calls to send)r!rrwrite)rr*r"Zresponserrr r)cszSSLTransport.sendrc Cst|dddhks td|fd|k}d|kp4| }d|k}d} |rN| d7} |rZ| d7} t|| } |jjd7_|dkrd}|d krtj}|d kr|std | S|r|rt| | |} n|rt| |} n 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. r/wbz&invalid mode %r (only r, w, b allowed)Nrz!unbuffered streams must be binary) setr!rZSocketIOZ_io_refsioDEFAULT_BUFFER_SIZEBufferedRWPairBufferedReaderBufferedWriter TextIOWrappermode) rr< bufferingencodingerrorsnewlineZwritingZreadingZbinaryZrawmoderawrtextrrr makefileis<   zSSLTransport.makefilecCs||jjdSr)rrunwraprrrr rDszSSLTransport.unwrapcCs|jdSr)rrrrrr rszSSLTransport.closeFcCs |j|Sr)r getpeercert)rZ binary_formrrr rEszSSLTransport.getpeercertcCs |jSr)rversionrrrr rFszSSLTransport.versioncCs |jSr)rcipherrrrr rGszSSLTransport.ciphercCs |jSr)rselected_alpn_protocolrrrr rHsz#SSLTransport.selected_alpn_protocolcCs |jSr)rselected_npn_protocolrrrr rIsz"SSLTransport.selected_npn_protocolcCs |jSr)rshared_ciphersrrrr rJszSSLTransport.shared_cipherscCs |jSr)r compressionrrrr rKszSSLTransport.compressioncCs|j|dSr)r settimeout)rvaluerrr rLszSSLTransport.settimeoutcCs |jSr)r gettimeoutrrrr rNszSSLTransport.gettimeoutcCs|jdSr)r_decref_socketiosrrrr rOszSSLTransport._decref_socketiosc Cs\z||jj||WStjk rV}z"|jtjkrD|jrDWY dSW5d}~XYnXdS)Nr)rrr r SSLErrorerrnoZ SSL_ERROR_EOFr)rrrerrr rs  zSSLTransport._wrap_ssl_readc Gsd}d}|rd}z ||}Wn@tjk r\}z |jtjtjfkrF||j}W5d}~XYnX|j}|j||dkrd}q|tjkr|j t }|r|j |q|j q|S)z>Performs an I/O loop between incoming/outgoing and the socket.TNF)r rPrQZSSL_ERROR_WANT_READZSSL_ERROR_WANT_WRITErr rr-r# SSL_BLOCKSIZEr r.Z write_eof)rfuncargsZ should_loopZretrQrRZbufrrr rs(      zSSLTransport._ssl_io_loop)NT)rN)rr)Nr)r)r)r/NNNN)F)N)__name__ __module__ __qualname____doc__ staticmethodr rrrrr r#r%r-r)rCrDrrErFrGrHrIrJrKrLrNrOrrrrrr r sD       -  r) r6rr Zurllib3.exceptionsrZurllib3.packagesrrSrrrrr s