Your IP : 3.15.203.195


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.opt-1.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�xFt|�D]:\}}yt|�Wq
tk
rBtd||f��Yq
Xq
WxF|j�D]:\}}yt|�WqRtk
r�td||f��YqRXqRWt|t�s�t|�}||_||_||_||_	d|_
dS)Nz*Positional argument %d is not hashable: %rz'Keyword argument %r is not hashable: %r)�	enumerate�hashr
�items�
isinstance�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
r5ns

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 r2r4r6r5r9r	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;r>)rr	r	r
�_get_hooks_enabled�s
zHookable._get_hooks_enabledcCs
||_dS)N)r>)rZenabledr	r	r
�_set_hooks_enabled�szHookable._set_hooks_enabledcCst|d�sd|_|jS)N�__hooks_frozen__F)r;rA)rr	r	r
�_get_hooks_frozen�s
zHookable._get_hooks_frozencCsB||jkrdS||_|r"t�|_nx|jD]}|j�q*W|`dS)N)�hooks_frozenrAr<�__hooks_frozen_entries__r9)rZfreeze�	hookentryr	r	r
�_set_hooks_frozen�s

zHookable._set_hooks_frozencCs
d|_dS)NT)rC)rr	r	r
�freeze_hooks�szHookable.freeze_hookscCs
d|_dS)NF)rC)rr	r	r
�
thaw_hooks�szHookable.thaw_hookscOs|j|df|�|�dS)N)�_Hookable__add_hook)rr-r.r/r	r	r
�add_hook�szHookable.add_hookcOs|j||f|�|�dS)N)rI)rr-r.r/r	r	r
�add_hook_hookable�szHookable.add_hook_hookablecOs t||||d�}|jj|�dS)N)r0)r"r=�add)rr-Z	_hookabler.r/rEr	r	r
Z
__add_hook�szHookable.__add_hookcOs|jjt|||��dS)N)r=�remover")rr-r.r/r	r	r
�remove_hook�szHookable.remove_hookcCs8|jr4|js&x&|jD]}|j�qWn|jj|j�dS)N)�
hooks_enabledrCr=r9rD�update)rrEr	r	r
r�s
zHookable._run_hooksN)rrr �__doc__�propertyr=r?r@rOrBrFrCrGrHrJrKrIrNrr	r	r	r
r|s

c	@seZdZdZdZdd�Zd
S)rz5A set object which calls registered hooks on changes.rL�clear�difference_update�discard�intersection_update�poprM�symmetric_difference_updaterPcCstj|�}t�|_|S)N)r<�copyr:)rr3r	r	r
rY�s
zHookableSet.copyN)	rLrSrTrUrVrWrMrXrP)rrr rQrrYr	r	r	r
r�s)rQ�collectionsZsixr�__all__rr�objectr"rr<rr	r	r	r
�<module>s":G

?>