o
    i                     @   s    d dl mZ G dd deZdS )    )osetc                   @   s6   e Zd ZdZi fddZdd ZdddZd	d
 ZdS )EventManagera  Spyne supports a simple event system that can be used to have repetitive
    boilerplate code that has to run for every method call nicely tucked away
    in one or more event handlers. The popular use-cases include things like
    database transaction management, logging and performance measurements.

    Various Spyne components support firing events at various stages during the
    request handling process, which are documented in the relevant classes.

    The events are stored in an ordered set. This means that the events are ran
    in the order they were added and adding a handler twice does not cause it to
    run twice.
    c                 C   s   || _ t|| _dS )aw  Initializer for the ``EventManager`` instance.

        :param parent: The owner of this event manager. As of Spyne 2.13, event
        managers can be owned by multiple objects, in which case this property
        will be none.

        :param handlers: A dict of event name (string)/callable pairs. The dict
        shallow-copied to the ``EventManager`` instance.
        N)parentdicthandlers)selfr   r    r   K/var/www/html/LicenciasMIG/venv/lib/python3.10/site-packages/spyne/evmgr.py__init__&   s   zEventManager.__init__c                 C   s(   | j |t }|| || j |< dS )a5  Register a handler for the given event name.

        :param event_name: The event identifier, indicated by the documentation.
                           Usually, this is a string.
        :param handler: A static python function that receives a single
                        MethodContext argument.
        N)r   getr   add)r   
event_namehandlerr   r   r   r	   add_listener4   s   	
zEventManager.add_listenerNc                 C   s(   |d u r
| j |= d S | j | | d S N)r   remove)r   r   r   r   r   r	   del_listenerA   s   zEventManager.del_listenerc                 O   s4   | j |t }|D ]}||g|R i | q
dS )aA  Run all the handlers for a given event name.

        :param event_name: The event identifier, indicated by the documentation.
                           Usually, this is a string.
        :param ctx: The method context. Event-related data is conventionally
                        stored in ctx.event attribute.
        N)r   r   r   )r   r   ctxargskwargsr   r   r   r   r	   
fire_eventH   s   	zEventManager.fire_eventr   )__name__
__module____qualname____doc__r
   r   r   r   r   r   r   r	   r      s    
r   N)spyne.util.osetr   objectr   r   r   r   r	   <module>   s   