5,j"ddlmZddlZddlZddlZddlZddlmZejrddl m Z ddl m Z m Z ejeefZejdZd ZGd d ZdS) ) annotationsN)ProxySchemeUnsupported)Self)_TYPE_PEER_CERT_RET_TYPE_PEER_CERT_RET_DICT _ReturnValuei@ceZdZdZed[dZ d\d]dZd^dZd_dZd`dZ dadbdZ dcddd Z dedfd%Z dgdhd(Z dgdid)Z djdddd*dkd2Zdld3Zdld4Zej dmdnd9Zejdod<Zdpdqd?Zdrd@ZdsdBZdrdCZdtdEZdrdFZdudIZdvdJZdldKZdjdwdMZejdxdPZejdydSZejdzdVZ d{d|dZZdS)} 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. ssl_contextssl.SSLContextreturnNonecDt|dstddS)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 IC:\PYTHON\GemmaClient\venv\Lib\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_eofsboolctj|_tj|_||_||_||j|j||_||jj dS)zV Create an SSLTransport around socket using the provided ssl_context. )rN) ssl MemoryBIOincomingoutgoingrrrsslobj _ssl_io_loop do_handshake)selfrr rrs r__init__zSSLTransport.__init__1su    $8! !** M4=/+   $+233333rrc|SNr%s r __enter__zSSLTransport.__enter__Hs r_ typing.Anyc.|dSr()close)r%r,s r__exit__zSSLTransport.__exit__Ks rintc4|jSr()rfilenor*s rr3zSSLTransport.filenoN{!!###rlenbuffertyping.Any | None int | bytesc.|||Sr()_wrap_ssl_read)r%r6r7s rreadzSSLTransport.readQs""3///rrbuflenflagscV|dkrtd||S)Nrz+non-zero flags not allowed in calls to recv) ValueErrorr;)r%r=r>s rrecvzSSLTransport.recvTs. A::JKK K""6***r _WriteBuffernbytes int | NoneNone | int | bytescz|dkrtd|t|}|||S)Nrz0non-zero flags not allowed in calls to recv_into)r@r6r<)r%r7rCr>s r recv_intozSSLTransport.recv_intoYs@ A::OPP P >[[Fyy(((rdatabytescX|dkrtdd}t|5}|d5}t|}||kr(|||d}||z }||k(dddn #1swxYwYddddS#1swxYwYdS)Nrz.non-zero flags not allowed in calls to sendallB)r@ memoryviewcastr6send)r%rHr>countview byte_viewamountvs rsendallzSSLTransport.sendalles1 A::MNN N    tyy~~ ^^F&..IIi/00 &..                                 s4B>B; BB BB BB#&B#cl|dkrtd||jj|S)Nrz+non-zero flags not allowed in calls to send)r@r#r"write)r%rHr>s rrNzSSLTransport.sendos5 A::JKK K  !2D999r)encodingerrorsnewlinemodestr bufferingrWrXrY1typing.BinaryIO | typing.TextIO | socket.SocketIOc.t|hdkstd|dd|v}d|vp| }|s|sJd|v}d} |r| dz } |r| dz } tj|| } |jxjdz c_|d }|d kr t j}|d kr|std | S|r|rt j| | |} n1|rt j| |} n|sJt j | |} |r| St 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)rar`r_rNrz!unbuffered streams must be binary) setr@rSocketIO_io_refsioDEFAULT_BUFFER_SIZEBufferedRWPairBufferedReaderBufferedWriter TextIOWrapperrZ) r%rZr\rWrXrYwritingreadingbinaryrawmoderawr7texts rmakefilezSSLTransport.makefilets 4yyOOO++LTLLLMM M++,W!'!!!   sNG   sNGodG,, !  I q==.I >> F !DEEEJ  7w 7&sC;;FF  7&sI66FFNN7&sI66F  M&'BB  rcD||jjdSr()r#r"unwrapr*s rruzSSLTransport.unwraps! $+,-----rc8|jdSr()rr/r*s rr/zSSLTransport.closes r. binary_formtyping.Literal[False]_TYPE_PEER_CERT_RET_DICT | NonecdSr(r)r%rws r getpeercertzSSLTransport.getpeercerts +.#rtyping.Literal[True] bytes | NonecdSr(r)r{s rr|zSSLTransport.getpeercertsNQcrFrc6|j|Sr()r"r|r{s rr|zSSLTransport.getpeercerts{&&{333rc4|jSr()r"versionr*s rrzSSLTransport.versions{""$$$rtuple[str, str, int] | Nonec4|jSr()r"cipherr*s rrzSSLTransport.cipherr4rc4|jSr()r"selected_alpn_protocolr*s rrz#SSLTransport.selected_alpn_protocols{11333r!list[tuple[str, str, int]] | Nonec4|jSr()r"shared_ciphersr*s rrzSSLTransport.shared_cipherss{))+++rc4|jSr()r" compressionr*s rrzSSLTransport.compressions{&&(((rvalue float | Nonec:|j|dSr()r settimeout)r%rs rrzSSLTransport.settimeouts u%%%%%rc4|jSr()r gettimeoutr*s rrzSSLTransport.gettimeouts{%%'''rc8|jdSr()r_decref_socketiosr*s rrzSSLTransport._decref_socketioss %%'''''rbytearray | Nonec ||jj||S#tj$r(}|jtjkr |jrYd}~dSd}~wwxYwNr)r#r"r<rSSLErrorerrno SSL_ERROR_EOFr)r%r6r7es rr;zSSLTransport._wrap_ssl_readsm $$T[%5sFCC C|   w#+++0I+qqqqq  s #AAAAfunctyping.Callable[[], None]cdSr(r))r%rs rr#zSSLTransport._ssl_io_loopsEHSrtyping.Callable[[bytes], int]arg1cdSr(r))r%rrs rr#zSSLTransport._ssl_io_loopsUXUXr/typing.Callable[[int, bytearray | None], bytes]arg2cdSr(r))r%rrrs rr#zSSLTransport._ssl_io_loops r"typing.Callable[..., _ReturnValue]None | bytes | intr cfd}d}|rd} | | |}n| ||}n |||}nD#tj$r2}|jtjtjfvr||j}Yd}~nd}~wwxYw|j}|j||d}ne|tjkrU|j t}|r|j |n|j |tjt |S)z>Performs an I/O loop between incoming/outgoing and the socket.TNF)rrrSSL_ERROR_WANT_READSSL_ERROR_WANT_WRITEr!r<rrTrA SSL_BLOCKSIZEr rV write_eoftypingrMr ) r%rrr should_loopretrrbufs rr#zSSLTransport._ssl_io_loopsX  .E r1rr9r)r7rBrCrDr>r1rrE)r)rHrIr>r1rr)rHrIr>r1rr1r() rZr[r\rDrWrrXrrYrrr])rr).)rwrxrry)rwr}rr~)F)rwrrr)rr)rr)rr)rrrr)rr)r6r1r7rrr9)rrrr)rrrrIrr1)rrrr1rrrrI)NN)rrrrrrrr )__name__ __module__ __qualname____doc__ staticmethodrr&r+r0r3r<rArGrTrNrsrur/roverloadr|rrrrrrrrr;r#r)rrr r s    \ &'+%) 44444.$$$$00000+++++" ) ) ) ) ):::::!%2 $!"222222h.... _36...._. _QQQ_Q44444%%%%$$$$4444,,,,))))&&&&(((((((( _HHH_H _XXX_X __$(!% $.$.$.$.$.$.$.rr ) __future__rrgrrr exceptionsr TYPE_CHECKINGtyping_extensionsrssl_rr Union bytearrayrLrBTypeVarr rr r)rrrs"""""" ////// D&&&&&&CCCCCCCC|Iz12 v~n--  y.y.y.y.y.y.y.y.y.y.r