e\ T d dl Z d dlZd dlZddlmZ ddlmZ dZ G d d ZdS ) N )ProxySchemeUnsupported)sixi @ c e Zd ZdZed Z d!dZd Zd Zd Z d"d Z d#dZd$d Zd%dZ d%dZ d&dZd Zd Zd'dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd(dZd ZdS ))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. c z t | d s*t j rt d t d 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_contexts w/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib/python3.11/site-packages/pip/_vendor/urllib3/util/ssltransport.py$_validate_ssl_context_for_tls_in_tlsz1SSLTransport._validate_ssl_context_for_tls_in_tls sZ {J// w ,, -9 NTc t j | _ t j | _ || _ || _ | | j | j | | _ | | j j 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 s r __init__zSSLTransport.__init__, su $8!!**M4=/ + $+233333r c | S N r s r __enter__zSSLTransport.__enter__? s r c . | d S r )close)r _s r __exit__zSSLTransport.__exit__B s r c 4 | j S r )r filenor s r r' zSSLTransport.filenoE {!!###r c . | || S r )_wrap_ssl_read)r lenbuffers r readzSSLTransport.readH s ""3///r r c V |dk rt d | | S )Nr z+non-zero flags not allowed in calls to recv) ValueErrorr+ )r r, flagss r recvzSSLTransport.recvK s. A::JKKK""3'''r c |dk rt d |r|t | }n|d}| || S )Nr z0non-zero flags not allowed in calls to recv_intor) )r0 r, r. )r r- nbytesr1 s r recv_intozSSLTransport.recv_intoP sQ A::OPPP v~[[FF ^Fyy(((r c X |dk rt d d}t | 5 }| d 5 }t | }||k r(| ||d }||z }||k (d d d n# 1 swxY w Y d d d d S # 1 swxY w Y d S )Nr z.non-zero flags not allowed in calls to sendallB)r0 memoryviewcastr, send)r datar1 countview byte_viewamountvs r sendallzSSLTransport.sendallY s1 A::MNNN tyy~~ ^^F&..IIi/00 &.. s4 B>B;BB BB BB#&B#c p |dk rt d | | j j | }|S )Nr z+non-zero flags not allowed in calls to send)r0 r r write)r r; r1 responses r r: zSSLTransport.sendc s9 A::JKKK$$T[%6==r rc . t | h dk st d|d d|v }d|v p| }|s|sJ d|v }d} |r| dz } |r| dz } t j | | } | j xj dz c_ |d }|dk rt j }|dk r|st d | S |r|rt j | | | }n1|rt j | | }n|sJ t j | | }|r|S t j |||| }||_ |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. > brE wz invalid mode z (only r, w, b allowed)rH rE rG Nr z!unbuffered streams must be binary)setr0 r SocketIO_io_refsioDEFAULT_BUFFER_SIZEBufferedRWPairBufferedReaderBufferedWriter TextIOWrappermode) r rU bufferingencodingerrorsnewlinewritingreadingbinaryrawmoderawr- texts r makefilezSSLTransport.makefilei s~ 4yyOOO++*OPPP++,W!'!!! sNG sNGodG,,!Iq==.I>> F !DEEEJ 7w 7&sC;;FF 7&sI66FFNN7&sI66F M&'BB r c D | | j j d S r )r r unwrapr s r rb zSSLTransport.unwrap s! $+,-----r c 8 | j d S r )r r# r s r r# zSSLTransport.close s r Fc 6 | j | S r )r getpeercert)r binary_forms r re zSSLTransport.getpeercert s {&&{333r c 4 | j S r )r versionr s r rh zSSLTransport.version s {""$$$r c 4 | j S r )r cipherr s r rj zSSLTransport.cipher r( r c 4 | j S r )r selected_alpn_protocolr s r rl z#SSLTransport.selected_alpn_protocol s {11333r c 4 | j S r )r selected_npn_protocolr s r rn z"SSLTransport.selected_npn_protocol s {00222r c 4 | j S r )r shared_ciphersr s r rp zSSLTransport.shared_ciphers s {))+++r c 4 | j S r )r compressionr s r rr zSSLTransport.compression s {&&(((r c : | j | d S r )r settimeout)r values r rt zSSLTransport.settimeout s u%%%%%r c 4 | j S r )r gettimeoutr s r rw zSSLTransport.gettimeout s {%%'''r c 8 | j d S r )r _decref_socketiosr s r ry zSSLTransport._decref_socketios s %%'''''r c | | j j || S # t j $ r(}|j t j k r | j rY d }~dS d }~ww xY wNr )r r r. r SSLErrorerrno SSL_ERROR_EOFr )r r, r- es r r+ zSSLTransport._wrap_ssl_read sm $$T[%5sFCCC| w#+++0I+qqqqq s # AAAAc d}d}|rd} || }nD# t j $ r2}|j t j t j fvr||j }Y d}~nd}~ww xY w| j }| j | |d}ne|t j k rU| j t }|r| j | n| j ||S )z>Performs an I/O loop between incoming/outgoing and the socket.TNF)r r| r} SSL_ERROR_WANT_READSSL_ERROR_WANT_WRITEr r. r rA r2 SSL_BLOCKSIZEr rC write_eof)r funcargsshould_loopretr} r bufs r r zSSLTransport._ssl_io_loop s .E dDk<