B `@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)hasattrrPY2r) ssl_contextr 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 MemoryBIOincomingoutgoingsuppress_ragged_eofssocketrsslobj _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 |jS)N)rfileno)rr r r rEszSSLTransport.filenocCs |||S)N)_wrap_ssl_read)rlenbufferr r r readHszSSLTransport.readrcCs|dkrtd||S)Nrz+non-zero flags not allowed in calls to recv) ValueErrorr)rrflagsr r r recvKszSSLTransport.recvcCs>|dkrtd|r&|dkr&t|}n |dkr2d}|||S)Nrz0non-zero flags not allowed in calls to recv_intoi)r rr)rrnbytesr!r r r recv_intoPs  zSSLTransport.recv_intoc Csr|dkrtdd}t|L}|d6}t|}x&||krX|||d}||7}q4WWdQRXWdQRXdS)Nrz.non-zero flags not allowed in calls to sendallB)r memoryviewcastrsend)rdatar!countview byte_viewamountvr r r sendallYs zSSLTransport.sendallcCs$|dkrtd||jj|}|S)Nrz+non-zero flags not allowed in calls to send)r rrwrite)rr)r!responser r r r(cszSSLTransport.sendrc Cst|dddhks td|fd|k}d|kp4| }|sB|sBtd|k}d} |rZ| d7} |rf| d7} t|| } |jjd7_|dkrd}|d krtj}|d kr|std | S|r|rt| | |} n&|rt | |} n|stt | |} |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. r2wbz&invalid mode %r (only r, w, b allowed)Nrz!unbuffered streams must be binary) setr AssertionErrorrSocketIO_io_refsioDEFAULT_BUFFER_SIZEBufferedRWPairBufferedReaderBufferedWriter TextIOWrappermode) rrB bufferingencodingerrorsnewlinewritingreadingbinaryrawmoderawrtextr r r makefileis@    zSSLTransport.makefilecCs||jjdS)N)rrunwrap)rr r r rNszSSLTransport.unwrapcCs|jdS)N)rr)rr r r rszSSLTransport.closeFcCs |j|S)N)r getpeercert)rZ binary_formr r r rOszSSLTransport.getpeercertcCs |jS)N)rversion)rr r r rPszSSLTransport.versioncCs |jS)N)rcipher)rr r r rQszSSLTransport.ciphercCs |jS)N)rselected_alpn_protocol)rr r r rRsz#SSLTransport.selected_alpn_protocolcCs |jS)N)rselected_npn_protocol)rr r r rSsz"SSLTransport.selected_npn_protocolcCs |jS)N)rshared_ciphers)rr r r rTszSSLTransport.shared_cipherscCs |jS)N)r compression)rr r r rUszSSLTransport.compressioncCs|j|dS)N)r settimeout)rvaluer r r rVszSSLTransport.settimeoutcCs |jS)N)r gettimeout)rr r r rXszSSLTransport.gettimeoutcCs|jdS)N)r_decref_socketios)rr r r rYszSSLTransport._decref_socketiosc CsTy||jj||Stjk rN}z|jtjkr<|jrPerforms 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)rfuncargsZ should_loopretr[r\bufr r r rs(     zSSLTransport._ssl_io_loop)NT)rN)rr)Nr)r)r)r2NNNN)F)N)__name__ __module__ __qualname____doc__ staticmethodr rrrrrr"r$r/r(rMrNrrOrPrQrRrSrTrUrVrXrYrrr r r r r s4       ,  r) r<rr Zurllib3.exceptionsrZurllib3.packagesrr]rr r r r s