
    i                    X    d Z ddlmZ ddlmZmZmZ ddgZ G d d      Z G d d      Z	y)	a  
Dirt Simple Events

A Dispatcher (or a subclass of Dispatcher) stores event handlers that
are 'fired' simple event objects when interesting things happen.

Create a dispatcher:

  >>> d = Dispatcher()

Now create a handler for the event and subscribe it to the dispatcher
to handle Event events.  A handler is a simple function or method that
accepts the event as an argument:

  >>> def handler1(event): print(repr(event))
  >>> d.subscribe(Event, handler1) # doctest: +ELLIPSIS
  <rdflib.events.Dispatcher object at ...>

Now dispatch a new event into the dispatcher, and see handler1 get
fired:

  >>> d.dispatch(Event(foo='bar', data='yours', used_by='the event handlers'))
  <rdflib.events.Event ['data', 'foo', 'used_by']>
    )annotations)AnyDictOptionalEvent
Dispatcherc                      e Zd ZdZd Zd Zy)r   a  
    An event is a container for attributes.  The source of an event
    creates this object, or a subclass, gives it any kind of data that
    the events handlers need to handle the event, and then calls
    notify(event).

    The target of an event registers a function to handle the event it
    is interested with subscribe().  When a sources calls
    notify(event), each subscriber to that event will be called in no
    particular order.
    c                :    | j                   j                  |       y N)__dict__update)selfkws     <C:\Projects\mas-dev\.venv\Lib\site-packages\rdflib/events.py__init__zEvent.__init__.   s    R     c                z    t        | j                  j                               }d|D cg c]  }| c}dS c c}w )Nz<rdflib.events.Event >)sortedr   keys)r   attrsas      r   __repr__zEvent.__repr__1   s4    t}}))+,9>-?Aa-?AA-?s   	8N)__name__
__module____qualname____doc__r   r    r   r   r   r   !   s    
!Br   c                  :    e Zd ZU dZdZded<   d	dZd Zd Zd Z	y)
r   z]
    An object that can dispatch events to a privately managed group of
    subscribers.
    NzOptional[Dict[Any, Any]]_dispatch_mapc                    || _         | S r   r    )r   amaps     r   set_mapzDispatcher.set_map>   s    !r   c                    | j                   S r   r"   )r   s    r   get_mapzDispatcher.get_mapB   s    !!!r   c                    | j                   | j                  i        | j                   j                  |d      }||g}n|j                  |       || j                   |<   | S )zuSubscribe the given handler to an event_type.  Handlers
        are called in the order they are subscribed.
        N)r    r$   getappend)r   
event_typehandlerlsts       r   	subscribezDispatcher.subscribeE   sa     %LL  $$Z6;)CJJw),:&r   c                    | j                   N| j                   j                  t        |      d      }|t        dt        |      z        |D ]
  } ||        yy)zPDispatch the given event to the subscribed handlers for
        the event's typeNzunknown event type: %s)r    r(   type
ValueError)r   eventr,   l_s       r   dispatchzDispatcher.dispatchU   s\     )$$((ed;C{ !9DK!GHH5	 	 *r   )r#   zDict[Any, Any])
r   r   r   r   r    __annotations__r$   r&   r-   r3   r   r   r   r   r   6   s(    
 /3M+2" r   N)
r   
__future__r   typingr   r   r   __all__r   r   r   r   r   <module>r8      s5   2 # & &L
!B B*' 'r   