
    H>qj                        d dl Z d dlZd dlZd dlZd dlmZmZmZm	Z	m
Z
mZmZmZ ddlmZmZmZ  G d d      ZddlmZmZmZmZmZm
ZmZmZmZmZmZmZmZ ddl m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) dd	l*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 dd
l3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z; ddl<m=Z=m>Z> ddl?m@Z@ ddlAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJ ddlKmLZLmMZMmNZNmOZOmPZP ddlQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZe y)    N)AnyAsyncIterable	AwaitableIterableListOptionalTupleUnion   )NO_VALUEget_event_loopmain_event_loopc            
       ~   e Zd ZU dZdZeZ ej                  e       Ze	d    e
d<   e	d    e
d<   ee
d<   ee
d<   ee   e
d<   ee
d<   e	d    e
d	<   ddedefdZdefdZdefdZd Zd Z	 	 ddedd fdZddZd Zd Zd Zd ZdefdZddZddZd Zd Zed         Z dd!ed"efd#Z!eZ"eZ#eZ$eZ%d$ Z&d% Z'd& Z(dd'Z)d( Z*e!Z+	 d) Z,d* Z-ed+e.fd,       Z/ed-        Z0ed.e1dd/fd0       Z2ed1e3dd2fd3       Z4e	 	 dd5e.d6e5d7e6e.e5   df   dd8fd9       Z7eed:d4dfd6e5d7e6e.e5   df   dd;fd<       Z8ed4dd=d6e5d7e6e.e5   df   dd>fd?       Z9eddd@       Z:edd6e5dAe6e;df   ddBfdC       Z<e	 	 ddDed6e5d7e6e.e5   df   ddEfdF       Z=efddGZ>ddAe;ddHfdIZ?ddAe;ddJfdKZ@efddLZAdM fddNZBddOZCddPZDddQZEdddRZFdddSZGddTZHddUZIddVZJddWZKddXZLdYe6e;ef   ddZfd[ZM	 	 d	 dd\ZNdd]ZOdd^ZPdd_ZQdd`ZRddaZSefddbZTddcZUdddZVdddeZWdddfZXddgZYddhZZddiZ[	 	 ddje6e;df   dke6e5df   ddlfdmZ\ddAe;ddnfdoZ]ddpZ^ddqZ_dddrZ`ddsZaddtZbddduZcdddvZddwe;ddxfdyZe	 ddzd d{edd|fd}Zfdd~ZgddZhddZiddZjddZkd
ddeddfdZlddZmddZn	 d	 ddZoddeddfdZpddZqddZrddZsddZtddZuy)Eventz
    Enable event passing between loosely coupled components.
    The event emits values to connected listeners and has
    a selection of operators to create general data flow pipelines.

    Args:
        name: Name to use for this event.
    )error_event
done_event_name_value_slots_done_source__weakref__r   r   r   r   r   r   r   Tname_with_error_done_eventsc                     d | _         	 d | _        	 |r"t        dd      | _         t        dd      | _        g | _        |xs | j                  j
                  | _        t        | _        d| _	        d | _
        y )NerrorFdone)r   r   r   r   	__class____qualname__r   r   r   r   r   )selfr   r   s      M/opt/rentech/trading_bot/.venv/lib/python3.12/site-packages/eventkit/event.py__init__zEvent.__init__%   sq    	 	 #$We4D#FE2DO8T^^88

    returnc                     | j                   S )z$
        This event's name.
        )r   r    s    r!   r   z
Event.name9   s     zzr#   c                     | j                   S )ze
        ``True`` if event has ended with no more emits coming,
        ``False`` otherwise.
        )r   r&   s    r!   r   z
Event.done?   s    
 zzr#   c                 b    | j                   s#d| _         | j                  j                  |        yy)zd
        Set this event to be ended. The event should not emit anything
        after that.
        TN)r   r   emitr&   s    r!   set_donezEvent.set_doneF   s)    
 zzDJOO  & r#   c                 p    | j                   }|t        u rt        S t        |      dk(  r|d   S |r|S t        S )z2
        This event's last emitted value.
        r   r   )r   r   len)r    vs     r!   valuezEvent.valueO   sC     KK=x 	:FaKAaD	:*+Q	:19	:r#   Nkeep_refc                    t        |t              r|j                  |        | S | j                  |      \  }}|s/t	        |d      r#t        j                  || j                        }d}nd}|||g}| j                  j                  |       | j                  r|| j                  j                  |       | j                  r|| j                  j                  |       | S )a-  
        Connect a listener to this event. If the listener is added multiple
        times then it is invoked just as many times on emit.

        The ``+=`` operator can be used as a synonym for this method::

            import eventkit as ev

            def f(a, b):
                print(a * b)

            def g(a, b):
                print(a / b)

            event = ev.Event()
            event += f
            event += g
            event.emit(10, 5)

        Args:
            listener: The callback to invoke on emit of this event.
                It gets the ``*args`` from an emit as arguments.
                If the listener is a coroutine function, or a function that
                returns an awaitable, the awaitable is run in the
                asyncio event loop.
            error: The callback to invoke on error of this event.
                It gets (this event, exception) as two arguments.
            done: The callback to invoke on ending of this event.
                It gets this event as single argument.
            keep_ref:
                * ``True``: A strong reference to the callable is kept
                * ``False``: If the callable allows weak refs and it is
                  garbage collected, then it is automatically disconnected
                  from this event.
        r   N)
isinstanceOp
set_source_splithasattrweakrefref_onFinalizer   appendr   connectr   )	r    listenerr   r   r/   objfuncr7   slots	            r!   r:   zEvent.connectW   s    J h#%KKK)	TGC7++c4#3#34CCCS$4 ??t/OO##D) 1$$U+r#   c                    | j                  |      \  }}| j                  D ]4  }|d   |u s|d   s |d          |u s|d   |u s%dx|d<   x|d<   |d<    n | j                  D cg c]  }|g dk7  s| c}| _        || j                  j                  |       || j                  j                  |       | S c c}w )a  
        Disconnect a listener from this event.

        The ``-=`` operator can be used as a synonym for this method.

        Args:
            listener: The callback to disconnect. The callback is removed at
                most once. It is valid if the callback is already
                not connected.
            error: The error callback to disconnect.
            done: The done callback to disconnect.
        r   r      NNNN)r4   r   r   
disconnectr   )r    r;   r   r   r<   r=   r>   ss           r!   rB   zEvent.disconnect   s     KK)	TKK 	DQ3$q'gd1gi3.>Q4.22Q2$q'DG		
 #'++IQ6H1HqI''.OO&&t, Js   &B;3B;c                 n   | j                   D ]+  }|d   |u s|d   s |d          |u sdx|d<   x|d<   |d<   - | j                   D cg c]  }|g dk7  s| c}| _         | j                  | j                  j                  |       | j                  | j                  j                  |       yyc c}w )z
        Disconnect all listeners on the given object.
        (also the error and done listeners).

        Args:
            obj: The target object that is to be completely removed from
              this event.
        r   r   Nr@   rA   )r   r   disconnect_objr   )r    r<   r>   rC   s       r!   rE   zEvent.disconnect_obj   s     KK 	3DAw#~aWT!WY#-=.22Q2$q'DG	3 #'++IQ6H1HqI'++C0??&OO**3/ ' Js   	B2B2c                    || _         | j                  j                         D ]\  \  }}}	 |r |       }d}||r || }n|r
 ||g| }n || }|r-t        |d      r!t	               }t        j                  ||       ^ y# t        $ ra}t        | j                        r| j                  j                  | |       n%t        j                  j                  d| d|         Y d}~d}~ww xY w)z
        Emit a new value to all connected listeners.

        Args:
            args: Argument values to emit to listeners.
        N	__await__)loopzValue z caused exception for event )r   r   copyr5   r   asyncioensure_future	Exceptionr,   r   r)   r   logger	exception)r    argsr<   r7   r=   resultrH   r   s           r!   r)   z
Event.emit   s     "kk..0 	KNCdK%C;!%t!%c!1D!1!$dgfk:)+D))&t<#	K&  Kt''($$))$6LL** &B4&IK	Ks   AB	C,AC''C,c                 D    t        j                  | j                  g|  y)z
        Threadsafe version of :meth:`emit` that doesn't invoke the
        listeners directly but via the event loop of the main thread.
        N)r   call_soon_threadsafer)   )r    rO   s     r!   emit_threadsafezEvent.emit_threadsafe   s    
 	,,TYY>>r#   c                 R    | j                   D ]  }dx|d<   x|d<   |d<    g | _         y)z+
        Disconnect all listeners.
        Nr   r   r@   r   )r    r>   s     r!   clearzEvent.clear   s9     KK 	/D*..DG.d1gQ	/r#   c                 T    t               }|j                  | j                               S )a  
        Start the asyncio event loop, run this event to completion and
        return all values as a list::

            import eventkit as ev

            ev.Timer(0.25, count=10).run()
            ->
            [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5]

        .. note::

            When running inside a Jupyter notebook this will give an error
            that the asyncio event loop is already running. This can be
            remedied by applying
            `nest_asyncio <https://github.com/erdewit/nest_asyncio>`_
            or by using the top-level ``await`` statement of Jupyter::

                await event.list()
        )r   run_until_completelist)r    rH   s     r!   runz	Event.run   s#    * &&tyy{33r#   c                 h    | }|D ]*  }t         j                  |      }|j                  |       |}, |S )a  
        Form several events into a pipe::

            import eventkit as ev

            e1 = ev.Sequence('abcde')
            e2 = ev.Enumerate().map(lambda i, c: (i, i + ord(c)))
            e3 = ev.Star().pluck(1).map(chr)

            e1.pipe(e2, e3)     # or: ev.Event.Pipe(e1, e2, e3)
            ->
            ['a', 'c', 'e', 'g', 'i']

        Args:
            targets: One or more Events that have no source yet,
                or ``Event`` constructors that needs no arguments.
        )r   creater3   )r    targetssourcets       r!   pipez
Event.pipe  s=    $  	AQALL F	 r#   c                     t               }|D ]9  }t        j                  |      }|j                  |        |j	                  |       ; |S )a   
        Fork this event into one or more target events.
        Square brackets can be used as a synonym::

            import eventkit as ev

            ev.Range(2, 5)[ev.Min, ev.Max, ev.Sum].zip()
            ->
            [(2, 2, 2), (2, 3, 5), (2, 4, 9)]

        The events in the fork can be combined by one of the join
        methods of ``Fork``.

        Args:
            targets: One or more events that have no source yet,
                or ``Event`` constructors that need no arguments.
        )Forkr   r\   r3   r9   )r    r]   forkr_   s       r!   rc   z
Event.fork  sE    $ v 	AQALLKKN	 r#   c                     || _         y N)r   )r    r^   s     r!   r3   zEvent.set_source5  s	    r#   c                     | j                   D ]  }|d   |u sd x|d<   x|d<   |d<    | j                   D cg c]  }|g dk7  s| c}| _         y c c}w )Nr   r   r@   rA   rU   )r    r7   r>   rC   s       r!   r8   zEvent._onFinalize8  s^    KK 	3DAw#~.22Q2$q'DG	3 #'++IQ6H1HqIIs   AAc                 l   t        | t        j                        rd| fS t        | t        j                        r| j                  | j
                  fS t        | t        j                        r-t        | j                        t        u r| j                  | fS d| fS t        | d      r| dfS t        d|        )zC
        Split given callable in (object, function) tuple.
        N__call__zInvalid callable: )
r1   typesFunctionType
MethodType__self____func__BuiltinMethodTypetyper5   
ValueError)cs    r!   r4   zEvent._split>  s    
 a++,!95++,JJ

++5223AJJ4'

A& ay Q
#t91!566r#   skip_to_lasttuplesc                  K   fd}fd}fd}| j                         ryt        j                         | j                  |||       	 	 j	                          d{   \  }}|s%|r|nt        |      dk(  r|d   n	|r|nt         n|dk(  r|nK	 | j                  |||       y7 L# | j                  |||       w xY ww)a"  
        Create an asynchronous iterator that yields the emitted values
        from this event::

            async def coro():
                async for args in event.aiter():
                    ...

        :meth:`__aiter__` is a synonym for :meth:`aiter` with
        default arguments,

        Args:
            skip_to_last:
                * ``True``: Backlogged source values are skipped over to
                  yield only the latest value. Can be used as a
                  slipper clutch between a source that produces too fast
                  and the handling that can't keep up.
                * ``False``: All events are yielded.
            tuples:
                * ``True``: Always yield arguments as a tuple.
                * ``False``: Unpack single argument tuples.
        c                      r1j                         r!j                          j                         r!j                  d| f       y )N )qsize
get_nowait
put_nowait)rO   qrr   s    r!   on_eventzEvent.aiter.<locals>.on_eventj  s3    ggiLLN ggiLL"d$r#   c                 ,    j                  d|f       y )NERRORry   )r^   r   rz   s     r!   on_errorzEvent.aiter.<locals>.on_errorp  s    LL'5)*r#   c                 (    j                  d       y )N)DONENr~   )r^   rz   s    r!   on_donezEvent.aiter.<locals>.on_dones  s    LL(r#   Nr   r   r}   )r   rJ   Queuer:   getr,   r   rB   )	r    rr   rs   r{   r   r   whatrO   rz   s	    `      @r!   aiterzEvent.aiterS  s     .	%	+	) 99;07Xx1	9#$557]
d"($Tad1g%)Tx8W_J  OOHh8 + OOHh8s0   A	C	B1 "B/#7B1 C	/B1 1CC	c                 D    d| j                          d| j                   dS )NzEvent<z, >)r   r   r&   s    r!   __repr__zEvent.__repr__  s!    		}Bt{{m155r#   c                 ,    t        | j                        S re   )r,   r   r&   s    r!   __len__zEvent.__len__  s    4;;r#   c                      y)NT r&   s    r!   __bool__zEvent.__bool__  s    r#   c                 >    t        |d      s|f} | j                  | S )N__iter__)r5   rc   )r    fork_targetss     r!   __getitem__zEvent.__getitem__  s$    |Z0(?Ltyy,''r#   c                      fdfd fd} j                         rt        d      t        j                          j	                         j                  |       j                         S )aN  
        Asynchronously await the next emit of an event::

            async def coro():
                args = await event
                ...

        If the event does an empty ``emit()``, then the value
        of ``args`` is set to ``util.NO_VALUE``.

        :meth:`wait` and :meth:`__await__` are each other's inverse.
        c                      j                         s-j                  t        |       dk(  r| d   n	| r| nt               y y )Nr   r   )r   
set_resultr,   r   )rO   futs    r!   r{   z!Event.__await__.<locals>.on_event  s5    88:"4yA~DG44XO r#   c                 J    j                         sj                  |       y y re   )r   set_exception)r^   r   r   s     r!   r   z!Event.__await__.<locals>.on_error  s    88:!!%( r#   c                 *    j                         y re   )rB   )fr   r{   r    s    r!   on_future_donez'Event.__await__.<locals>.on_future_done  s    OOHh/r#   zEvent already done)r   rp   rJ   Futurer:   add_done_callbackrG   )r    r   r   r   r{   s   ` @@@r!   rG   zEvent.__await__  s^    	O
	)	0 99;122nnXx(n-}}r#   c                 l    | j                  |      \  t        fd| j                  D              S )z7
        See if callable is already connected.
        c              3   h   K   | ])  }|d    u xs |d   xr  |d          u xr |d   u  + yw)r   r   r@   Nr   ).0rC   r=   r<   s     r!   	<genexpr>z%Event.__contains__.<locals>.<genexpr>  sK      " qTS[2AaD2TQqTVs]D!D"s   /2)r4   anyr   )r    rq   r=   r<   s     @@r!   __contains__zEvent.__contains__  s4     KKN	T "[[" " 	"r#   c                 r    | j                   duxs | j                  du}| j                  | j                  |ffS )z%
        Don't pickle slots.
        N)r   r   r   r   )r    with_error_done_events     r!   
__reduce__zEvent.__reduce__  s>    
 D(GDOO4,G 	~~

,ABBBr#   event_namesc                 >    |D ]  }t        | |t        |              y)z
        Convenience function for initializing multiple events as members
        of the given object.

        Args:
            event_names: Names to use for the created events.
        N)setattrr   )r<   r   r   s      r!   initz
Event.init  s#       	,DCuT{+	,r#   c                    t        | t              r| S t        | d      r |        } t        | t              r| S t        | d      rt        j                  |       S t        | d      rt        j	                  |       S t        d|        )z
        Create an event from a async iterator, awaitable, or event
        constructor without arguments.

        Args:
            obj: The source object. If it's already an event then it
              is passed as-is.
        rh   	__aiter__rG   zInvalid type: )r1   r   r5   aiteratewaitrp   )r<   s    r!   r\   zEvent.create  sv     c5!J3
#%Cc5!JS+&>>#&&S+&::c?"~cU344r#   futureWaitc                     t        |       S )a  
        Create a new event that emits the value of the
        awaitable when it becomes available and then set this event done.

        :meth:`wait` and :meth:`__await__` are each other's inverse.

        Args:
            future: Future to wait on.
        )r   )r   s    r!   r   z
Event.wait  s     F|r#   aitAiteratec                     t        |       S )a  
        Create a new event that emits the yielded values from the
        asynchronous iterator.

        The asynchronous iterator serves as a source for both the time
        and value of emits.

        :meth:`aiterate` and :meth:`__aiter__` are each other's inverse.

        Args:
            ait: The asynchronous source iterator. It must ``await``
                at least once; If necessary use::

                    await asyncio.sleep(0)
        )r   )r   s    r!   r   zEvent.aiterate	  s    " }r#   r   valuesintervaltimesSequencec                     t        | ||      S )a|  
        Create a new event that emits the given values.
        Supply at most one ``interval`` or ``times``.

        Args:
            values: The source values.
            interval: Time interval in seconds between values.
            times: Relative times for individual values, in seconds since
                start of event. The sequence should match ``values``.
        )r   )r   r   r   s      r!   sequencezEvent.sequence  s     %00r#   r   Repeatc                     t        || ||      S )a  
        Create a new event that repeats ``value`` a number of ``count`` times.

        Args:
            value: The value to emit.
            count: Number of times to emit.
            interval: Time interval in seconds between values.
            times: Relative times for individual values, in seconds since
                start of event. The sequence should match ``values``.
        )r   )r.   countr   r   s       r!   repeatzEvent.repeat,  s     hue44r#   r   r   Rangec                     t        || |dS )aW  
        Create a new event that emits the values from a range.

        Args:
            args: Same as for built-in ``range``.
            interval: Time interval in seconds between values.
            times: Relative times for individual values, in seconds since
                start of event. The sequence should match the range.
        r   )r   )r   r   rO   s      r!   rangezEvent.range<  s     dXU;;r#   c                     t        | ||      S )a  
        Create a new event that emits the datetime value, at that datetime,
        from a range of datetimes.

        Args:
            start: Start time, can be specified as:

                * ``datetime.datetime``.
                * ``datetime.time``: Today is used as date.
                * ``int`` or ``float``: Number of seconds relative to now.
                  Values will be quantized to the given step.
            end: End time, can be specified as:

                * ``datetime.datetime``.
                * ``datetime.time``: Today is used as date.
                * ``None``: No end limit.
            step: Number of seconds, or ``datetime.timedelta``,
                to space between values.
        )	Timerange)startendsteps      r!   	timerangezEvent.timerangeK  s    * T**r#   r   Timerc                     t        | |      S )a  
        Create a new timer event that emits at regularly paced intervals
        the number of seconds since starting it.

        Args:
            interval: Time interval in seconds between emits.
            count: Number of times to emit, or ``None`` for no limit.
        )r   )r   r   s     r!   timerzEvent.timerb  s     Xu%%r#   rC   Marblec                     t        | ||      S )az  
        Create a new event that emits the values from a Rx-type marble string.

        Args:
            s: The string with characters that are emitted.
            interval: Time interval in seconds between values.
            times: Relative times for individual values, in seconds since
                start of event. The sequence should match the marble string.

        )r   )rC   r   r   s      r!   marblezEvent.marblen  s     a5))r#   c                     t        ||       S )z
        For every source value, apply predicate and re-emit when True.

        Args:
            predicate: The function to test every source value with.
                The default is to test the general truthiness with ``bool()``.
        )Filterr    	predicates     r!   filterzEvent.filter  s     i&&r#   Skipc                     t        ||       S )z
        Drop the first ``count`` values from source and follow the source
        after that.

        Args:
            count: Number of source values to drop.
        )r   r    r   s     r!   skipz
Event.skip  s     E4  r#   Takec                     t        ||       S )z
        Re-emit first ``count`` values from the source and then end.

        Args:
            count: Number of source values to re-emit.
        )r   r   s     r!   takez
Event.take  s     E4  r#   c                     t        ||       S )a  
        Re-emit values from the source until the predicate becomes False
        and then end.

        Args:
            predicate: The function to test every source value with.
                The default is to test the general truthiness with ``bool()``.
        )	TakeWhiler   s     r!   	takewhilezEvent.takewhile       D))r#   c                     |  S re   r   )xs    r!   <lambda>zEvent.<lambda>  s    E r#   c                     t        ||       S )a  
        Drop source values until the predicate becomes False and after that
        re-emit everything from the source.

        Args:
            predicate: The function to test every source value with.
                The default is to test the inverted general truthiness.
        )	DropWhiler   s     r!   	dropwhilezEvent.dropwhile  r   r#   c                     t        ||       S )z
        Re-emit values from the source until the ``notifier`` emits
        and then end. If the notifier ends without any emit then
        keep passing source values.

        Args:
            notifier: Event that signals to end this event.
        )	TakeUntil)r    notifiers     r!   	takeuntilzEvent.takeuntil  s     4((r#   c                     t        ||       S )z
        On emit of the source emit a constant value::

            emit(value) -> emit(constant)

        Args:
            constant: The constant value to emit.
        )Constant)r    constants     r!   r   zEvent.constant  s     $''r#   c                     t        ||       S )av  
        On emit of the source, emit the next value from an iterator::

            emit(a, b, ...) -> emit(next(it))

        The time of events follows the source and the values follow
        the iterator.

        Args:
            it: The source iterator to use for generating values. When the
                iterator is exhausted the event is set to be done.
        )Iterate)r    its     r!   iteratezEvent.iterate  s     r4  r#   c                     t        |||       S )z
        Count and emit the number of source emits::

            emit(a, b, ...) -> emit(count)

        Args:
            start: Start count.
            step: Add count by this amount for every new source value.
        )Countr    r   r   s      r!   r   zEvent.count  s     UD$''r#   c                     t        |||       S )z
        Add a count to every source value::

            emit(a, b, ...) -> emit(count, a, b, ...)

        Args:
            start: Start count.
            step: Increase by this amount for every new source value.
        )	Enumerater   s      r!   	enumeratezEvent.enumerate  s     d++r#   c                     t        |       S )z
        Add a timestamp (from time.time()) to every source value::

            emit(a, b, ...) -> emit(timestamp, a, b, ...)

        The timestamp is the float number in seconds since the
        midnight Jan 1, 1970 epoch.
        )	Timestampr&   s    r!   	timestampzEvent.timestamp  s     r#   c                     t        |d| iS )z
        Pad source values with extra arguments on the left::

            emit(a, b, ...) -> emit(*left_args, a, b, ...)

        Args:
            left_args: Arguments to inject.
        r^   )Partial)r    	left_argss     r!   partialzEvent.partial  s     	/$//r#   c                     t        |d| iS )z
        Pad source values with extra arguments on the right::

            emit(a, b, ...) -> emit(a, b, ..., *right_args)

        Args:
            right_args: Arguments to inject.
        r^   )PartialRight)r    
right_argss     r!   partial_rightzEvent.partial_right  s     Z555r#   c                     t        |       S )z
        Unpack a source tuple into positional arguments, similar to the
        star operator::

            emit((a, b, ...)) -> emit(a, b, ...)

        :meth:`star` and :meth:`pack` are each other's inverse.
        )Starr&   s    r!   starz
Event.star  s     Dzr#   c                     t        |       S )z
        Pack positional arguments into a tuple::

            emit(a, b, ...) -> emit((a, b, ...))

        :meth:`star` and :meth:`pack` are each other's inverse.
        )Packr&   s    r!   packz
Event.pack  s     Dzr#   
selectionsPluckc                     t        |d| iS )a  
        Extract arguments or nested properties from the source values.

        Select which argument positions to keep::

            emit(a, b, c, d).pluck(1, 2) -> emit(b, c)

        Re-order arguments::

            emit(a, b, c).pluck(2, 1, 0) -> emit(c, b, a)

        To do an empty emit leave ``selections`` empty::

            emit(a, b).pluck() -> emit()

        Select nested properties from positional arguments::

            emit(person, account).pluck(
                '1.number', '0.address.street') ->

            emit(account.number, person.address.street)

        If no value can be extracted then ``NO_VALUE`` is emitted in its place.

        Args:
            selections: The values to extract.
        r^   )r  )r    r  s     r!   pluckzEvent.pluck&  s    8 j...r#   c                      t        |||||       S )ao  
        Apply a sync or async function to source values using
        positional arguments::

            emit(a, b, ...) -> emit(func(a, b, ...))

        or if ``func`` returns an awaitable then it will be awaited::

            emit(a, b, ...) -> emit(await func(a, b, ...))

        In case of timeout or other failure, ``NO_VALUE`` is emitted.

        Args:
            func: The function or coroutine constructor to apply.
            timeout: Timeout in seconds since coroutine is started
            ordered:
                * ``True``: The order of emitted results preserves the
                  order of the source values.
                * ``False``: Results are in order of completion.
            task_limit: Max number of concurrent tasks, or None for no limit.

        ``timeout``, ``ordered`` and ``task_limit`` apply to
        async functions only.
        )Map)r    r=   timeoutordered
task_limits        r!   mapz	Event.mapD  s    6 4':t<<r#   c                     t        |||       S )a  
        Higher-order event map that creates a new ``Event`` instance
        for every source value::

            emit(a, b, ...) -> new Event constr(a, b, ...)

        Args:
            constr: Constructor function for creating a new event.
                Apart from returning  an ``Event``, the constructor may also
                return an awaitable or an asynchronous iterator, in which
                case an ``Event`` will be created.
            joiner: Join operator to combine the emits of nested events.
        )Emap)r    constrjoiners      r!   emapz
Event.emapa  s     FFD))r#   c                     t        ||       S )as  
        :meth:`emap` that uses :meth:`merge` to combine the nested events::

            marbles = [
                'A   B    C    D',
                '_1   2  3    4',
                '__K   L     M   N']

            ev.Range(3).mergemap(lambda v: ev.Marble(marbles[v]))
            ->
            ['A', '1', 'K', 'B', '2', 'L', '3', 'C', 'M', '4', 'D', 'N']
        )Mergemapr    r  s     r!   mergemapzEvent.mergemapq       %%r#   c                     t        ||       S )a  
        :meth:`emap` that uses :meth:`concat` to combine the nested events::

            marbles = [
                'A    B    C    D',
                '_       1    2    3    4',
                '__                  K    L      M   N']

            ev.Range(3).concatmap(lambda v: ev.Marble(marbles[v]))
            ->
            ['A', 'B', '1', '2', '3', 'K', 'L', 'M', 'N']
        )	Concatmapr  s     r!   	concatmapzEvent.concatmap       &&r#   c                     t        ||       S )a  
        :meth:`emap` that uses :meth:`chain` to combine the nested events::

            marbles = [
                'A    B    C    D           ',
                '_       1    2    3    4',
                '__                  K    L      M   N']

            ev.Range(3).chainmap(lambda v: ev.Marble(marbles[v]))
            ->
            ['A', 'B', 'C', 'D', '1', '2', '3', '4', 'K', 'L', 'M', 'N']
        )Chainmapr  s     r!   chainmapzEvent.chainmap  r  r#   c                     t        ||       S )a  
        :meth:`emap` that uses :meth:`switch` to combine the nested events::

            marbles = [
                'A    B    C    D           ',
                '_                 K    L      M   N',
                '__      1    2      3    4'
            ]
            ev.Range(3).switchmap(lambda v: Event.marble(marbles[v]))
            ->
            ['A', 'B', '1', '2', 'K', 'L', 'M', 'N'])
        )	Switchmapr  s     r!   	switchmapzEvent.switchmap  r  r#   c                     t        |||       S )a  
        Apply a two-argument reduction function to the previous reduction
        result and the current value and emit the new reduction result.

        Args:
            func: Reduction function::

                emit(args) -> emit(func(prev_args, args))

            initializer: First argument of first reduction::

                    first_result = func(initializer, first_value)

                If no initializer is given, then the first result is
                emitted on the second source emit.
        )Reduce)r    r=   initializers      r!   reducezEvent.reduce  s    " dK..r#   c                     t        |       S )z 
        Minimum value.
        )Minr&   s    r!   minz	Event.min       4yr#   c                     t        |       S )z 
        Maximum value.
        )Maxr&   s    r!   maxz	Event.max  r,  r#   c                     t        ||       S )zX
        Total sum.

        Args:
            start: Value added to total sum.
        )Sumr    r   s     r!   sumz	Event.sum  s     5$r#   c                     t        ||       S )zW
        Total product.

        Args:
            start: Initial start value.
        )Productr2  s     r!   productzEvent.product  s     ud##r#   c                     t        |       S )z 
        Total average.
        )Meanr&   s    r!   meanz
Event.mean       Dzr#   c                     t        |       S )zH
        Test if predicate holds for at least one source value.
        )r   r&   s    r!   r   z	Event.any  r,  r#   c                     t        |       S )z@
        Test if predicate holds for all source values.
        )Allr&   s    r!   allz	Event.all  r,  r#   nweightEmac                     t        |||       S )z
        Exponential moving average.

        Args:
            n: Number of periods.
            weight: Weight of new value.

        Give either ``n`` or ``weight``.
        The relation is ``weight = 2 / (n + 1)``.
        )rA  )r    r?  r@  s      r!   emaz	Event.ema  s     1fd##r#   Previousc                     t        ||       S )a  
        For every source value, emit the ``count``-th previous value::

            source:  -ab---c--d-e-
            output:  --a---b--c-d-

        Starts emitting on the ``count + 1``-th source emit.

        Args:
            count: Number of periods to go back.
        )rD  r   s     r!   previouszEvent.previous  s     t$$r#   c                     t        |       S )z
        Emit ``(previous_source_value, current_source_value)`` tuples.
        Starts emitting on the second source emit::

            source:  -a----b------c--------d-----
            output:  ------(a,b)--(b,c)----(c,d)-
        )Pairwiser&   s    r!   pairwisezEvent.pairwise  s     ~r#   c                     t        |       S )zT
        Emit only source values that have changed from the previous value.
        )Changesr&   s    r!   changeszEvent.changes  s     t}r#   c                     t        ||       S )a1  
        Emit only unique values, dropping values that have already
        been emitted.

        Args:
            key: `The callable `'key(value)`` is used to group values.
                The default of ``None`` groups values by equality.
                The resulting group must be hashable.
        )Unique)r    keys     r!   uniquezEvent.unique  s     c4  r#   c                     t        |       S )zI
        Wait until source has ended and re-emit its last value.
        )Lastr&   s    r!   lastz
Event.last(  r:  r#   c                     t        |       S )zR
        Collect all source values and emit as list when the source ends.
        )ListOpr&   s    r!   rY   z
Event.list.       d|r#   c                     t        ||       S )z
        Emit a ``deque`` with the last ``count`` values from the source
        (or less in the lead-in phase).

        Args:
            count: Number of last periods to use, or 0 to use all.
        )Dequer   s     r!   dequezEvent.deque4       UD!!r#   c                     t        ||       S )z
        Emit a numpy array with the last ``count`` values from the source
        (or less in the lead-in phase).

        Args:
            count: Number of last periods to use, or 0 to use all.
        )Arrayr   s     r!   arrayzEvent.array>  rZ  r#   sizeChunkc                     t        ||       S )z
        Chunk values up in lists of equal size. The last chunk can be shorter.

        Args:
            size: Chunk size.
        )r_  )r    r^  s     r!   chunkzEvent.chunkH  s     T4  r#   r   
emit_empty	ChunkWithc                     t        |||       S )z
        Emit a chunked list of values when the timer emits.

        Args:
            timer: Event to use for timing the chunks.
            emit_empty: Emit empty list if no values present since last emit.
        )rc  )r    r   rb  s      r!   	chunkwithzEvent.chunkwithQ  s     
D11r#   c                     t        | g| S )a  
        Re-emit from a source until it ends, then move to the next source,
        Repeat until all sources have ended, ending the chain.
        Emits from pending sources are queued up::

            source 1:  -a----b---c|
            source 2:        --2-----3--4|
            source 3:  ------------x---------y--|
            output:    -a----b---c2--3--4x---y--|


        Args:
            sources: Source events.
        )Chainr    sourcess     r!   chainzEvent.chain\  s     T$G$$r#   c                     t        | g| S )a>  
        Re-emit everything from the source events::

            source 1:  -a----b-------------c------d-|
            source 2:     ------1-----2------3--4-|
            source 3:      --------x----y--|
            output:    -a----b--1--x--2-y--c-3--4-d-|

        Args:
            sources: Source events.
        )Mergerh  s     r!   mergezEvent.mergem  s     T$G$$r#   c                     t        | g| S )ai  
        Re-emit everything from one source until it ends and then move
        to the next source::

            source 1:  -a----b-----|
            source 2:    --1-----2-----3----4--|
            source 3:                 -----------x--y--|
            output:    -a----b---------3----4----x--y--|

        Args:
            sources: Source events.
        )Concatrh  s     r!   concatzEvent.concat{       d%W%%r#   c                     t        | g| S )az  
        Re-emit everything from one source and move to another source as soon
        as that other source starts to emit::

            source 1:  -a----b---c-----d---|
            source 2:        -----------x---y-|
            source 3:  ---------1----2----3-----|
            output:    -a----b--1----2--x---y---|

        Args:
            sources: Source events.
        )Switchrh  s     r!   switchzEvent.switch  rq  r#   c                     t        | g| S )a  
        Zip sources together: The i-th emit has the i-th value from
        each source as positional arguments. Only emits when each source has
        emtted its i-th value and ends when any source ends::

            source 1:    -a----b------------------c------d---e--f---|
            source 2:    --------1-------2-------3---------4-----|
            output emit: --------(a,1)---(b,2)----(c,3)----(d,4)-|


        Args:
            sources: Source events.
        )Ziprh  s     r!   zipz	Event.zip  s     4"'""r#   )r   r   	Ziplatestc                     t        | g|d|iS )a$  
        Emit zipped values with the latest value from each of the
        source events. Emits every time when a source emits::

            source 1:   -a-------------------b-------c---|
            source 2:   ---------------1--------------------2------|
            output emit: (a,NoValue)---(a,1)-(b,1)---(c,1)--(c,2)--|

        Args:
            sources: Source events.
            partial:
                * True: Use ``NoValue`` for sources that have not emitted yet.
                * False: Wait until all sources have emitted.
        r   )rx  )r    r   ri  s      r!   	ziplatestzEvent.ziplatest  s     9999r#   c                     t        ||       S )a!  
        Time-shift all source events by a delay::

            source:  -abc-d-e---f---|
            output:  ---abc-d-e---f---|

        This applies to the source errors and the source done event as well.

        Args:
            delay: Time delay of all events (in seconds).
        )Delay)r    delays     r!   r}  zEvent.delay  s     UD!!r#   c                     t        ||       S )z
        When the source doesn't emit for longer than the timeout period,
        do an empty emit and set this event as done.

        Args:
            timeout: Timeout value.
        )Timeout)r    r  s     r!   r  zEvent.timeout  s     w%%r#   c                     t        ||||       S )a  
        Limit number of emits per time without dropping values.
        Values that come in too fast are queued and re-emitted as soon
        as allowed by the limits.

        A nested ``status_event`` emits ``True`` when throttling starts
        and ``False`` when throttling ends.

        The limit can be dynamically changed with ``set_limit``.

        Args:
            maximum: Maximum payload per interval.
            interval: Time interval (in seconds).
            cost_func: The sum of ``cost_func(value)`` for every
                source value inside the ``interval`` that is to remain
                under the ``maximum``. The default is to count every
                source value as 1.
        )Throttle)r    maximumr   	cost_funcs       r!   throttlezEvent.throttle  s    ( 9d;;r#   on_firstDebouncec                     t        |||       S )a  
        Filter out values from the source that happen in rapid succession.

        Args:
            delay: Maximal time difference (in seconds) between
                successive values before debouncing kicks in.
            on_first:
                * True: First value is send immediately and following values
                  in the rapid succession are dropped::

                    source: -abcd----efg-
                    output: -a-------e---

                * False: Last value of a rapid succession is send after
                  the delay and the values before that are dropped::

                    source:  -abcd----efg--
                    output:   ----d------g-
        )r  )r    r}  r  s      r!   debouncezEvent.debounce  s    ( x..r#   c                     t        |       S )z=
        Create a shallow copy of the source values.
        )Copyr&   s    r!   rI   z
Event.copy  r:  r#   c                     t        |       S )z:
        Create a deep copy of the source values.
        )Deepcopyr&   s    r!   deepcopyzEvent.deepcopy  s     ~r#   c                     t        ||       S )z
        At the times that the timer emits, sample the value from this
        event and emit the sample.

        Args:
            timer: Event used to time the samples.
        )Sample)r    r   s     r!   samplezEvent.sample
  s     eT""r#   c                     t        |       S )z.
        Emit errors from the source.
        )Errorsr&   s    r!   errorszEvent.errors  rV  r#   c                     t        |       S )z3
        End on any error from the source.
        )
EndOnErrorr&   s    r!   end_on_errorzEvent.end_on_error  s     $r#   )rv   T)NNF)NN)r]   r   )r]   r   r$   rb   )FF)r$   rb   )r   N)r   Nr   )r$   r   re   )r$   r   )r   )r$   r   )r$   r   )r   r   r$   r   )r$   r   )r$   r   )r   r   )r$   r   )r$   r   )r$   r   )r$   r   )r$   r   )r$   r  )r$   r  )NTN)r$   r  )r  AddableJoinOpr$   r  )r$   r  )r$   r  )r$   r   )r$   r#  )r$   r&  )r$   r*  )r$   r.  )r   )r$   r1  )r$   r5  )r$   r8  )r$   r   )r$   r=  )r$   rH  )r$   rK  )r$   rN  )r$   rR  )r$   rU  )r$   rX  )r$   r\  )T)ri  r   r$   rg  )r$   rl  )r$   ro  )r$   rs  )r$   rv  )r$   r|  )r$   r  )r$   r  )F)r$   r  )r$   r  )r   r   r$   r  )r$   r  )r$   r  )v__name__
__module__r   __doc__	__slots__r   logging	getLoggerrM   r   __annotations__strAnyTyper   boolr"   r   r   r*   r.   r:   rB   rE   r)   rS   rV   rZ   r`   rc   r3   r8   staticmethodr4   r   __iadd____isub__rh   __or__r   r   r   r   rG   r   r   r   r   r   r\   r   r   r   r   floatr
   r   r   r   r   intr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r
  r  r  r  r  r!  r$  r(  r+  r/  r3  r6  r9  r   r>  rC  rF  rI  rL  rP  rS  rY   rY  r]  ra  re  rj  rm  rp  rt  rw  rz  r}  r  r  r  rI   r  r  r  r  r   r#   r!   r   r      s2   5I HWx(F'""!!JOJKgS  (c d ': 26!&55+25n40$ KD?4T 4022J 7 7(29 29d 29h HHHF6 (
@ I"C 	,x 	, 	, 5 5. 
Y 
6 
 
 m 
  $ 012611(-1%$./1;E1 1 !q265/45%$./5;C5 5 %&26<"<%$./<;B< < + +, 	& 	&eCI&6 	&' 	& 	& &'26**#*%$./*;C* *"  $ '!# !f !!# !f ! #' 	* #2 	*	)	(!
(
,		0	6	/sCx /W /> /3= %=:* &'&' (0 /& $ )-)-$U39% $%+&$27$%c %* %
!""!# !' ! 6:	2 	2.2	2>I	2%"%&&#  37 :4 :; :""& 04<8B<,/ / /,# r#   r   )r=  r   r   rX  rA  r   r.  r8  r*  rH  r5  r&  r1  )	r\  ArrayAllArrayAnyArrayMax	ArrayMeanArrayMin	ArrayProdArrayStdArraySum)r  rg  ro  rb   rl  rs  rv  rx  )r   r   r   r   r   r   r   r   )r  r  )r2   )	rK  r   r   rR  r   r   r   r   rN  )r  r|  r  r  r  )r   r_  rc  r  r   r  r  r  r   r   r  r  r  r   r   r  rD  r  r#  r   )frJ   r  ri   r6   typingr   r  r   r   r   r   r   r	   r
   utilr   r   r   r   ops.aggregater=  r   rX  rA  rU  r.  r8  r*  rH  r5  r&  r1  	ops.arrayr\  r  r  r  r  r  r  r  r  ops.combiner  rg  ro  rb   rl  rs  rv  rx  
ops.creater   r   r   r   r   r   r   r   ops.miscr  r  ops.opr2   
ops.selectrK  r   r   rR  r   r   r   r   rN  
ops.timingr  r|  r  r  r  ops.transformr   r_  rc  r  r   r  r  r  r   r   r  r  r  r   r   r  rD  r  r#  r   r   r#   r!   <module>r     s          < ;R  R j(     G G GG G G ( P P P0 0* * * * * *r#   