Your IP : 3.22.41.80


Current Path : /usr/lib/python3.6/site-packages/slip/util/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/slip/util/__pycache__/hookable.cpython-36.pyc

3

�uAc^�@sldZddlZddlmZddgZGdd�de�ZGdd	�d	e�ZGd
d�deee��Z	Gdd�de
e	�ZdS)z[This module contains variants of certain base types which call registered
hooks on changes.�N)�with_metaclass�Hookable�HookableSetc@s eZdZdd�Zedd��ZdS)�HookableTypec
Cs�d|kr�y|d}WnJtk
r^d}x0dd�|D�D]}|rRtdt|���q8|}q8WYnXx |dD]}tj||�||<qjWtj||||�S)N�_hookable_change_methodsZ_hookable_base_classcss|]}|tkr|VqdS)N)r)�.0�x�r	�/usr/lib/python3.6/hookable.py�	<genexpr>)sz'HookableType.__new__.<locals>.<genexpr>ztoo many base classes: %s)�KeyError�	TypeError�strr�wrap_method�type�__new__)�cls�name�basesZdct�baseZbase_candidate�
methodnamer	r	r
r"szHookableType.__new__cs t||���fdd�}||_|S)Ncs�|f|�|�}|j�|S)N)�
_run_hooks)�self�p�kZretval)�funcr	r
�
methodwrapper9sz/HookableType.wrap_method.<locals>.methodwrapper)�getattr�__name__)rrrrr	)rr
r5s
zHookableType.wrap_methodN)r�
__module__�__qualname__r�classmethodrr	r	r	r
r src@s6eZdZddd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�
_HookEntryNcCs�t|tj�st�t|t�st�xFt|�D]:\}}yt|�Wq(tk
r`td||f��Yq(Xq(WxF|j�D]:\}}yt|�Wqptk
r�td||f��YqpXqpWt|t	�s�t	|�}||_
||_||_||_
d|_dS)Nz*Positional argument %d is not hashable: %rz'Keyword argument %r is not hashable: %r)�
isinstance�collections�Callable�AssertionErrorr�	enumerate�hashr
�items�tuple�_HookEntry__hook�_HookEntry__args�_HookEntry__kwargs�_HookEntry__hookable�_HookEntry__hash)r�hook�args�kwargs�hookable�nrrr	r	r
�__init__Ds.
z_HookEntry.__init__cCs$|j|jko"|j|jko"|j|jkS)N)r+r,r-)r�objr	r	r
�__cmp__csz_HookEntry.__cmp__cCs|js|j�|_|jS)N)r/�
_compute_hash)rr	r	r
�__hash__is
z_HookEntry.__hash__cCs>t|j�}t|�t|j�A}t|�ttt|jj����A}|S)N)r(r+r,r*�sortedr-r))r�	hashvaluer	r	r
r8ns

z_HookEntry._compute_hashcCs4|jr |j|jf|j�|j�n|j|j|j�dS)N)r.r+r,r-)rr	r	r
�runusz_HookEntry.run)N)rrr r5r7r9r8r<r	r	r	r
r"Bs

r"c@s�eZdZdZedd��Zdd�Zdd�Zeee�Zdd	�Z	d
d�Z
ee	e
�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)rz2An object which calls registered hooks on changes.cOst|d�st�|_|jS)N�__real_hooks__)�hasattr�setr=)rrrr	r	r
�	__hooks__�s
zHookable.__hooks__cCst|d�sd|_|jS)N�__hooks_enabled__T)r>rA)rr	r	r
�_get_hooks_enabled�s
zHookable._get_hooks_enabledcCs
||_dS)N)rA)rZenabledr	r	r
�_set_hooks_enabled�szHookable._set_hooks_enabledcCst|d�sd|_|jS)N�__hooks_frozen__F)r>rD)rr	r	r
�_get_hooks_frozen�s
zHookable._get_hooks_frozencCsB||jkrdS||_|r"t�|_nx|jD]}|j�q*W|`dS)N)�hooks_frozenrDr?�__hooks_frozen_entries__r<)rZfreeze�	hookentryr	r	r
�_set_hooks_frozen�s

zHookable._set_hooks_frozencCs
d|_dS)NT)rF)rr	r	r
�freeze_hooks�szHookable.freeze_hookscCs
d|_dS)NF)rF)rr	r	r
�
thaw_hooks�szHookable.thaw_hookscOs|j|df|�|�dS)N)�_Hookable__add_hook)rr0r1r2r	r	r
�add_hook�szHookable.add_hookcOs|j||f|�|�dS)N)rL)rr0r1r2r	r	r
�add_hook_hookable�szHookable.add_hook_hookablecOs>t|tj�st�t|t�st�t||||d�}|jj|�dS)N)r3)r#r$r%r&rr"r@�add)rr0Z	_hookabler1r2rHr	r	r
Z
__add_hook�szHookable.__add_hookcOs|jjt|||��dS)N)r@�remover")rr0r1r2r	r	r
�remove_hook�szHookable.remove_hookcCs8|jr4|js&x&|jD]}|j�qWn|jj|j�dS)N)�
hooks_enabledrFr@r<rG�update)rrHr	r	r
r�s
zHookable._run_hooksN)rrr �__doc__�propertyr@rBrCrRrErIrFrJrKrMrNrLrQrr	r	r	r
r|s

c	@seZdZdZdZdd�Zd
S)rz5A set object which calls registered hooks on changes.rO�clear�difference_update�discard�intersection_update�poprP�symmetric_difference_updaterScCstj|�}t�|_|S)N)r?�copyr=)rr6r	r	r
r\�s
zHookableSet.copyN)	rOrVrWrXrYrZrPr[rS)rrr rTrr\r	r	r	r
r�s)rTr$Zsixr�__all__rr�objectr"rr?rr	r	r	r
�<module>s":G

?>