
    -2i<                       U d dl mZ d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 d dlmZmZ d	d
lmZ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m Z m!Z! ej"        dk    rd dlm#Z# nd dl$m#Z# ej"        dk    r	d dlm%Z%m&Z& nd dl$m%Z%m&Z& ej"        dk    rd dlm'Z' nd dl$m'Z'  ed          Z( e%d          Z)e*e*e+e+f         df         Z,de-d<   e*e,df         Z.de-d<    G d de          Z/ ed           G d de                      Z0 ed           G d d e e0                               Z1 G d! d"e          Z2dS )#    )annotations)TLSAttributeTLSConnectableTLSListener	TLSStreamN)CallableMapping)	dataclass)wraps)
SSLContext)AnyTypeVar   )BrokenResourceErrorEndOfStreamaclose_forcefullyget_cancelled_exc_class	to_thread)TypedAttributeSettyped_attribute)AnyByteStreamAnyByteStreamConnectable
ByteStreamByteStreamConnectableListener	TaskGroup)   
   )	TypeAlias)r      )TypeVarTupleUnpack)r      )overrideT_RetvalPosArgsT.r   _PCTRTT_PCTRTTTc                  @   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 )r   z5Contains 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/   r0   r2   r3   r5   r6   r8        P/var/www/html/pixcura-vrs/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((((((r?   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 )2r   a  
    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_streamr1   r6   r4   _ssl_objectzssl.MemoryBIO	_read_bio
_write_bioNT)r2   hostnamessl_contextr6   r2   bool | NonerG   r*   rH   ssl.SSLContext | Nonereturnc               F  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                    }t          |          t           j
        u r|                    ||||          }	n$t          j        |j        ||||d           d{V }	 | |||	||          }
|
                    |	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)r2   server_hostname)rC   r6   rD   rE   rF   )sslPurposeCLIENT_AUTHSERVER_AUTHcreate_default_contexthasattroptionsrM   	MemoryBIOtyper   wrap_bior   run_sync_call_sslobject_methoddo_handshake)clsrC   r2   rG   rH   r6   purposebio_inbio_outr5   wrappers              r@   wrapzTLSStream.wraph   sl     : &,K 	E+6S''CK<S  4W==K s677 E##(D'DD##-// ..$--[( .  JJ  )1$         J #- 3"
 
 
 ,,Z-DEEEEEEEEEr?   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        $ ry}| j                                         | j                                          t#          |t
          j                  s|j        r d|j        v r| j        rt          |t          d  d }~ww xY wj)NTUNEXPECTED_EOF_WHILE_READING)rF   pendingrC   sendreadrO   SSLWantReadErrorreceiverE   writer   	write_eofOSErrorr   SSLWantWriteErrorSSLSyscallErrorSSLError
isinstanceSSLEOFErrorstrerrorr6   )selfrb   rd   resultdataexcs         r@   rZ   z TLSStream._call_sslobject_method   s     )	(tH ?* M/44T_5I5I5K5KLLLLLLLLLM ' / / //. 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<   ((***))+++c3?33 4L4%Cs|%S%S/ 41s:)t31)	sb   A I)A"CI)#E	?I)	E	
:EE		I)AI)I)$:GI)0A4I$$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)rZ   rD   unwraprE   rn   rF   rC   rj   rv   s    r@   r|   zTLSStream.unwrap   sx       ))$*:*ABBBBBBBBB  """!!###$dn&9&9&;&;;;r?   Nonec                   K   | j         rE	 |                                  d {V  n)# t          $ r t          | j                   d {V   w xY w| j                                         d {V  d S N)r6   r|   BaseExceptionr   rC   acloser}   s    r@   r   zTLSStream.aclose   s      # 	kkmm########    '(=>>>>>>>>> #**,,,,,,,,,,,s	   & &A   	max_bytesintr,   c                h   K   |                      | j        j        |           d {V }|st          |S r   )rZ   rD   rj   r   )rv   r   rx   s      r@   rl   zTLSStream.receive   sF      001A1F	RRRRRRRR 	r?   itemc                V   K   |                      | j        j        |           d {V  d S r   )rZ   rD   rm   )rv   r   s     r@   ri   zTLSStream.send   s:      ))$*:*@$GGGGGGGGGGGr?   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   r8   rematchr   groupNotImplementedError)rv   r8   r   majorminors        r@   send_eofzTLSStream.send_eof   s      jj!9::1;?? 	u{{1~~..EKKNN4Ga0H0H5Eu~&&)2$/2 2  
 "E
 
 	
r?   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rD   getpeercertr}   s   r@   <lambda>z,TLSStream.extra_attributes.<locals>.<lambda>  s    43C3O3OPU3V3V r?   c                 8     j                             d          S )NTr   r}   s   r@   r   z,TLSStream.extra_attributes.<locals>.<lambda>  s    $:J:V:V; ; r?   c                      j         j        S r   )rD   r2   r}   s   r@   r   z,TLSStream.extra_attributes.<locals>.<lambda>  s    d.>.J r?   c                 R     j         j        r j                                         nd S r   )rD   r2   r3   r}   s   r@   r   z,TLSStream.extra_attributes.<locals>.<lambda>  s-    +21A1P1P1R1R1R r?   c                      j         S r   r6   r}   s   r@   r   z,TLSStream.extra_attributes.<locals>.<lambda>  
    d6N r?   c                      j         S r   )rD   r}   s   r@   r   z,TLSStream.extra_attributes.<locals>.<lambda>  s
    T-= r?   )rC   extra_attributesr   r+   rD   selected_alpn_protocolr-   get_channel_bindingr.   r/   r0   r2   r3   r6   r5   r8   versionr}   s   `r@   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&>#
 
 	
r?   )rC   r   r2   rI   rG   r*   rH   rJ   r6   r1   rK   r   )rb   rc   rd   re   rK   r%   )rK   rz   rK   r~   )r   )r   r   rK   r,   )r   r,   rK   r~   rK   r   )r9   r:   r;   r<   r=   classmethodra   rZ   r|   r   rl   ri   r   propertyr   r>   r?   r@   r   r   V   s=          $###
 $(#-1$(D D D D D [DL, , , ,\
< 
< 
< 
<- - - -    H H H H
 
 
 
 
 
 
 X
 
 
r?   r   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 )!r   a  
    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.SSLContextrH   Tr1   r6      floathandshake_timeoutry   r   streamr   rK   r~   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   rs   r   logging	getLoggerr9   	exception	Exception)ry   r   s     r@   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 		 	r?   NhandlerCallable[[TLSStream], Any]
task_groupTaskGroup | Nonec                    K   t                    d fd            } j                            ||           d {V  d S )Nr   r   rK   r~   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)rH   r6   )	 r   r   r   ra   rH   r6   r   r   )r   r   wrapped_streamry   r   rv   s       r@   handler_wrapperz*TLSListener.serve.<locals>.handler_wrapper`  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   rK   r~   )r   r   serve)rv   r   r   r   s   ``  r@   r   zTLSListener.serve[  so      
 
w	. 	. 	. 	. 	. 	. 
	. m!!/:>>>>>>>>>>>r?   c                H   K   | j                                          d {V  d S r   )r   r   r}   s    r@   r   zTLSListener.acloser  s2      m""$$$$$$$$$$$r?   r   c                &     t           j         fdiS )Nc                      j         S r   r   r}   s   r@   r   z.TLSListener.extra_attributes.<locals>.<lambda>x  r   r?   )r   r6   r}   s   `r@   r   zTLSListener.extra_attributesu  s!     ,.N.N.N.N
 	
r?   )ry   r   r   r   rK   r~   r   )r   r   r   r   rK   r~   r   r   )r9   r:   r;   r<   r=   r6   r   staticmethodr   r   r   r   r   r>   r?   r@   r   r   #  s          "  $$$$$!!!!!   \D (,? ? ? ? ?.% % % % 
 
 
 X
 
 
r?   r   c                  <    e Zd ZdZddddddZedd            ZdS )r   a  
    Wraps another connectable and does TLS negotiation after a successful connection.

    :param connectable: the connectable to wrap
    :param hostname: host name of the server (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 server does the same
    NTrG   rH   r6   connectabler   rG   r*   rH   rJ   r6   r1   rK   r~   c                  || _         |p"t          j        t          j        j                  | _        t          | j        t          j                  s)t          dt          | j                  j
                   || _        || _        d S )Nz7ssl_context must be an instance of ssl.SSLContext, not )r   rO   rS   rP   rR   rH   rs   r   	TypeErrorrW   r9   rG   r6   )rv   r   rG   rH   r6   s        r@   __init__zTLSConnectable.__init__  s     ''2 (
c6PK#7
 7
 $*CN;; 	5())25 5   !#6   r?   r   c                   K   | j                                          d {V }	 t                              || j        | j        | j                   d {V S # t          $ r t          |           d {V   w xY w)Nr   )	r   connectr   ra   rG   rH   r6   r   r   )rv   r   s     r@   r   zTLSConnectable.connect  s      '//11111111		" ,$($<	 (           	 	 	#F+++++++++	s   2A !A7)
r   r   rG   r*   rH   rJ   r6   r1   rK   r~   )rK   r   )r9   r:   r;   r<   r   r$   r   r>   r?   r@   r   r   |  sg        	 	  $-1$(7 7 7 7 7 7(    X  r?   r   )3
__future__r   __all__r   r   rO   syscollections.abcr   r	   dataclassesr
   	functoolsr   r   typingr   r   r   r   r   r   r   r   _core._typedattrr   r   abcr   r   r   r   r   r   version_infor   typing_extensionsr!   r"   r$   r%   r&   tupler7   r'   r=   r(   r   r   r   r   r>   r?   r@   <module>r      se   " " " " " " "  				 



 



 - - - - - - - - ! ! ! ! ! !                                  B A A A A A A A                w       ++++++w+++++++++66666666w******7:<
##5c?C/0 0 0 0 0GSL) ) ) ) )) ) ) ) )$ ) ) )8 eI
 I
 I
 I
 I

 I
 I
 I
X eU
 U
 U
 U
 U
(9% U
 U
 U
p, , , , ,* , , , , ,r?   