U
    ÇZjR  ã                   @   s4   d Z G dd„ dƒZG dd„ deƒZG dd„ dƒZdS )a  
    Events
    ~~~~~~

    Implements C#-Style Events.

    Derived from the original work by Zoran Isailovski:
    http://code.activestate.com/recipes/410686/ - Copyright (c) 2005

    :copyright: (c) 2014-2017 by Nicola Iarocci.
    :license: BSD, see LICENSE for more details.
c                   @   sL   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )Ú
_EventSlotc                 C   s   g | _ || _d S ©N)ÚtargetsÚ__name__)ÚselfÚname© r   úP/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/events/events.pyÚ__init__   s    z_EventSlot.__init__c                 C   s
   d| j  S )Nz
event '%s')r   ©r   r   r   r   Ú__repr__   s    z_EventSlot.__repr__c                 O   s   t | jƒD ]}|||Ž q
d S r   )Útupler   )r   ÚaÚkwÚfr   r   r   Ú__call__   s    z_EventSlot.__call__c                 C   s   | j  |¡ | S r   )r   Úappend©r   r   r   r   r   Ú__iadd__   s    z_EventSlot.__iadd__c                 C   s   || j kr| j  |¡ q | S r   )r   Úremover   r   r   r   Ú__isub__!   s    
z_EventSlot.__isub__c                 C   s
   t | jƒS r   )Úlenr   r
   r   r   r   Ú__len__&   s    z_EventSlot.__len__c                    s   ‡ fdd„}|ƒ S )Nc                  3   s   ˆ j D ]
} | V  qd S r   ©r   )Útargetr
   r   r   Úgen*   s    
z _EventSlot.__iter__.<locals>.genr   ©r   r   r   r
   r   Ú__iter__)   s    z_EventSlot.__iter__c                 C   s
   | j | S r   r   )r   Úkeyr   r   r   Ú__getitem__/   s    z_EventSlot.__getitem__N)r   Ú
__module__Ú__qualname__r	   r   r   r   r   r   r   r   r   r   r   r   r      s   r   c                   @   s   e Zd ZdS )ÚEventsExceptionN)r   r   r    r   r   r   r   r!   3   s   r!   c                   @   sJ   e Zd ZdZdefdd„Zdd„ Zdd„ Zd	d
„ ZeZ	dd„ Z
dd„ ZdS )ÚEventsa  
    Encapsulates the core to event subscription and event firing, and feels
    like a "natural" part of the language.

    The class Events is there mainly for 3 reasons:

        - Events (Slots) are added automatically, so there is no need to
        declare/create them separately. This is great for prototyping. (Note
        that `__events__` is optional and should primarilly help detect
        misspelled event names.)
        - To provide (and encapsulate) some level of introspection.
        - To "steel the name" and hereby remove unneeded redundancy in a call
        like:

            xxx.OnChange = event('OnChange')
    Nc                 C   sH   || _ |d k	rDz|D ]} qqW n   tdt|ƒ ƒ‚Y nX || _d S )Nztype object %s is not iterable)Ú__event_slot_cls__ÚAttributeErrorÚtypeÚ
__events__)r   ÚeventsZevent_slot_clsÚ_r   r   r   r	   H   s    
ÿzEvents.__init__c                 C   s|   |  d¡rtd| jj|f ƒ‚t| dƒr@|| jkrdtd| ƒ‚n$t| jdƒrd|| jjkrdtd| ƒ‚|  |¡ | j|< }|S )NÚ__z&type object '%s' has no attribute '%s'r&   zEvent '%s' is not declared)	Ú
startswithr$   Ú	__class__r   Úhasattrr&   r!   r#   Ú__dict__)r   r   Zevr   r   r   Ú__getattr__V   s    

ÿ

zEvents.__getattr__c                 C   s
   | j | S r   )r-   )r   Úitemr   r   r   r   f   s    zEvents.__getitem__c                 C   s   d| j j| j jtt| ƒƒf S )Nz<%s.%s object at %s>)r+   r   r   ÚhexÚidr
   r   r   r   r   i   s    
þzEvents.__repr__c                 C   s   t t|  ¡ ƒƒS r   )r   Úlistr   r
   r   r   r   r   p   s    zEvents.__len__c                    s   ˆ j  ¡ f‡ fdd„	}|ƒ S )Nc                 3   s$   | D ]\}}t |ˆ jƒr|V  qd S r   )Ú
isinstancer#   )Ú	dictitemsÚattrÚvalr
   r   r   r   t   s    zEvents.__iter__.<locals>.gen)r-   Úitemsr   r   r
   r   r   s   s    zEvents.__iter__)r   r   r    Ú__doc__r   r	   r.   r   r   Ú__str__r   r   r   r   r   r   r"   7   s   r"   N)r8   r   Ú	Exceptionr!   r"   r   r   r   r   Ú<module>   s   "