
    9Cg1                       d dl mZ d dlZd dlZd dlZd dlZd dlmZmZ d dl	m
Z
 d dlmZ d dlmZmZ ddlmZmZmZmZ dd	lmZmZ dd
lmZmZmZmZ ej        dk    r	d dlmZmZ nd dl mZmZ  ed          Z! ed          Z"e#e#e$e$f         df         Z%e#e%df         Z& G d de          Z' e
d           G d de                      Z( e
d           G d dee(                               Z)dS )    )annotationsN)CallableMapping)	dataclass)wraps)AnyTypeVar   )BrokenResourceErrorEndOfStreamaclose_forcefullyget_cancelled_exc_class)TypedAttributeSettyped_attribute)AnyByteStream
ByteStreamListener	TaskGroup)      )TypeVarTupleUnpackT_RetvalPosArgsT.c                  @   e Zd ZU dZ e            Zded<    e            Zded<    e            Zded<    e            Z	ded	<    e            Z
d
ed<    e            Zded<    e            Zded<    e            Zded<    e            Zded<    e            Zded<   dS )TLSAttributez5Contains Transport Layer Security related attributes.
str | Nonealpn_protocolbyteschannel_binding_tls_uniqueztuple[str, str, int]cipherz*None | dict[str, str | _PCTRTTT | _PCTRTT]peer_certificatezbytes | Nonepeer_certificate_binaryboolserver_sidez!list[tuple[str, str, int]] | Noneshared_ciphersssl.SSLObject
ssl_objectstandard_compatiblestrtls_versionN)__name__
__module____qualname____doc__r   r   __annotations__r    r!   r"   r#   r%   r&   r(   r)   r+        C/var/www/api/venv/lib/python3.11/site-packages/anyio/streams/tls.pyr   r       s!        ?? !0 1 1M1111(7(9(99999#2?#4#4F4444 FU_EVEVVVVV,;O,=,====='))K)))) 9H8I8INIIII / 1 1J1111 !0 1 11111&((K((((((r2   r   F)eqc                      e Zd ZU dZded<   ded<   ded<   ded	<   ded
<   edddddd*d            Zd+dZd,dZd-dZ	d.d/d$Z
d0d&Zd-d'Zed1d)            ZdS )2	TLSStreama  
    A stream wrapper that encrypts all sent data and decrypts received data.

    This class has no public initializer; use :meth:`wrap` instead.
    All extra attributes from :class:`~TLSAttribute` are supported.

    :var AnyByteStream transport_stream: the wrapped stream

    r   transport_streamr$   r)   r'   _ssl_objectzssl.MemoryBIO	_read_bio
_write_bioNT)r%   hostnamessl_contextr)   r%   bool | Noner;   r   r<   ssl.SSLContext | Nonereturnc                 K   || }|sh|rt           j        j        nt           j        j        }t          j        |          }t          t           d          r|xj        t           j         z  c_        t          j                    }t          j                    }|	                    ||||          }	 | |||	||          }
|

                    |	j                   d{V  |
S )a  
        Wrap an existing stream with Transport Layer Security.

        This performs a TLS handshake with the peer.

        :param transport_stream: a bytes-transporting stream to wrap
        :param server_side: ``True`` if this is the server side of the connection,
            ``False`` if this is the client side (if omitted, will be set to ``False``
            if ``hostname`` has been provided, ``False`` otherwise). Used only to create
            a default context when an explicit context has not been provided.
        :param hostname: host name of the peer (if host name checking is desired)
        :param ssl_context: the SSLContext object to use (if not provided, a secure
            default will be created)
        :param standard_compatible: if ``False``, skip the closing handshake when
            closing the connection, and don't raise an exception if the peer does the
            same
        :raises ~ssl.SSLError: if the TLS handshake fails

        NOP_IGNORE_UNEXPECTED_EOF)r%   server_hostname)r7   r)   r8   r9   r:   )sslPurposeCLIENT_AUTHSERVER_AUTHcreate_default_contexthasattroptionsrA   	MemoryBIOwrap_bio_call_sslobject_methoddo_handshake)clsr7   r%   r;   r<   r)   purposebio_inbio_outr(   wrappers              r3   wrapzTLSStream.wrapN   s     : &,K 	E+6S''CK<S  4W==K s677 E##(D'DD##-// ))Gh * 
 

 #- 3"
 
 
 ,,Z-DEEEEEEEEEr2   func&Callable[[Unpack[PosArgsT]], T_Retval]argsUnpack[PosArgsT]r   c                  K   	 	  || }| j         j        r7| j                            | j                                                    d {V  |S # t
          j        $ r 	 | j         j        r7| j                            | j                                                    d {V  | j                                         d {V }| j        	                    |           np# t          $ r | j                                         Y nKt          $ r?}| j                                         | j                                          t          |d }~ww xY wY nt
          j        $ r: | j                            | j                                                    d {V  Y nt
          j        $ r?}| j                                         | j                                          t          |d }~wt
          j        $ rr}| j                                         | j                                          t#          |t
          j                  s	d|j        v r| j        rt          |t          d  d }~ww xY wc)NTUNEXPECTED_EOF_WHILE_READING)r:   pendingr7   sendreadrC   SSLWantReadErrorreceiver9   writer   	write_eofOSErrorr   SSLWantWriteErrorSSLSyscallErrorSSLError
isinstanceSSLEOFErrorstrerrorr)   )selfrT   rV   resultdataexcs         r3   rL   z TLSStream._call_sslobject_method   s     *	)tJ ?* M/44T_5I5I5K5KLLLLLLLLLO ' / / //. Q"3889M9M9O9OPPPPPPPPP!%!6!>!>!@!@@@@@@@D N((.... # / / /N,,..... 7 7 7N,,...O--///-367 ( I I I+001E1E1G1GHHHHHHHHHHH& 3 3 3((***))+++)s2<   ((***))+++sCO4445EE/ 41s:)t31*	sb   A I"A"CI"#E	?I"	E	
:EE		I"AI"I"$:GI"0A-II"tuple[AnyByteStream, bytes]c                   K   |                      | j        j                   d{V  | j                                         | j                                         | j        | j                                        fS )z
        Does the TLS closing handshake.

        :return: a tuple of (wrapped byte stream, bytes left in the read buffer)

        N)rL   r8   unwrapr9   r`   r:   r7   r\   rh   s    r3   rn   zTLSStream.unwrap   sx       ))$*:*ABBBBBBBBB  """!!###$dn&9&9&;&;;;r2   Nonec                   K   | j         rE	 |                                  d {V  n)# t          $ r t          | j                   d {V   w xY w| j                                         d {V  d S N)r)   rn   BaseExceptionr   r7   aclosero   s    r3   rt   zTLSStream.aclose   s      # 	kkmm########    '(=>>>>>>>>> #**,,,,,,,,,,,s	   & &A   	max_bytesintr   c                h   K   |                      | j        j        |           d {V }|st          |S rr   )rL   r8   r\   r   )rh   rv   rj   s      r3   r^   zTLSStream.receive   sF      001A1F	RRRRRRRR 	r2   itemc                V   K   |                      | j        j        |           d {V  d S rr   )rL   r8   r_   )rh   ry   s     r3   r[   zTLSStream.send   s:      ))$*:*@$GGGGGGGGGGGr2   c                P  K   |                      t          j                  }t          j        d|          }|r`t          |                    d                    t          |                    d          pd          }}||fdk     rt          d|           t          d          )NzTLSv(\d+)(?:\.(\d+))?   r
   r   )r|   r   z;send_eof() requires at least TLSv1.3; current session uses z7send_eof() has not yet been implemented for TLS streams)extrar   r+   rematchrw   groupNotImplementedError)rh   r+   r   majorminors        r3   send_eofzTLSStream.send_eof   s      jj!9::1;?? 	u{{1~~..EKKNN4Ga0H0H5Eu~&&)2$/2 2  
 "E
 
 	
r2   Mapping[Any, Callable[[], Any]]c                    i  j         j        t          j         j        j        t          j         j        j        t          j         j        j        t          j	         fdt          j
         fdt          j         fdt          j         fdt          j         fdt          j         fdt          j         j        j        i
S )Nc                 8     j                             d          S )NFr8   getpeercertro   s   r3   <lambda>z,TLSStream.extra_attributes.<locals>.<lambda>   s    43C3O3OPU3V3V r2   c                 8     j                             d          S )NTr   ro   s   r3   r   z,TLSStream.extra_attributes.<locals>.<lambda>   s    $:J:V:V; ; r2   c                      j         j        S rr   )r8   r%   ro   s   r3   r   z,TLSStream.extra_attributes.<locals>.<lambda>   s    d.>.J r2   c                 R     j         j        r j                                         nd S rr   )r8   r%   r&   ro   s   r3   r   z,TLSStream.extra_attributes.<locals>.<lambda>   s-    +21A1P1P1R1R1R r2   c                      j         S rr   r)   ro   s   r3   r   z,TLSStream.extra_attributes.<locals>.<lambda>   
    d6N r2   c                      j         S rr   )r8   ro   s   r3   r   z,TLSStream.extra_attributes.<locals>.<lambda>   s
    T-= r2   )r7   extra_attributesr   r   r8   selected_alpn_protocolr    get_channel_bindingr!   r"   r#   r%   r&   r)   r(   r+   versionro   s   `r3   r   zTLSStream.extra_attributes   s    
#4
&(8(O3 4!1!8)+V+V+V+V0 3 3 3 3 $&J&J&J&J' * * * * ,.N.N.N.N#%=%=%=%=$d&6&>#
 
 	
r2   )r7   r   r%   r=   r;   r   r<   r>   r)   r$   r?   r6   )rT   rU   rV   rW   r?   r   )r?   rl   r?   rp   )ru   )rv   rw   r?   r   )ry   r   r?   rp   r?   r   )r,   r-   r.   r/   r0   classmethodrS   rL   rn   rt   r^   r[   r   propertyr   r1   r2   r3   r6   r6   <   s7          $###
 $(#-1$(6 6 6 6 6 [6p- - - -^
< 
< 
< 
<- - - -    H H H H
 
 
 
 
 
 
 X
 
 
r2   r6   c                      e Zd ZU dZded<   ded<   dZded<   d	Zd
ed<   edd            Z	 dddZ	ddZ
ed d            ZdS )!TLSListenera  
    A convenience listener that wraps another listener and auto-negotiates a TLS session
    on every accepted connection.

    If the TLS handshake times out or raises an exception,
    :meth:`handle_handshake_error` is called to do whatever post-mortem processing is
    deemed necessary.

    Supports only the :attr:`~TLSAttribute.standard_compatible` extra attribute.

    :param Listener listener: the listener to wrap
    :param ssl_context: the SSL context object
    :param standard_compatible: a flag passed through to :meth:`TLSStream.wrap`
    :param handshake_timeout: time limit for the TLS handshake
        (passed to :func:`~anyio.fail_after`)
    zListener[Any]listenerzssl.SSLContextr<   Tr$   r)      floathandshake_timeoutrk   rs   streamr   r?   rp   c                ,  K   t          |           d{V  t          | t                                s.t          j        t
                                        d|            t          | t                    rt          | t                                r dS )a  
        Handle an exception raised during the TLS handshake.

        This method does 3 things:

        #. Forcefully closes the original stream
        #. Logs the exception (unless it was a cancellation exception) using the
           ``anyio.streams.tls`` logger
        #. Reraises the exception if it was a base exception or a cancellation exception

        :param exc: the exception
        :param stream: the original stream

        NzError during TLS handshake)exc_info)r   re   r   logging	getLoggerr,   	exception	Exception)rk   r   s     r3   handle_handshake_errorz"TLSListener.handle_handshake_error  s         ''''''''' #68899 	
 h''11,s 2   
 #y)) 	Z=T=V=V-W-W 		 	r2   NhandlerCallable[[TLSStream], Any]
task_groupTaskGroup | Nonec                    K   t                    d fd            } j                            ||           d {V  d S )Nr   r   r?   rp   c                N  K   ddl m} 	  |j                  5  t                              | j        j                   d {V }d d d            n# 1 swxY w Y    |           d {V  d S # t          $ r'}                    ||            d {V  Y d }~d S d }~ww xY w)Nr
   )
fail_after)r<   r)   )	 r   r   r6   rS   r<   r)   rs   r   )r   r   wrapped_streamrk   r   rh   s       r3   handler_wrapperz*TLSListener.serve.<locals>.handler_wrapper9  sP     %%%%%%
.Z 677  +4>>$($4,0,D ,: , , & & & & & &N               gn----------- ! ? ? ?11#v>>>>>>>>>>>>>>>?s:   A3 .A	A3 AA3 AA3 3
B$=BB$)r   r   r?   rp   )r   r   serve)rh   r   r   r   s   ``  r3   r   zTLSListener.serve4  so      
 
w	. 	. 	. 	. 	. 	. 
	. m!!/:>>>>>>>>>>>r2   c                H   K   | j                                          d {V  d S rr   )r   rt   ro   s    r3   rt   zTLSListener.acloseK  s2      m""$$$$$$$$$$$r2   r   c                &     t           j         fdiS )Nc                      j         S rr   r   ro   s   r3   r   z.TLSListener.extra_attributes.<locals>.<lambda>Q  r   r2   )r   r)   ro   s   `r3   r   zTLSListener.extra_attributesN  s!     ,.N.N.N.N
 	
r2   )rk   rs   r   r   r?   rp   rr   )r   r   r   r   r?   rp   r   r   )r,   r-   r.   r/   r0   r)   r   staticmethodr   r   rt   r   r   r1   r2   r3   r   r      s          "  $$$$$!!!!!   \D (,? ? ? ? ?.% % % % 
 
 
 X
 
 
r2   r   )*
__future__r   r   r~   rC   syscollections.abcr   r   dataclassesr   	functoolsr   typingr   r	   r   r   r   r   r   _core._typedattrr   r   abcr   r   r   r   version_infor   r   typing_extensionsr   r   tupler*   _PCTRTT_PCTRTTTr   r6   r   r1   r2   r3   <module>r      sc   " " " " " "  				 



 



 - - - - - - - - ! ! ! ! ! !                          B A A A A A A A @ @ @ @ @ @ @ @ @ @ @ @w+++++++++666666667:<
##
c3h$
%#) ) ) ) )$ ) ) )8 e|
 |
 |
 |
 |

 |
 |
 |
~ eU
 U
 U
 U
 U
(9% U
 U
 U
 U
 U
r2   