
    vKg!                       % S SK Jr  S SKrS SKrS SKrS SKJr	  S SK
JrJrJrJrJrJr  S SKrSSKJr  SSKJr  SSKJrJr  SS	KJrJr  \(       a  S S
KJrJr  \" S5      r Sr!S\"S'   SS jr# " S S\$5      r% " S S5      r&\	" S/ SQ5      r'\" S\S9r(\ " S S\\\(   5      5       r)\)RT                  RW                  SS5      \)l*        \ " S S\\)\(      5      5       r,g)    )annotationsN)Enum)TYPE_CHECKINGAnyClassVarFinalGenericTypeVar   )_sync)aclose_forcefully)ConflictDetectorfinal)ListenerStream)	AwaitableCallableTi @  TFinalSTARTING_RECEIVE_SIZEc                d    [        U [        R                  5      =(       d    S[        U SS5      ;   $ )NUNEXPECTED_EOF_WHILE_READINGstrerror )
isinstance_stdlib_sslSSLEOFErrorgetattr)excs    I/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/trio/_ssl.py_is_eofr!      s/    
 c;223 &'#z2*FF    c                      \ rS rSrSrSrg)NeedHandshakeError   zSome :class:`SSLStream` methods can't return any meaningful data until
after the handshake. If you call them before the handshake, they raise
this error.

r   N)__name__
__module____qualname____firstlineno____doc____static_attributes__r   r"   r    r$   r$      s    r"   r$   c                  <    \ rS rSrSS jrSS jr\S	S j5       rSrg)
_Once   c                ^    Xl         X l        SU l        [        R                  " 5       U l        g )NF)_afn_argsstartedr   Event_done)selfafnargss      r    __init___Once.__init__   s     	
[[]
r"   c               N  #    U R                   (       dC  SU l         U R                  " U R                  6 I S h  vN   U R                  R	                  5         g U(       d   U R                  R                  5       (       a  g U R                  R                  5       I S h  vN   g  Ni N7f)NT)r2   r0   r1   r4   setis_setwait)r5   
checkpoints     r    ensure_Once.ensure   sm     ||DL))TZZ(((JJNN

 1 1 3 3**//### )
 $s"   5B%B!A#B%B#B%#B%c                H    [        U R                  R                  5       5      $ N)boolr4   r<   r5   s    r    done
_Once.done   s    DJJ%%'((r"   )r0   r1   r4   r2   N)r6   z Callable[..., Awaitable[object]]r7   objectreturnNone)r>   rC   rH   rI   )rH   rC   )	r&   r'   r(   r)   r8   r?   propertyrE   r+   r   r"   r    r-   r-      s     #$ ) )r"   r-   _State)OKBROKENCLOSEDT_Stream)boundc                    ^  \ rS rSr% SrSSSS.           SS jjr1 SkrS\S	'   1 S
krS\S'   SS jr	SU 4S jjr
SU 4S jjrSS jrSSS.         SS jjrSS jrSS jrS S!S jjrS"S jrS#S jrSS jrSS jrSrU =r$ )$	SSLStream   a  Encrypted communication using SSL/TLS.

:class:`SSLStream` wraps an arbitrary :class:`~trio.abc.Stream`, and
allows you to perform encrypted communication over it using the usual
:class:`~trio.abc.Stream` interface. You pass regular data to
:meth:`send_all`, then it encrypts it and sends the encrypted data on the
underlying :class:`~trio.abc.Stream`; :meth:`receive_some` takes encrypted
data out of the underlying :class:`~trio.abc.Stream` and decrypts it
before returning it.

You should read the standard library's :mod:`ssl` documentation carefully
before attempting to use this class, and probably other general
documentation on SSL/TLS as well. SSL/TLS is subtle and quick to
anger. Really. I'm not kidding.

Args:
  transport_stream (~trio.abc.Stream): The stream used to transport
      encrypted data. Required.

  ssl_context (~ssl.SSLContext): The :class:`~ssl.SSLContext` used for
      this connection. Required. Usually created by calling
      :func:`ssl.create_default_context`.

  server_hostname (str, bytes, or None): The name of the server being
      connected to. Used for `SNI
      <https://en.wikipedia.org/wiki/Server_Name_Indication>`__ and for
      validating the server's certificate (if hostname checking is
      enabled). This is effectively mandatory for clients, and actually
      mandatory if ``ssl_context.check_hostname`` is ``True``.

  server_side (bool): Whether this stream is acting as a client or
      server. Defaults to False, i.e. client mode.

  https_compatible (bool): There are two versions of SSL/TLS commonly
      encountered in the wild: the standard version, and the version used
      for HTTPS (HTTP-over-SSL/TLS).

      Standard-compliant SSL/TLS implementations always send a
      cryptographically signed ``close_notify`` message before closing the
      connection. This is important because if the underlying transport
      were simply closed, then there wouldn't be any way for the other
      side to know whether the connection was intentionally closed by the
      peer that they negotiated a cryptographic connection to, or by some
      `man-in-the-middle
      <https://en.wikipedia.org/wiki/Man-in-the-middle_attack>`__ attacker
      who can't manipulate the cryptographic stream, but can manipulate
      the transport layer (a so-called "truncation attack").

      However, this part of the standard is widely ignored by real-world
      HTTPS implementations, which means that if you want to interoperate
      with them, then you NEED to ignore it too.

      Fortunately this isn't as bad as it sounds, because the HTTP
      protocol already includes its own equivalent of ``close_notify``, so
      doing this again at the SSL/TLS level is redundant. But not all
      protocols do! Therefore, by default Trio implements the safer
      standard-compliant version (``https_compatible=False``). But if
      you're speaking HTTPS or some other protocol where
      ``close_notify``\s are commonly skipped, then you should set
      ``https_compatible=True``; with this setting, Trio will neither
      expect nor send ``close_notify`` messages.

      If you have code that was written to use :class:`ssl.SSLSocket` and
      now you're porting it to Trio, then it may be useful to know that a
      difference between :class:`SSLStream` and :class:`ssl.SSLSocket` is
      that :class:`~ssl.SSLSocket` implements the
      ``https_compatible=True`` behavior by default.

Attributes:
  transport_stream (trio.abc.Stream): The underlying transport stream
      that was passed to ``__init__``. An example of when this would be
      useful is if you're using :class:`SSLStream` over a
      :class:`~trio.SocketStream` and want to call the
      :class:`~trio.SocketStream`'s :meth:`~trio.SocketStream.setsockopt`
      method.

Internally, this class is implemented using an instance of
:class:`ssl.SSLObject`, and all of :class:`~ssl.SSLObject`'s methods and
attributes are re-exported as methods and attributes on this class.
However, there is one difference: :class:`~ssl.SSLObject` has several
methods that return information about the encrypted connection, like
:meth:`~ssl.SSLSocket.cipher` or
:meth:`~ssl.SSLSocket.selected_alpn_protocol`. If you call them before the
handshake, when they can't possibly return useful data, then
:class:`ssl.SSLObject` returns None, but :class:`trio.SSLStream`
raises :exc:`NeedHandshakeError`.

This also means that if you register a SNI callback using
`~ssl.SSLContext.sni_callback`, then the first argument your callback
receives will be a :class:`ssl.SSLObject`.

NF)server_hostnameserver_sidehttps_compatiblec                  Xl         [        R                  U l        XPl        [
        R                  " 5       U l        S U l        [
        R                  " 5       U l	        UR                  U R                  U R                  UUS9U l        [        U R                  5      U l        [        R                   " 5       U l        SU l        [        R&                  " 5       U l        [+        S5      U l        [+        S5      U l        [0        U l        g )N)rU   rT   r   z8another task is currently sending data on this SSLStreamz:another task is currently receiving data on this SSLStream)transport_streamrK   rL   _state_https_compatibler   	MemoryBIO	_outgoing_delayed_outgoing	_incomingwrap_bio_ssl_objectr-   _do_handshake
_handshookr   StrictFIFOLock_inner_send_lock_inner_recv_countLock_inner_recv_lockr   _outer_send_conflict_detector_outer_recv_conflict_detectorr   _estimated_receive_size)r5   rX   ssl_contextrT   rU   rV   s         r    r8   SSLStream.__init__Z  s     +;ii!1$..0/3$..0&//NNNN#+	 0 
   2 23 !& 4 4 6!" %


 .>F.
* .>H.
* (=$r"   >   ciphercontextpendingsessionversioncompressiongetpeercertrU   session_reusedshared_ciphersrT   get_channel_bindingselected_npn_protocolselected_alpn_protocolr   
_forwarded>	   rm   rq   rr   rs   rt   ru   rv   rw   rx   _after_handshakec                    XR                   ;   aO  XR                  ;   a*  U R                  R                  (       d  [	        SU< 35      e[        U R                  U5      $ [        U5      e)Nz#call do_handshake() before calling )ry   rz   rb   rE   r$   r   r`   AttributeError)r5   names     r    __getattr__SSLStream.__getattr__  sU    ??",,,T__5I5I(+Nth)WXX4++T22 &&r"   c                p   > XR                   ;   a  [        U R                  X5        g [        TU ]  X5        g rB   )ry   setattrr`   super__setattr__)r5   r}   value	__class__s      r    r   SSLStream.__setattr__  s*    ??"D$$d2G,r"   c                ^   > [        [        TU ]	  5       5      [        U R                  5      -   $ rB   )listr   __dir__ry   )r5   r   s    r    r   SSLStream.__dir__  s#    EGO%&doo)>>>r"   c                   U R                   [        R                  L a  g U R                   [        R                  L a  [        R
                  eU R                   [        R                  L a  [        R                  e[        5       erB   )	rY   rK   rL   rM   trioBrokenResourceErrorrN   ClosedResourceErrorAssertionErrorrD   s    r    _check_statusSSLStream._check_status  sV    ;;&))#[[FMM)***[[FMM)*** ""r"   )ignore_want_readis_handshakec               L  #    [         R                  R                  5       I S h  vN   SnSnU(       Gd  SnS n U" U6 nSnU(       a  SnSnU R                  R                  5       n
U(       aW  U(       dP  U R                  R                  (       a5  U R                  R                  5       S:X  a  U R                   b   eXl        Sn
U
(       ao  U R"                   IS h  vN   Sn U R                   b  U R                   U
-   n
S U l        U R$                  R'                  U
5      I S h  vN   S S S 5      IS h  vN   OU(       a  U R(                  nU R*                   IS h  vN   SnXR(                  :X  a  U R$                  R-                  5       I S h  vN nU(       d  U R.                  R1                  5         O?[3        U R4                  [7        U5      5      U l        U R.                  R9                  U5        U =R(                  S-  sl        S S S 5      IS h  vN   U(       d  GM  U(       d&  [         R                  R;                  5       I S h  vN   W$  GN0! [        R                   a    Sn GN/[        R
                  [        R                  4 a+  n	[        R                  U l	        [         R                  U	eS n	A	ff = f GN GN!   [        R                  U l	        e = f GN! , IS h  vN  (       d  f       N= f GN GNr N! , IS h  vN  (       d  f       GN= f N7f)NFTzTLSv1.3r"   r   )r   lowlevelcheckpoint_if_cancelledr   SSLWantReadErrorSSLErrorCertificateErrorrK   rM   rY   r   r\   readr`   rU   rq   r]   rd   rX   send_allre   rg   receive_somer^   	write_eofmaxrj   lenwritecancel_shielded_checkpoint)r5   fnr   r   r7   yieldedfinished	want_readretr   to_send
recv_countdatas                r    _retrySSLStream._retry  s     mm335552 IC $i  !	nn))+G* !$$00$$,,.);--555)0&v 000"G	11=&*&<&<w&FG59D2"33<<WEEE 100  "33
000"G!%;%;;%)%:%:%G%G%II# NN446;> $ < < #D	<D8 !NN006..!3. 10q (J --::<<<
U 	6@ // ! 	((+*F*FG 8$mm..C78B 1 F '-mm 10000 1  J 1000 =s  "L$IL$I BL$KL$K%#AK$K%K)L$4K"5(L$K?L$!/LLA:LL$LL$%(L$L"L$J>-L$0#J>&J99J>>L$KKK%"L$%K<+K.,K<8L$LL$LLL	L$c                   #     U R                  U R                  R                  SS9I S h  vN   g  N!   [        R                  U l        e = f7f)NT)r   )r   r`   do_handshakerK   rM   rY   rD   s    r    ra   SSLStream._do_handshakes  s@     	++d..;;$+OOO	 --DKs%   A'3 13 A3 AAc                r   #    U R                  5         U R                  R                  SS9I Sh  vN   g N7f)u  Ensure that the initial handshake has completed.

The SSL protocol requires an initial handshake to exchange
certificates, select cryptographic keys, and so forth, before any
actual data can be sent or received. You don't have to call this
method; if you don't, then :class:`SSLStream` will automatically
perform the handshake as needed, the first time you try to send or
receive data. But if you want to trigger it manually – for example,
because you want to look at the peer's certificate before you start
talking to them – then you can call this method.

If the initial handshake is already in progress in another task, this
waits for it to complete and then returns.

If the initial handshake has already completed, this returns
immediately without doing anything (except executing a checkpoint).

.. warning:: If this method is cancelled, then it may leave the
   :class:`SSLStream` in an unusable state. If this happens then any
   future attempt to use the object will raise
   :exc:`trio.BrokenResourceError`.

Tr>   N)r   rb   r?   rD   s    r    r   SSLStream.do_handshakez  s.     0 	oo$$$555s   -757c                  #    U R                      U R                  5          U R                  R                  SS9I Sh  vN   Uc+  [        U R                  U R                   R"                  5      nO'[$        R&                  " U5      nUS:  a  [)        S5      e U R+                  U R,                  R.                  U5      I Sh  vN nUc   eUsSSS5        $  N! [        R
                   a  nU R                  (       aw  [        UR                  [        R                  5      (       d  [        UR                  5      (       a4  [        R                  R                  5       I Sh  vN     SnASSS5        ge SnAff = f N! [        R
                   ae  nU R                  (       aN  [        UR                  5      (       a4  [        R                  R                  5       I Sh  vN     SnASSS5        ge SnAff = f! , (       d  f       g= f7f)a  Read some data from the underlying transport, decrypt it, and
return it.

See :meth:`trio.abc.ReceiveStream.receive_some` for details.

.. warning:: If this method is cancelled while the initial handshake
   or a renegotiation are in progress, then it may leave the
   :class:`SSLStream` in an unusable state. If this happens then any
   future attempt to use the object will raise
   :exc:`trio.BrokenResourceError`.

Fr   Nr"   r   zmax_bytes must be >= 1)ri   r   rb   r?   r   r   rZ   r   	__cause__r   SSLSyscallErrorr!   r   r>   r   rj   r^   ro   	_operatorindex
ValueErrorr   r`   r   )r5   	max_bytesr   receiveds       r    r   SSLStream.receive_some  s     // oo,,,>>>     < <dnn>T>TU	%OOI6	q=$%=>>!%T-=-=-B-BI!NN+++9 0/ ?++  ))s}}k.I.IJJs}}----22444 0/ , O ++  ))gcmm.D.D--22444M 0/P ; 0/s   HG;CCCAG;)E?E=
E?
HCE:,A5E5!E$"E5'G;+	H4E55E::G;=E??G8AG3G" G3%G;)	H2G33G88G;;
H	Hc                  #    U R                      U R                  5         U R                  R                  SS9I Sh  vN   U(       d0  [        R
                  R                  5       I Sh  vN    SSS5        gU R                  U R                  R                  U5      I Sh  vN   SSS5        g Nr NG N! , (       d  f       g= f7f)aJ  Encrypt some data and then send it on the underlying transport.

See :meth:`trio.abc.SendStream.send_all` for details.

.. warning:: If this method is cancelled, then it may leave the
   :class:`SSLStream` in an unusable state. If this happens then any
   attempt to use the object will raise
   :exc:`trio.BrokenResourceError`.

Fr   N)
rh   r   rb   r?   r   r   r>   r   r`   r   )r5   r   s     r    r   SSLStream.send_all  s      // //((E(::: mm..000 0/ ++d..44d;;; 0/: 1; 0/s\   C-B5B/,B5)B1*B5/	C8)B5!B3"B5&	C/B51B53B55
C?Cc                  #    U R                      U R                     U R                  5         U R                  R	                  SS9I Sh  vN   U R                  U R                  R                  5      I Sh  vN   U R                  n[        R                  U l        SU l        XR                  R                  5       4sSSS5        sSSS5        $  N N[! , (       d  f       O= fSSS5        g! , (       d  f       g= f7f)a  Cleanly close down the SSL/TLS encryption layer, allowing the
underlying stream to be used for unencrypted communication.

You almost certainly don't need this.

Returns:
  A pair ``(transport_stream, trailing_bytes)``, where
  ``transport_stream`` is the underlying transport stream, and
  ``trailing_bytes`` is a byte string. Since :class:`SSLStream`
  doesn't necessarily know where the end of the encrypted data will
  be, it can happen that it accidentally reads too much from the
  underlying stream. ``trailing_bytes`` contains this extra data; you
  should process it as if it was returned from a call to
  ``transport_stream.receive_some(...)``.

Fr   N)ri   rh   r   rb   r?   r   r`   unwraprX   rK   rN   rY   r^   r   r5   rX   s     r    r   SSLStream.unwrap  s     " //1S1S //((E(:::++d..55666#44 --DK$(D!$nn&9&9&;< 2T1S//:6 2T1S///s^   C?C.-C	C
,C6C7AC=	C.
C?CC
C"	C.%	C?.
C<8C?c                  #    U R                   [        R                  L a'  [        R                  R                  5       I Sh  vN   gU R                   [        R                  L d  U R                  (       a8  [        R                  U l         U R                  R                  5       I Sh  vN   g U R                  R                  SS9I Sh  vN   [        R                  " [        R                  [        R                  5         U R!                  U R"                  R$                  SS9I Sh  vN   SSS5        U R                  R                  5       I Sh  vN    [        R                  U l         g GN/ N N NL! , (       d  f       NP= f N5!   ['        U R                  5      I Sh  vN    e = f! [        R                  U l         f = f7f)a  Gracefully shut down this connection, and close the underlying
transport.

If ``https_compatible`` is False (the default), then this attempts to
first send a ``close_notify`` and then close the underlying stream by
calling its :meth:`~trio.abc.AsyncResource.aclose` method.

If ``https_compatible`` is set to True, then this simply closes the
underlying stream and marks this stream as closed.

NFr   T)r   )rY   rK   rN   r   r   r>   rM   rZ   rX   acloserb   r?   
contextlibsuppressr   BusyResourceErrorr   r`   r   r   rD   s    r    r   SSLStream.aclose  sN     ;;&--'--**,,,;;&--'4+A+A --DK''..000@	( //((E(:::` $$T%=%=t?U?UVkk$"2"2"9"9DkQQQ W ''..000 --DKM - 1 ;b R WV 1	#D$9$9:::
 !--DKs   ?G
E0A%G
'E3(G
.F 
E57F (E9*E7+E9/F 7F0 F
F0 G
3G
5F 7E99
FF 
F0 F-&F)'F--F0 0GG
c                F  #    U R                      U R                  5         U R                   ISh  vN   U R                  R	                  5       I Sh  vN   SSS5      ISh  vN   SSS5        g N? N N! , ISh  vN  (       d  f       N&= f! , (       d  f       g= f7f)z>See :meth:`trio.abc.SendStream.wait_send_all_might_not_block`.N)rh   r   rd   rX   wait_send_all_might_not_blockrD   s    r    r   'SSLStream.wait_send_all_might_not_blockX  sv      //  ,,, ++IIKKK -,! 0/  - L -,,,! 0/ss   B!!BA0BA6A2A6B"A4#B'	B!0B2A64B6B	<A?=B		B
BB!)r]   rj   rb   rZ   r^   re   rg   rd   ri   rh   r\   r`   rY   rX   )rX   rO   rk   _stdlib_ssl.SSLContextrT   zstr | bytes | NonerU   rC   rV   rC   rH   rI   )r}   strrH   r   )r}   r   r   rG   rH   rI   )rH   z	list[str]rH   rI   )
r   zCallable[..., T]r7   rG   r   rC   r   rC   rH   zT | NonerB   )r   z
int | NonerH   zbytes | bytearray)r   zbytes | bytearray | memoryviewrH   rI   )rH   z tuple[Stream, bytes | bytearray])r&   r'   r(   r)   r*   r8   ry   __annotations__rz   r~   r   r   r   r   ra   r   r   r   r   r   r   r+   __classcell__)r   s   @r    rR   rR      s    [H /3!!&'="'= ,'=
 ,'= '= '= 
'=RJ "
"h 
'-?#$ "'"qq q 	q
 q 
qf6F5n<*=4S(j&L &Lr"   rR   z._ssl c                  L    \ rS rSrSrSS.       S
S jjrSS jrSS jrSrg	)SSLListeneri  a  A :class:`~trio.abc.Listener` for SSL/TLS-encrypted servers.

:class:`SSLListener` wraps around another Listener, and converts
all incoming connections to encrypted connections by wrapping them
in a :class:`SSLStream`.

Args:
  transport_listener (~trio.abc.Listener): The listener whose incoming
      connections will be wrapped in :class:`SSLStream`.

  ssl_context (~ssl.SSLContext): The :class:`~ssl.SSLContext` that will be
      used for incoming connections.

  https_compatible (bool): Passed on to :class:`SSLStream`.

Attributes:
  transport_listener (trio.abc.Listener): The underlying listener that was
      passed to ``__init__``.

F)rV   c               (    Xl         X l        X0l        g rB   )transport_listener_ssl_contextrZ   )r5   r   rk   rV   s       r    r8   SSLListener.__init__  s     #5'!1r"   c                   #    U R                   R                  5       I Sh  vN n[        UU R                  SU R                  S9$  N$7f)zuAccept the next connection and wrap it in an :class:`SSLStream`.

See :meth:`trio.abc.Listener.accept` for details.

NT)rU   rV   )r   acceptrR   r   rZ   r   s     r    r   SSLListener.accept  sJ      "&!8!8!?!?!AA!33	
 	
 Bs   AA%Ac                T   #    U R                   R                  5       I Sh  vN   g N7f)zClose the transport listener.N)r   r   rD   s    r    r   SSLListener.aclose  s     %%,,...s   (&()rZ   r   r   N)r   zListener[T_Stream]rk   r   rV   rC   rH   rI   )rH   zSSLStream[T_Stream]r   )	r&   r'   r(   r)   r*   r8   r   r   r+   r   r"   r    r   r     sA    4 "'	2.	2 ,	2
 	2 
	2
/r"   r   )r   zBaseException | NonerH   rC   )-
__future__r   r   operatorr   sslr   enumr   _Enumtypingr   r   r   r   r   r	   r
   r   r   r   _highlevel_genericr   _utilr   r   abcr   r   collections.abcr   r   r   r   r   r!   	Exceptionr$   r-   rK   rO   rR   r'   replacer   r   r"   r    <module>r      s    "     R R   1 * !3t CL: !& v % ) ), 
x3	4 :V, D
L) D
L D
LP !++33GR@	  1/(9X./ 1/ 1/r"   