=3 d dl mZ d dlZd dlZd dlZd dlZddlmZ ej rd dl m Z ddlmZm Z ej dd Zej eef Z ej d ZdZ G d d ZdS ) )annotationsN )ProxySchemeUnsupported)Literal )_TYPE_PEER_CERT_RET_TYPE_PEER_CERT_RET_DICT_SelfTSSLTransport)bound_ReturnValuei @ c e Zd ZdZed]d Z d^d_dZd`dZdadZdbdZ dcdddZ dedfd!Z dgdhd&Zdidjd)Z didkd*Z dldddd+dmd3Zdnd4Zdnd5Zej dodpd: Zej dqd= Zdrdsd@ZdtdAZdudCZdtdDZdtdEZdvdGZdtdHZdwdKZdxdLZdndMZdldydOZej dzdR Zej d{dU Zej d|dX Z d}d~d\ZdS )r aL 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. ssl_contextssl.SSLContextreturnNonec D t | d st 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_biozXTLS in TLS requires SSLContext.wrap_bio() which isn't available on non-native SSLContextN)hasattrr )r s k/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib/python3.11/site-packages/urllib3/util/ssltransport.py$_validate_ssl_context_for_tls_in_tlsz1SSLTransport._validate_ssl_context_for_tls_in_tls" s7 {J// (5 NTsocket socket.socketserver_hostname str | Nonesuppress_ragged_eofsboolc t j | _ t j | _ || _ || _ | | j | j | | _ | | j j dS )zV Create an SSLTransport around socket using the provided ssl_context. )r N) ssl MemoryBIOincomingoutgoingr r r sslobj_ssl_io_loopdo_handshake)selfr r r r s r __init__zSSLTransport.__init__2 su $8!!**M4=/ + $+233333r r' r c | S N r' s r __enter__zSSLTransport.__enter__I s r _ typing.Anyc . | d S r* )close)r' r. s r __exit__zSSLTransport.__exit__L s r intc 4 | j S r* )r filenor, s r r5 zSSLTransport.filenoO {!!###r lenbuffertyping.Any | Noneint | bytesc . | || S r* )_wrap_ssl_read)r' r8 r9 s r readzSSLTransport.readR s ""3///r r buflenflagsc V |dk rt d | | S )Nr z+non-zero flags not allowed in calls to recv) ValueErrorr= )r' r? r@ s r recvzSSLTransport.recvU s. A::JKKK""6***r _WriteBuffernbytes int | NoneNone | int | bytesc z |dk rt d |t | }| || S )Nr z0non-zero flags not allowed in calls to recv_into)rB r8 r> )r' r9 rE r@ s r recv_intozSSLTransport.recv_intoZ s@ A::OPPP>[[Fyy(((r databytesc 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)rB memoryviewcastr8 send)r' rJ r@ countview byte_viewamountvs r sendallzSSLTransport.sendallf s1 A::MNNN tyy~~ ^^F&..IIi/00 &.. s4 B>B;BB BB BB#&B#c l |dk rt d | | j j | S )Nr z+non-zero flags not allowed in calls to send)rB r% r$ write)r' rJ r@ s r rP zSSLTransport.sendp s5 A::JKKK !2D999r )encodingerrorsnewlinemodestr bufferingrY rZ r[ 1typing.BinaryIO | typing.TextIO | socket.SocketIOc . 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. > brwz invalid mode z (only r, w, b allowed)rc rb ra r Nr z!unbuffered streams must be binary)setrB r SocketIO_io_refsioDEFAULT_BUFFER_SIZEBufferedRWPairBufferedReaderBufferedWriter TextIOWrapperr\ ) r' r\ r^ rY rZ r[ writingreadingbinaryrawmoderawr9 texts r makefilezSSLTransport.makefileu s 4yyOOO++LTLLLMMM++,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 rw zSSLTransport.unwrap s! $+,-----r c 8 | j d S r* )r r1 r, s r r1 zSSLTransport.close s r .binary_formLiteral[False]_TYPE_PEER_CERT_RET_DICT | Nonec d S r* r+ r' ry s r getpeercertzSSLTransport.getpeercert s r Literal[True]bytes | Nonec d S r* r+ r} s r r~ zSSLTransport.getpeercert r Fr c 6 | j | S r* )r$ r~ r} s r r~ zSSLTransport.getpeercert s {&&{333r c 4 | j S r* )r$ versionr, s r r zSSLTransport.version s {""$$$r tuple[str, str, int] | Nonec 4 | j S r* )r$ cipherr, s r r zSSLTransport.cipher r6 r c 4 | j S r* )r$ selected_alpn_protocolr, s r r z#SSLTransport.selected_alpn_protocol s {11333r c 4 | j S r* )r$ selected_npn_protocolr, s r r z"SSLTransport.selected_npn_protocol s {00222r !list[tuple[str, str, int]] | Nonec 4 | j S r* )r$ shared_ciphersr, s r r zSSLTransport.shared_ciphers s {))+++r c 4 | j S r* )r$ compressionr, s r r zSSLTransport.compression s {&&(((r valuefloat | Nonec : | j | d S r* )r settimeout)r' r s r r zSSLTransport.settimeout s u%%%%%r c 4 | j S r* )r gettimeoutr, s r r zSSLTransport.gettimeout s {%%'''r c 8 | j d S r* )r _decref_socketiosr, s r r zSSLTransport._decref_socketios s %%'''''r bytearray | Nonec | | 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' r8 r9 es r r= zSSLTransport._wrap_ssl_read sm $$T[%5sFCCC| w#+++0I+qqqqq s # AAAAfunctyping.Callable[[], None]c d S r* r+ )r' r s r r% zSSLTransport._ssl_io_loop r r typing.Callable[[bytes], int]arg1c d S r* r+ )r' r r s r r% zSSLTransport._ssl_io_loop r r /typing.Callable[[int, bytearray | None], bytes]arg2c d S r* r+ )r' r r r s r r% zSSLTransport._ssl_io_loop s r "typing.Callable[..., _ReturnValue]None | bytes | intr c f d}d}|rd} | | | }n| || }n ||| }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 |t j t | 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 rV rC SSL_BLOCKSIZEr" rX write_eoftypingrO r ) r' r r r should_loopretr r bufs r r% zSSLTransport._ssl_io_loop sX .E