
    H>qj                     2    d dl mZ ddlmZ  G d de      Zy)    )Union   )Eventc                   n    e Zd ZdZdZddeedf   fdZej                  Z	d Z
d Zd Zdefd	Zdefd
Zy)Opat  
    Base functionality for operators.

    The Observer pattern is implemented by the following three methods::

        on_source(self, *args)
        on_source_error(self, source, error)
        on_source_done(self, source)

    The default handlers will pass along source emits, errors and done events.
    This makes ``Op`` also suitable as an identity operator.
     Nsourcec                 V    t        j                  |        || j                  |       y y N)r   __init__
set_sourceselfr	   s     N/opt/rentech/trading_bot/.venv/lib/python3.12/site-packages/eventkit/ops/op.pyr   zOp.__init__   s%    tOOF#     c                     t        | j                        r| j                  j                  ||       y t        j                  j                  |       y r   )lenerror_eventemitr   logger	exception)r   r	   errors      r   on_source_errorzOp.on_source_error   s8    t !!&%0LL""5)r   c                     | j                   "| j                  | j                          d | _         | j                          y r   )_source_disconnect_fromset_done)r   r   s     r   on_source_donezOp.on_source_done#   s.    <<#!!$,,/DLr   c                     t        j                  |      }| j                  || _        | j                  |       y | j                  j	                  |       y r   )r   creater   _connect_fromr   r   s     r   r   zOp.set_source)   sA    f%<<!DLv&LL##F+r   c                     |j                         r| j                          y |j                  | j                  | j                  | j
                  d       y )NT)keep_ref)doner   connect	on_sourcer   r   r   s     r   r!   zOp._connect_from1   sA    ;;=MMONN$$##	  r   c                 f    |j                  | j                  | j                  | j                         y r   )
disconnectr&   r   r   r   s     r   r   zOp._disconnect_from;   s)    NN  	!r   r   )__name__
__module____qualname____doc__	__slots__r   r   r   r   r&   r   r   r   r!   r   r   r   r   r   r      sU     I$uUD[1 $
 

I*,E !u !r   r   N)typingr   eventr   r   r   r   r   <module>r0      s     9! 9!r   