
    g                     x   U d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
 d dlZd dlmZ d dlmZ  e	de      Z e       Zeeeg df   f   ed<   d	ed
dfdZdedededed
df
dZ edddd      Zeeeeef   f   ed<   e
ed   ed   ed   f   Ze
ed   ed   ed   ed   f   Z	 	 d"dee   dedededed ed
efd!Zy)#    )wraps)AnyCallableDictOptionalTupleTypeTypeVarUnionN)Literal)EventEmitterUpliftingEventEmitter)boundEMIT_WRAPPERSevent_emitterreturnc                 0    | t         v rt        |            yy)zAUnwrap an uplifted EventEmitter, returning it to its prior state.N)r   )r   s    @/var/www/openai/venv/lib/python3.12/site-packages/pyee/uplift.pyunwrapr      s    %m$& &    leftrighterror_handlerproxy_new_listenerc           	            j                   t        j                         t              dt        dt
        dt
        dt        f fd       }d fd}d fd}| _         |t         <   | _        y )	Neventargskwargsr   c                     j                  | ||      }s| dk7  r	j                  | ||      }nd}|xs |}|sj                  | |r|d   nd        |S )Nnew_listenerFr   )_call_handlers_emit_handle_potential_error)
r   r   r   left_handledright_handledhandledr   r   r   r   s
         r   wrapped_emitz_wrap.<locals>.wrapped_emit    si    !00fE .!8!00fEM!M/- 66ud1gSWXr   c                  X    t        j                  t        d             t                y )NzjPatched ee.unwrap() is deprecated and will be removed in a future release. Use pyee.uplift.unwrap instead.)warningswarnDeprecationWarningr   )r   s   r   _unwrapz_wrap.<locals>._unwrap3   s&    B	
 	tr   c                  b     _         r
t         <   n	t         =  ` _         t               y )N)emitr   r   )r   	left_emitleft_unwrapr   s   r   unwrap_hookz_wrap.<locals>.unwrap_hook<   s2    	"-M$d#	ur   )r   N)r-   r   getr   strr   boolr   )	r   r   r   r   r&   r+   r0   r.   r/   s	   ````   @@r   _wrapr4      sz     		I0=0A0A$0GK
9C  s t  $	 	 DI%M$DKr   )FT)TF)TT)FF)forwardbackwardbothneither_PROXY_NEW_LISTENER_SETTINGSnew
underlyingr8   r5   r6   r7   clserror_handlingr   r   c                     t         |   \  }} | |i |}t        ||f||f||f      }	|	|   \  }
}t        |||
|       t        ||||       |S )ap  A helper to create instances of an event emitter `cls` that inherits
    event behavior from an `underlying` event emitter instance.

    This is mostly helpful if you have a simple underlying event emitter
    that you don't have direct control over, but you want to use that
    event emitter in a new context - for example, you may want to `uplift` a
    `EventEmitter` supplied by a third party library into an
    `AsyncIOEventEmitter` so that you may register async event handlers
    in your `asyncio` app but still be able to receive events from the
    underlying event emitter and call the underlying event emitter's existing
    handlers.

    When called, `uplift` instantiates a new instance of `cls`, passing
    along any unrecognized arguments, and overwrites the `emit` method on
    the `underlying` event emitter to also emit events on the new event
    emitter and vice versa. In both cases, they return whether the `emit`
    method was handled by either emitter. Execution order prefers the event
    emitter on which `emit` was called.

    The `unwrap` function may be called on either instance; this will
    unwrap both `emit` methods.

    The `error_handling` flag can be configured to control what happens to
    unhandled errors:

    - 'new': Error handling for the new event emitter is always used and the
      underlying library's non-event-based error handling is inert.
    - 'underlying': Error handling on the underlying event emitter is always
      used and the new event emitter can not implement non-event-based error
      handling.
    - 'neither': Error handling for the new event emitter is used if the
      handler was registered on the new event emitter, and vice versa.

    Tuning this option can be useful depending on how the underlying event
    emitter does error handling. The default is 'new'.

    The `proxy_new_listener` option can be configured to control how
    `new_listener` events are treated:

    - 'forward': `new_listener` events are propagated from the underlying
      event emitter to the new event emitter but not vice versa.
    - 'both': `new_listener` events are propagated as with other events.
    - 'neither': `new_listener` events are only fired on their respective
      event emitters.
    - 'backward': `new_listener` events are propagated from the new event
      emitter to the underlying event emitter, but not vice versa.

    Tuning this option can be useful depending on how the `new_listener`
    event is used by the underlying event emitter, if at all. The default is
    'forward', since `underlying` may not know how to handle certain
    handlers, such as asyncio coroutines.

    Each event emitter tracks its own internal table of handlers.
    `remove_listener`, `remove_all_listeners` and `listeners` all
    work independently. This means you will have to remember which event
    emitter an event handler was added to!

    Note that both the new event emitter returned by `cls` and the
    underlying event emitter should inherit from `EventEmitter`, or at
    least implement the interface for the undocumented `_call_handlers` and
    `_emit_handle_potential_error` methods.
    )r:   r;   r8   )r9   dictr4   )r<   r;   r=   r   r   r   new_proxy_new_listenerunderlying_proxy_new_listenerr:   uplift_error_handlersnew_error_handlerunderlying_error_handlers               r   upliftrE   [   s    T 	%%78% "%d!5f!5CJN#JJ
#;c:EVK 3H2W//	#z,.DE	*c35RSJr   )r:   r5   )	functoolsr   typingr   r   r   r   r   r	   r
   r   r(   typing_extensionsr   	pyee.baser   r   r?   r   __annotations__r   r3   r4   r9   r2   ErrorStrategyProxyStrategyrE    r   r   <module>rN      sm    M M M  % " 7|L  9=tL(2t8"445 >', '4 '3
33 3 	3
 
3l >B		> d3dDj(9#9:  gengl&;WY=OOPI
+WV_gi>PP %*(1	W	#	$WW "W &	W
 W W Wr   