o
    ¹iž
  ã                   @  sL   d dl mZ dZd dlmZmZmZ ddgZG dd„ dƒZG dd„ dƒZ	dS )	é    )ÚannotationsaÚ  
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']>
)ÚAnyÚDictÚOptionalÚEventÚ
Dispatcherc                   @  s    e Zd ZdZdd„ Zdd„ ZdS )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                 K  s   | j  |¡ d S ©N)Ú__dict__Úupdate)ÚselfÚkw© r   úH/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/rdflib/events.pyÚ__init__/   s   zEvent.__init__c                 C  s"   t | j ¡ ƒ}ddd„ |D ƒf S )Nz<rdflib.events.Event %s>c                 S  s   g | ]}|‘qS r   r   )Ú.0Úar   r   r   Ú
<listcomp>4   s    z"Event.__repr__.<locals>.<listcomp>)Úsortedr	   Úkeys)r   Úattrsr   r   r   Ú__repr__2   s   zEvent.__repr__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   "   s    c                   @  s@   e Zd ZU dZdZded< ddd„Zd	d
„ Zdd„ Zdd„ Z	dS )r   z]
    An object that can dispatch events to a privately managed group of
    subscribers.
    NzOptional[Dict[Any, Any]]Ú_dispatch_mapÚamapúDict[Any, Any]c                 C  s
   || _ | S r   ©r   )r   r   r   r   r   Úset_map?   s   zDispatcher.set_mapc                 C  s   | j S r   r   )r   r   r   r   Úget_mapC   s   zDispatcher.get_mapc                 C  sJ   | j du r
|  i ¡ | j  |d¡}|du r|g}n| |¡ || 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Úlstr   r   r   Ú	subscribeF   s   



zDispatcher.subscribec                 C  sN   | j dur#| j  t|ƒd¡}|du rtdt|ƒ ƒ‚|D ]}||ƒ qdS dS )zPDispatch the given event to the subscribed handlers for
        the event's typeNzunknown event type: %s)r   r!   ÚtypeÚ
ValueError)r   Úeventr%   Úl_r   r   r   ÚdispatchT   s   

ûzDispatcher.dispatch)r   r   )
r   r   r   r   r   Ú__annotations__r   r    r&   r+   r   r   r   r   r   7   s   
 
N)
Ú
__future__r   r   Útypingr   r   r   Ú__all__r   r   r   r   r   r   Ú<module>   s    