ó
    X=Œj   ã                   óœ   • S SK JrJr  S SKJr  S SKJrJrJrJ	r	J
r
JrJrJrJr  S SKrS SKJrJr  \rS/r\R*                  r " S S\5      rg)é    )ÚAbstractAsyncContextManagerÚasynccontextmanager)ÚTracebackType)	ÚAnyÚAsyncGeneratorÚ	AwaitableÚCallableÚcastÚDictÚOptionalÚTupleÚTypeN)ÚEventEmitterÚ	PyeeErrorÚTrioEventEmitterc                   ó4  ^ • \ rS rSrSr  SS\S\\   S\S   4U 4S jjjrS\S	\	S
\
\S4   S\\\4   S\	/ \S   4   4
S jrS\S	\	S
\
\S4   S\\\4   SS4
S jr\S\S\S   4S j5       rS\SS 4S jrS\S\\\      S\\   S\\   S\\   4
S jrSrU =r$ )r   é   a  An event emitter class which can run trio tasks in a trio nursery.

By default, this class will lazily create both a nursery manager (the
object returned from `trio.open_nursery()` and a nursery (the object
yielded by using the nursery manager as an async context manager). It is
also possible to supply an existing nursery manager via the `manager`
argument, or an existing nursery via the `nursery` argument.

Instances of TrioEventEmitter are themselves async context managers, so
that they may manage the lifecycle of the underlying trio nursery. For
example, typical usage of this library may look something like this::

```py
async with TrioEventEmitter() as ee:
    # Underlying nursery is instantiated and ready to go
    @ee.on('data')
    async def handler(data):
        print(data)

    ee.emit('event')

# Underlying nursery and manager have been cleaned up
```

Unlike the case with the EventEmitter, all exceptions raised by event
handlers are automatically emitted on the `error` event. This is
important for trio coroutines specifically but is also handled for
synchronous functions for consistency.

For trio coroutine event handlers, calling emit is non-blocking. In other
words, you should not attempt to await emit; the coroutine is scheduled
in a fire-and-forget fashion.
NÚselfÚnurseryÚmanagerz)AbstractAsyncContextManager[trio.Nursery]c                 óÖ   >• [         [        U ]  5         S U l        S U l        U(       a  U(       a  [        S5      eXl        g U(       a  X l        g [        R                  " 5       U l        g )Nz?You may either pass a nursery or a nursery manager but not both)Úsuperr   Ú__init__Ú_nurseryÚ_managerr   ÚtrioÚopen_nursery)r   r   r   Ú	__class__s      €ÚM/Users/stevendouglas/BidBrain/.venv/lib/python3.13/site-packages/pyee/trio.pyr   ÚTrioEventEmitter.__init__@   sV   ø€ ô
 	Ô Ñ.Ô0Ø+/ˆŒØOSˆŒÞÞÜØXóð ð $�MÞØ#�Mä ×-Ò-Ó/ˆD�Mó    ÚfÚargs.ÚkwargsÚreturnc                 ó$   ^ ^^^• SUUUU 4S jjnU$ )Nc               “   ó†   >#   •  T" T0 TD6I S h  v•N   g  N! [          a  n TR                  SU 5         S n A g S n A ff = f7f)NÚerror)Ú	ExceptionÚemit)Úexcr#   r"   r$   r   s    €€€€r   ÚrunnerÚ.TrioEventEmitter._async_runner.<locals>.runnerY   s>   øé € ð(Ù˜Ð( Ñ(×(Ó(øÜó (Ø—	‘	˜' 3×'Ñ'ûð(üs0   ƒA… �‘ •A– ˜
>¢9´A¹>¾A)r%   N© )r   r"   r#   r$   r,   s   ```` r   Ú_async_runnerÚTrioEventEmitter._async_runnerS   s   û€ ÷	(ò 	(ð ˆr!   c                 ó’   • U R                   (       d  [        S5      eU R                   R                  U R                  XU5      5        g )NzUninitialized trio nursery)r   r   Ú
start_soonr/   )r   r"   r#   r$   s       r   Ú	_emit_runÚTrioEventEmitter._emit_runa   s6   € ð �}�}ÜÐ8Ó9Ð9Ø�‰× Ñ  ×!3Ñ!3°A¸VÓ!DÕEr!   )r   Nc                óþ   #   • U R                   b  U 7v •  gU R                  b1  U R                   ISh  v•N nXl         U 7v •  SSS5      ISh  v•N   g[        S5      e N+ N! , ISh  v•N  (       d  f       g= f7f)zçReturns an async contextmanager which manages the underlying
nursery to the EventEmitter. The `TrioEventEmitter`'s
async context management methods are implemented using this
function, but it may also be used directly for clarity.
Nz(Uninitialized nursery or nursery manager)r   r   r   )r   r   s     r   ÚcontextÚTrioEventEmitter.contextk   sW   é € ð �=‰=Ñ$ØŒJØ�]‰]Ñ&Ø—}—}’}¨Ø '”Ø“
÷ %—}�}ô ÐFÓGÐG÷	 %—}—}’}üsD   ‚1A=³A´A=·A#ÁA=ÁA!ÁA=Á!A=Á#A:Á)A,Á*A:Á6A=c              ƒ   ó˜   #   • U R                  5       U l        [        [        U R                  5      R	                  5       I S h  v•N $  N7f)N)r6   Ú_contextr
   r   Ú
__aenter__)r   s    r   r:   ÚTrioEventEmitter.__aenter__}   s7   é € à�L‰L‹Nð 	Œô œ#˜tŸ}™}Ó-×8Ñ8Ó:×:Ð:Ñ:ùs   ‚AA
ÁAÁA
ÚtypeÚvalueÚ	tracebackc              ƒ   ó´   #   • U R                   c  [        S5      eU R                   R                  XU5      I S h  v•N nS U l         S U l        S U l        U$  N7f)Nz(Attempting to exit uninitialized context)r9   r   Ú	__aexit__r   r   )r   r<   r=   r>   Úrvs        r   r@   ÚTrioEventEmitter.__aexit__ƒ   sV   é € ð �=‰=Ñ ÜÐFÓGÐGØ—=‘=×*Ñ*¨4¸	ÓB×BˆØˆŒØˆŒØˆŒØˆ	ñ	 Cùs   ‚8AºA»A)r9   r   r   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚSelfr   ÚNurseryr   r	   r   r   r   Ústrr   r/   r3   r   r   r6   r:   r   ÚBaseExceptionr   Úboolr@   Ú__static_attributes__Ú__classcell__)r   s   @r   r   r      sl  ø† ñ ðH &*ØIMñ0Øð0à˜'Ñ"ð0ð ÐEÑF÷0ð 0ð&Øðàðð �C˜�H‰oðð �S˜#�X‘ð	ð
 
�"�i ‘oÐ%Ñ	&ôðFØðFàðFð �C˜�H‰oðFð �S˜#�X‘ð	Fð
 
ôFð ðHØðHà	Ð0Ñ	1óHó ðHð";˜tð ;Ð(:ô ;ðØðà�t˜MÑ*Ñ+ðð ˜Ñ&ðð ˜MÑ*ð	ð
 
�$‰÷ò r!   )Ú
contextlibr   r   Útypesr   Útypingr   r   r   r	   r
   r   r   r   r   r   Ú	pyee.baser   r   rH   Ú__all__rI   r   r.   r!   r   Ú<module>rT      sK   ð÷ HÝ ÷
÷ 
õ 
ó ç -à
€àÐ
€ð �,‰,€ôr�|õ rr!   