+
    P\i<  c                  s  a  0 t $ ^ RIHt Rt^ RIt^ RIt^ RIt^ RIt^ RIH	t	H
t
 ^ RIHt ^ R	IHt ^ R
IHt ^ RIHtHt ^RIHtHtHtHtHt ^RIHtHt ^RIHtHtHtH t H!t!H"t" ]PF                  R8  d   ^ RIH$t$ M^ RI%H$t$ ]PF                  R 8  d
   ^ RIH&t&H't' M^ RI%H&t&H't' ]PF                  R!8  d   ^ RIH(t( M^ RI%H(t( ]! R4      t)]&! R4      t*]+]+],],3,          R3,          t-R].R&   ]+]-R3,          t/R].R&    ! R R]4      t0]! RR7       ! R R]4      4       t1]! RR7       ! R R]!]1,          4      4       t2 ! R R] 4      t3R# )"i    )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)TypeVarTupleUnpack)overrideT_RetvalPosArgsT.r   _PCTRTT_PCTRTTTc                  s   ] tR t^:t$ Rt]! 4       tR]R&   ]! 4       tR]R&   ]! 4       t	R]R&   ]! 4       t
R]R	&   ]! 4       tR
]R&   ]! 4       tR]R&   ]! 4       tR]R&   ]! 4       tR]R&   ]! 4       tR]R&   ]! 4       tR]R&   RtR# )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_version N)__name__
__module____qualname____firstlineno____doc__r   r"   __annotations__r$   r%   r&   r'   r)   r*   r,   r-   r/   __static_attributes__r0       6/usr/lib/python3.14/site-packages/anyio/streams/tls.pyr   r   :   s    ? !0 1M:1(7(99#2#4F 4 FUEVBV,;,=\=')K) 9H8IN5I / 1J1 !0 11&(K(r8   F)Zeqc            	      s    ] tR t^Vt$ RtR]R&   R]R&   R]R&   R]R	&   R]R
&   ]RRRRRRRR/R R ll4       tR R ltR R lt	R R lt
R!R R lltR R ltR R lt]R R l4       tR tR# )"r   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_streamr(   r-   r+   _ssl_objectzssl.MemoryBIO	_read_bio
_write_bior)   Nhostnamessl_contextTc               s0    V ^8  d   QhRRRRRRRRR	R
RR/# )   r:   r   r)   zbool | Noner>   r!   r?   ssl.SSLContext | Noner-   r(   returnr   r0   Zformat   "r9   __annotate__TLSStream.__annotate__i   sN     D D'D !	D
 D +D "D 
Dr8   c               s  "   Vf   V'       * pV'       g   V'       d   \         P                  P                  M\         P                  P                  p\         P                  ! V4      p\        \         R4      '       d)   V;P                  \         P                  ( ,          un        \         P                  ! 4       p\         P                  ! 4       p\        V4      \         P                  J d   VP                  WxW#R7      p	M-\        P                  ! VP                  VVVVR4      G Rj  xL
 p	V ! VVV	VVR7      p
V
P                  V	P                  4      G Rj  xL
  V
#  L6 L5i)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)   Zserver_hostname)r:   r-   r;   r<   r=   )sslPurposeZCLIENT_AUTHSERVER_AUTHcreate_default_contextZhasattrZoptionsrG   Z	MemoryBIOtyper	   Zwrap_bior   Zrun_sync_call_sslobject_methodZdo_handshake)Zclsr:   r)   r>   r?   r-   ZpurposeZbio_inZbio_outr,   Zwrappers   &&$$$$     r9   wrapZTLSStream.wraph   s,    : &,K+6''CKK<S<S  44W=K s677##(D(D'DD#--/ .$--[ . J  )11$$  J - 3"
 ,,Z-D-DEEE#  	Fs.   E$E$DE$)E */E$E"E$"E$c               $    V ^8  d   QhRRRRRR/# )r@   funcz&Callable[[Unpack[PosArgsT]], T_Retval]argszUnpack[PosArgsT]rB   r   r0   rC   rD   r9   rE   rF      s$     , ,:,CS,	,r8   c                	s  "     V! V!  pV P                   P                  '       d<   V P                  P                  V P                   P	                  4       4      G Rj  xL
  V#  L  \
        P                   Ed     T P                   P                  '       d=   T P                  P                  T P                   P	                  4       4      G Rj  xL 
  T P                  P                  4       G Rj  xL 
 pT P                  P                  T4        EK    \         d!    T P                  P                  4          EK>  \         dA   pT P                  P                  4        T P                   P                  4        \        ThRp?ii ; i\
        P                   dB    T P                  P                  T P                   P	                  4       4      G Rj  xL 
   EK  \
        P                   dA   pT P                  P                  4        T P                   P                  4        \        ThRp?i\
        P                    d   pT P                  P                  4        T P                   P                  4        \#        T\
        P$                  4      '       g$   TP&                  '       d2   RTP&                  9   d!   T P(                  '       d   \        Th\        Rhh Rp?ii ; i5i)TNZUNEXPECTED_EOF_WHILE_READING)r=   Zpendingr:   sendreadrH   ZSSLWantReadErrorreceiver<   writer   	write_eofZOSErrorr   ZSSLWantWriteErrorZSSLSyscallErrorZSSLError
isinstanceZSSLEOFErrorZstrerrorr-   )selfrP   rQ   Zresultdataexcs   &&*   r9   rM   Z TLSStream._call_sslobject_method   s     (tH ??***//44T__5I5I5KLLL MI '' //..."33889M9M9OPPP!%!6!6!>!>!@@@D NN((.. # /NN,,.. 7NN,,.OO--/-367 (( I++001E1E1GHHH&& 3((*))+)s2<< ((*))+c3??33LLL%Cs||%S///1s:)t3s   K)A& AK)A$K)&K&=D6DC"D2C53D8K&K)%F<K&=K)F
F;FFK&!7K&GK&K)"K&5K&6;H11K&K&	A%K!/"K!K!!K&&K)c                   V ^8  d   QhRR/# )r@   rB   ztuple[AnyByteStream, bytes]r0   rC   rD   r9   rE   rF      s     
< 
<9 
<r8   c                s  "   V P                  V P                  P                  4      G Rj  xL
  V P                  P	                  4        V P
                  P	                  4        V P                  V P                  P                  4       3#  L^5i)zl
Does the TLS closing handshake.

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

N)rM   r;   unwrapr<   rV   r=   r:   rS   rX      &r9   r\   ZTLSStream.unwrap   sk      ))$*:*:*A*ABBB  "!!#$$dnn&9&9&;;; 	Cs   )BB
ABc               r[   r@   rB   Noner0   rC   rD   r9   rE   rF      s     - -d -r8   c                	s  "   V P                   '       d    V P                  4       G R j  xL
  V P                  P                  4       G R j  xL
  R #  L(  \         d!    \        T P                  4      G R j  xL 
  h i ; i L65iN)r-   r\   BaseExceptionr   r:   acloser]   r^   r9   rc   ZTLSStream.aclose   so     ###kkm##
 ##**,,, $  '(=(=>>> 	-sC   BA AA BBBA #A?7A:8A??Bc                    V ^8  d   QhRRRR/# )r@   	max_bytesintrB   r#   r0   rC   rD   r9   rE   rF      s      s u r8   c                	s   "   V P                  V P                  P                  V4      G R j  xL
 pV'       g   \        hV#  L5ira   )rM   r;   rS   r   )rX   re   rY   s   && r9   rT   ZTLSStream.receive   s:     001A1A1F1F	RR	 Ss   *AAA	Ac               rd   )r@   itemr#   rB   r`   r0   rC   rD   r9   rE   rF      s     H Hu H Hr8   c                	sn   "   V P                  V P                  P                  V4      G R j  xL
  R #  L5ira   )rM   r;   rU   )rX   rg      &&r9   rR   ZTLSStream.send   s'     ))$*:*:*@*@$GGGs   *535c               r[   r_   r0   rC   rD   r9   rE   rF      s     
 
 
r8   c                	sB  "   V P                  \        P                  4      p\        P                  ! R V4      pV'       dT   \        VP                  ^4      4      \        VP                  ^4      ;'       g    ^ 4      rCW43R8  d   \        RV 24      h\        R4      h5i)zTLSv(\d+)(?:\.(\d+))?z;send_eof() requires at least TLSv1.3; current session uses z7send_eof() has not yet been implemented for TLS streams)i      )Zextrar   r/   rematchrf   ZgroupZNotImplementedError)rX   r/   rk   ZmajorZminors   &    r9   send_eofZTLSStream.send_eof   s     jj!9!9:1;?u{{1~.EKKN4G4Ga0H5~&)$$/=2 
 "E
 	
s   A4B7(Bc               r[   r@   rB   zMapping[Any, Callable[[], Any]]r0   rC   rD   r9   rE   rF     s     
 
"A 
r8   c                	sH  a  / S P                   P                  C\        P                  S P                  P
                  \        P                  S P                  P                  \        P                  S P                  P                  \        P                  V 3R  l\        P                  V 3R l\        P                  V 3R l\        P                  V 3R l\        P                  V 3R l\        P                  V 3R l\        P                  S P                  P                   /
C# )c                 :   < S P                   P                  R 4      # )Fr;   Zgetpeercertr]      r9   <lambda>,TLSStream.extra_attributes.<locals>.<lambda>  s    43C3C3O3OPU3Vr8   c                 rn   )Tro   r]   rp   r9   rq   rr     s    $:J:J:V:V;r8   c                 s0   < S P                   P                  # ra   )r;   r)   r]   rp   r9   rq   rr     s    d.>.>.J.Jr8   c                 st   < S P                   P                  '       d   S P                   P                  4       # R # ra   )r;   r)   r*   r]   rp   r9   rq   rr     s6    +++ 261A1A1P1P1R 22r8   c                    < S P                   # ra   r-   r]   rp   r9   rq   rr         d6N6Nr8   c                 rs   ra   )r;   r]   rp   r9   rq   rr     s    T-=-=r8   )r:   extra_attributesr   r"   r;   Zselected_alpn_protocolr$   Zget_channel_bindingr%   r&   r'   r)   r*   r-   r,   r/   Zversionr]      fr9   rv   ZTLSStream.extra_attributes  s    
##44
&&(8(8(O(O33  44!1!1!8!8))+V00 3 $$&J'' * ,,.N##%=$$d&6&6&>&>#
 	
r8   r0   )i   )r1   r2   r3   r4   r5   r6   ZclassmethodrN   rM   r\   rc   rT   rR   rl   propertyrv   r7   r0   r8   r9   r   r   V   s     $#D $(	D
  $D .2D %)D DL,\
<-H
 
 
r8   c                  s    ] tR tRt$ RtR]R&   R]R&   RtR]R	&   ^tR
]R&   ]R R l4       t	RR R llt
R R lt]R R l4       tRtR# )r   i#  aj  
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-   Zfloathandshake_timeoutc               rO   )r@   rZ   rb   streamr   rB   r`   r0   rC   rD   r9   rE   TLSListener.__annotate__<  s"      -  SW r8   c                s$  "   \        V4      G Rj  xL
  \        V \        4       4      '       g,   \        P                  ! \
        4      P                  RV R7       \        V \        4      '       d   \        V \        4       4      '       d   h R#  L|5i)au  
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)Zexc_info)r   rW   r   loggingZ	getLoggerr1   Z	exceptionZ	Exception)rZ   r{   rh   r9   handle_handshake_errorZ"TLSListener.handle_handshake_error;  sz        ''' #6899
 h'11,s 2 
 #y))Z=T=V-W-W .X 	(s   BBA=BNc               rO   )r@   handlerzCallable[[TLSStream], Any]
task_groupzTaskGroup | NonerB   r`   r0   rC   rD   r9   rE   r|   [  s(     ? ?+? %? 
	?r8   c                	s   a a"   \        S4      R  VV 3R ll4       pS P                  P                  W24      G Rj  xL
  R#  L5i)c               rd   )r@   r{   r   rB   r`   r0   rC   rD   r9   rE   Z'TLSListener.serve.<locals>.__annotate__a  s     	. 	.- 	.D 	.r8   c                s  <"   ^RI Hp  V! SP                  4      ;_uu_ 4        \        P	                  V SP
                  SP                  R7      G Rj  xL
 pRRR4       S! X4      G Rj  xL
  R#  L  + '       g   i     L$; i L  \         d&   pSP                  Y04      G Rj  xL 
   Rp?R# Rp?ii ; i5i)r@   )
fail_after)r?   r-   N)	 r   rz   r   rN   r?   r-   rb   r~   )r{   r   Zwrapped_streamrZ   r   rX   s   &   r9   handler_wrapperZ*TLSListener.serve.<locals>.handler_wrapper`  s     %
. 6 677+4>>$($4$4,0,D,D ,: , &N 8 n---& 87 . ! ?11#>>>?su   B>B 0A6A4A6B "B>-B	.B>4A66B	B 	B>B;B6*B-+B60B>6B;;B>N)r   ry   serve)rX   r   r   r   s   ff& r9   r   ZTLSListener.serve[  s=     
 
w	. 	. 
	. mm!!/>>>s   7AAAc               r[   r_   r0   rC   rD   r9   rE   r|   r  s     % %d %r8   c                	sV   "   V P                   P                  4       G R j  xL
  R #  L5ira   )ry   rc   r]   r^   r9   rc   ZTLSListener.acloser  s     mm""$$$s   )')c               r[   rm   r0   rC   rD   r9   rE   r|   v  s     
 
"A 
r8   c                	s0   a  \         P                  V 3R  l/# )c                 rs   ra   rt   r]   rp   r9   rq   Z.TLSListener.extra_attributes.<locals>.<lambda>x  ru   r8   )r   r-   r]   rw   r9   rv   ZTLSListener.extra_attributesu  s     ,,.N
 	
r8   r0   ra   )r1   r2   r3   r4   r5   r6   r-   rz   Zstaticmethodr~   r   rc   rx   rv   r7   r0   r8   r9   r   r   #  s[    "  $$!u! >?.% 
 
r8   c                  sL    ] tR tRtRtRRRRRR/R R	 llt]R
 R l4       tRtR# )r   i|  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
r>   Nr?   r-   Tc          
     s,    V ^8  d   QhRRRRRRRRR	R
/# )r@   connectabler   r>   r!   r?   rA   r-   r(   rB   r`   r0   rC   rD   r9   rE   TLSConnectable.__annotate__  s<     7 7-7 	7
 +7 "7 
7r8   c               	sN   Wn         T;'       g/    \        P                  ! \        P                  P                  4      V n        \        V P
                  \        P                  4      '       g,   \        R \        V P
                  4      P                   24      hW n        W@n        R# )z7ssl_context must be an instance of ssl.SSLContext, not N)r   rH   rK   rI   rJ   r?   rW   r	   Z	TypeErrorrL   r1   r>   r-   )rX   r   r>   r?   r-   s   &&$$$r9   __init__ZTLSConnectable.__init__  s     ''2 (
 (
c6P6PKK##7
 $**CNN;;I(()2235  !#6 r8   c               r[   )r@   rB   r   r0   rC   rD   r9   rE   r     s      y r8   c                	s  "   V P                   P                  4       G R j  xL
 p \        P                  VV P                  V P
                  V P                  R7      G R j  xL
 #  LD L  \         d    \        T4      G R j  xL 
  h i ; i5i)N)r>   r?   r-   )	r   connectr   rN   r>   r?   r-   rb   r   )rX   r{   s   & r9   r   ZTLSConnectable.connect  s     ''//11		" ,,$($<$<	 (    2  	#F+++	sD   BA%B:A)  A'!A) $B'A) )B
BB

B)r   r>   r?   r-   )	r1   r2   r3   r4   r5   r   r   r   r7   r0   r8   r9   r   r   |  s>    	7  $	7
 .27 %)7(  r8   )r   r   r   r   )ri   i
   )ri   i   )ri   i   )4__conditional_annotations__Z
__future__r    Z__all__r}   rj   rH   ZsysZcollections.abcr   r   Zdataclassesr   Z	functoolsr   r	   Ztypingr
   r   r   r   r   r   r   r   Z_core._typedattrr   r   Zabcr   r   r   r   r   r   Zversion_infor   Ztyping_extensionsr   r   r   r   r   Ztupler.   r   r6   r    r   r   r   r   )r   s   @r9   <module>r      s5   " "  	 
 
 - !     B  w +w++6w*:
#5c?C/0 0GSL)) ))$ )8 eI

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