
    vKg              
          S SK Jr  S SKJrJrJ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  \(       a  S SKJr  \" S\S	9r\" S
\S	9rSS jrSS jr\	\R*                  " SSS9 " S S\\\\4   5      5       5       rg)    )annotations)TYPE_CHECKINGGenericTypeVarN)final   )AsyncResourceHalfCloseableStreamReceiveStream
SendStream)	TypeGuardSendStreamT)boundReceiveStreamTc                   #    [         R                  " 5        nUR                  5         U R                  5       I Sh  vN   SSS5        g N! , (       d  f       g= f7f)a  Close an async resource or async generator immediately, without
blocking to do any graceful cleanup.

:class:`~trio.abc.AsyncResource` objects guarantee that if their
:meth:`~trio.abc.AsyncResource.aclose` method is cancelled, then they will
still close the resource (albeit in a potentially ungraceful
fashion). :func:`aclose_forcefully` is a convenience function that
exploits this behavior to let you force a resource to be closed without
blocking: it works by calling ``await resource.aclose()`` and then
cancelling it immediately.

Most users won't need this, but it may be useful on cleanup paths where
you can't afford to block, or if you want to close a resource and don't
care about handling it gracefully. For example, if
:class:`~trio.SSLStream` encounters an error and cannot perform its
own graceful close, then there's no point in waiting to gracefully shut
down the underlying transport either, so it calls ``await
aclose_forcefully(self.transport_stream)``.

Note that this function is async, and that it acts as a checkpoint, but
unlike most async functions it cannot block indefinitely (at least,
assuming the underlying resource object is correctly implemented).

N)trioCancelScopecancelaclose)resourcecss     W/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/trio/_highlevel_generic.pyaclose_forcefullyr      sA     2 
			r
		oo 
	 
	s,   A$AA
A	A
A
AAc                    [        U S5      $ )z,Check if the stream has a send_eof() method.send_eof)hasattr)streams    r   _is_halfclosabler   2   s    6:&&    F)eqslotsc                  d    \ rS rSr% SrS\S'   S\S'   SS jrSS jrSS	 jrSSS jjr	SS jr
Srg
)StapledStream7   a>  This class `staples <https://en.wikipedia.org/wiki/Staple_(fastener)>`__
together two unidirectional streams to make single bidirectional stream.

Args:
  send_stream (~trio.abc.SendStream): The stream to use for sending.
  receive_stream (~trio.abc.ReceiveStream): The stream to use for
      receiving.

Example:

   A silly way to make a stream that echoes back whatever you write to
   it::

      left, right = trio.testing.memory_stream_pair()
      echo_stream = StapledStream(SocketStream(left), SocketStream(right))
      await echo_stream.send_all(b"x")
      assert await echo_stream.receive_some() == b"x"

:class:`StapledStream` objects implement the methods in the
:class:`~trio.abc.HalfCloseableStream` interface. They also have two
additional public attributes:

.. attribute:: send_stream

   The underlying :class:`~trio.abc.SendStream`. :meth:`send_all` and
   :meth:`wait_send_all_might_not_block` are delegated to this object.

.. attribute:: receive_stream

   The underlying :class:`~trio.abc.ReceiveStream`. :meth:`receive_some`
   is delegated to this object.

r   send_streamr   receive_streamc                T   #    U R                   R                  U5      I Sh  vN $  N7f)z$Calls ``self.send_stream.send_all``.N)r%   send_all)selfdatas     r   r(   StapledStream.send_allb   s"     %%..t4444   (&(c                R   #    U R                   R                  5       I Sh  vN $  N7f)z9Calls ``self.send_stream.wait_send_all_might_not_block``.N)r%   wait_send_all_might_not_blockr)   s    r   r.   +StapledStream.wait_send_all_might_not_blockf   s      %%CCEEEEs   '%'c                   #    U R                   n[        U5      (       a  UR                  5       I Sh  vN $ UR                  5       I Sh  vN $  N N7f)zShuts down the send side of the stream.

If :meth:`self.send_stream.send_eof() <trio.abc.HalfCloseableStream.send_eof>` exists,
then this calls it. Otherwise, this calls
:meth:`self.send_stream.aclose() <trio.abc.AsyncResource.aclose>`.
N)r%   r   r   r   )r)   r   s     r   r   StapledStream.send_eofj   sD      !!F##***(( +(s!   0AAA
AAANc                T   #    U R                   R                  U5      I Sh  vN $  N7f)z+Calls ``self.receive_stream.receive_some``.N)r&   receive_some)r)   	max_bytess     r   r4   StapledStream.receive_somex   s"     ((55i@@@@r,   c                   #     U R                   R                  5       I Sh  vN   U R                  R                  5       I Sh  vN   g N' N! U R                  R                  5       I Sh  vN    f = f7f)z,Calls ``aclose`` on both underlying streams.N)r%   r   r&   r/   s    r   r   StapledStream.aclose|   sZ     	/""))+++%%,,... ,.$%%,,...sI   A5A A	A A5AA5	A A5A2+A.,A22A5 )r*   zbytes | bytearray | memoryviewreturnNone)r:   r;   )N)r5   z
int | Noner:   bytes)__name__
__module____qualname____firstlineno____doc____annotations__r(   r.   r   r4   r   __static_attributes__r9   r   r   r#   r#   7   s1     D ""5F)A/r   r#   )r   r	   r:   r;   )r   r   r:   zTypeGuard[HalfCloseableStream])
__future__r   typingr   r   r   attrsr   
trio._utilr   abcr	   r
   r   r   typing_extensionsr   r   r   r   r   definer#   r9   r   r   <module>rK      s    " 2 2    N N+ m:6)? <'
 e$H/K'(H/ % H/r   