U
    k&p[	                     @   s(   d Z G dd deZG dd deZdS )a  Hooks with callbacks.

In order to de-couple parts of the application, especially when plugins
are used, hooks can be used. A hook is a location in the application
code where plugins may want to do something. Each hook has a name and
a list of callbacks. The application defines the name and the location
where the hook will be invoked, and the plugins (or other parts of the
application) will register callbacks.

c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )HookzA hook.c                 C   s
   g | _ d S N	callbacks)self r   -/usr/lib/python3/dist-packages/cliapp/hook.py__init__"   s    zHook.__init__c                 C   s   || j kr| j | |S )znAdd a callback to this hook.

        Return an identifier that can be used to remove this callback.

        )r   append)r   callbackr   r   r   add_callback%   s    
zHook.add_callbackc                 O   s   | j D ]}||| qdS )z,Call all callbacks with the given arguments.Nr   )r   argskwargsr
   r   r   r   call_callbacks0   s    
zHook.call_callbacksc                 C   s   || j kr| j | dS )zRemove a specific callback.N)r   remove)r   Zcallback_idr   r   r   remove_callback5   s    
zHook.remove_callbackN)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r      s
   r   c                   @   s   e Zd ZdZdd ZdS )
FilterHookaV  A hook which filters data through callbacks.

    Every hook of this type accepts a piece of data as its first argument
    Each callback gets the return value of the previous one as its
    argument. The caller gets the value of the final callback.

    Other arguments (with or without keywords) are passed as-is to
    each callback.

    c                 O   s    | j D ]}||f||}q|S r   r   )r   datar   r   r
   r   r   r   r   H   s    
zFilterHook.call_callbacksN)r   r   r   r   r   r   r   r   r   r   ;   s   r   N)r   objectr   r   r   r   r   r   <module>   s   