3
AAd]W  ã               @   sŽ   d dl mZ d dlmZ ddlmZ ddlmZ ddlm	Z	 ej
dkrTddlmZ nej
d	krjdd
lmZ G dd„ deƒZG dd„ deƒZdS )é    )Ú	ETSConfig)ÚHandleré   )ÚAdapterBase)Úget_permissions_manager)Úpyface_actionÚwx)Ú	wx_windowZqt4)Ú
qt4_widgetc            K   @   sþ   e Zd ZdZdcZdddd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]gKZed^d_„ ƒZded`da„ZdbS )fÚSecureProxya`  The SecureProxy class is a wrapper for an object whose enabled and
    visible states can be managed.  It attaches one or more permissions to the
    object and enables and shows the object only if those permissions allow it.
    In all other respects it behaves exactly like the object.  It is based on
    Tomer Filiba's Object Proxy cookbook recipe.Ú_etsÚ__weakref__Tc             C   s0   t j| dƒ}|s|j|jƒ ƒ |j|jƒ ƒ dS )a6  Initialise the instance.  proxied is the object whose enabled and
        visible states are managed according to the permissions of the current
        user.  permissions is a list of permissions to attach to the object.
        show is set if the proxied object should be visible when it is
        disabled.r   N)ÚobjectÚ__getattribute__Úupdate_visibleÚget_visibleÚupdate_enabledÚget_enabled)ÚselfÚproxiedÚpermissionsÚshowÚadapter© r   ú}/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/apptools-4.4.0-py3.6.egg/apptools/permissions/secure_proxy.pyÚ__init__+   s    zSecureProxy.__init__c             C   s   t tj| dƒj|ƒS )Nr   )Úgetattrr   r   r   )r   Únamer   r   r   r   ;   s    zSecureProxy.__getattribute__c             C   s   t tj| dƒj|ƒ d S )Nr   )Údelattrr   r   r   )r   r   r   r   r   Ú__delattr__>   s    zSecureProxy.__delattr__c             C   s   t j| dƒj||ƒ d S )Nr   )r   r   Úsetattr)r   r   Úvaluer   r   r   Ú__setattr__A   s    zSecureProxy.__setattr__c             C   s   t tj| dƒjƒS )Nr   )Úboolr   r   r   )r   r   r   r   Ú__bool__D   s    zSecureProxy.__bool__c             C   s   t tj| dƒjƒS )Nr   )Ústrr   r   r   )r   r   r   r   Ú__str__G   s    zSecureProxy.__str__c             C   s   t tj| dƒjƒS )Nr   )Úreprr   r   r   )r   r   r   r   Ú__repr__J   s    zSecureProxy.__repr__Ú__abs__Ú__add__Ú__and__Ú__call__Z__cmp__Z
__coerce__Ú__contains__Ú__delitem__Z__delslice__Ú__div__Ú
__divmod__Ú__eq__Ú	__float__Ú__floordiv__Ú__ge__Ú__getitem__Z__getslice__Ú__gt__Ú__hash__Z__hex__Ú__iadd__Ú__iand__Ú__idiv__Z__idivmod__Ú__ifloordiv__Ú__ilshift__Ú__imod__Ú__imul__Ú__int__Ú
__invert__Ú__ior__Ú__ipow__Ú__irshift__Ú__isub__Ú__iter__Ú__itruediv__Ú__ixor__Ú__le__Ú__len__Ú__long__Ú
__lshift__Ú__lt__Ú__mod__Ú__mul__Ú__ne__Ú__neg__Z__oct__Ú__or__Ú__pos__Ú__pow__Ú__radd__Ú__rand__Ú__rdiv__Ú__rdivmod__Ú
__reduce__Ú__reduce_ex__r(   Ú__reversed__Z__rfloorfiv__Ú__rlshift__Ú__rmod__Ú__rmul__Ú__ror__Ú__rpow__Ú__rrshift__Ú
__rshift__Ú__rsub__Ú__rtruediv__Ú__rxor__Ú__setitem__Z__setslice__Ú__sub__Ú__truediv__Ú__xor__Únextc             C   sX   dd„ }i }x0| j D ]&}t||ƒrt| |ƒ r||ƒ||< qW td| j|jf | f|ƒS )z$Creates a proxy for the given class.c                s   ‡ fdd„}|S )Nc                s   t tj| dƒjˆ ƒ||ŽS )Nr   )r   r   r   r   )r   ÚargsÚkw)r   r   r   Úmethode   s    zASecureProxy._ets_class_proxy.<locals>.make_method.<locals>.methodr   )r   rl   r   )r   r   Úmake_methodd   s    z1SecureProxy._ets_class_proxy.<locals>.make_methodz%s(%s))Ú_special_namesÚhasattrÚtypeÚ__name__)ÚclsÚtheclassrm   Ú	namespacer   r   r   r   Ú_ets_class_proxy`   s    zSecureProxy._ets_class_proxyc       	      C   sÊ   t j|||ƒ}|jƒ }|dkr y| jd }W n tk
rJ   i  | _}Y nX |j}y|| }W n& tk
r„   | j|ƒ ||< }Y nX tj	|ƒ}tj
|d|ƒ n&|s²|j|jƒ ƒ |j|jƒ ƒ ||_|S )z¡Apply a set of permissions to an object.  This may be done by
        creating a proxy or by modifying the object in situ depending on its
        type.
        NÚ
_ets_cacher   )r   ÚfactoryZadaptÚ__dict__ÚKeyErrorrv   Ú	__class__ru   r   Ú__new__r"   r   r   r   r   r   )	rr   r   r   r   r   ZadaptedÚcacheZpclassrs   r   r   r   r{   q   s&    
zSecureProxy.__new__N)r   r   )T)T)rq   Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r   r"   r$   r&   r(   rn   Úclassmethodru   r{   r   r   r   r   r   "   s4   









r   c                   s0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )ÚSecureHandlerzÚThe SecureHandler class is a sub-class of the TraitsUI Handler class
    that ensures that the enabled and visible state of the items of a TraitsUI
    view are updated when the user's authorisation state changes.
    c                s(   t t| ƒjf |Ž tƒ jj| jdƒ dS )zInitialise the object.Zuser_authenticatedN)Úsuperr‚   r   r   Zuser_managerZon_trait_eventÚ_refresh)r   Útraits)rz   r   r   r   £   s    zSecureHandler.__init__c             C   s
   || _ dS )z(Reimplemented to save the UIInfo object.N)Ú_info)r   Úinfor   r   r   Ú	init_info«   s    zSecureHandler.init_infoc             C   s   | j jjƒ  dS )z@Invoked whenever the current user's authorisation state changes.N)r†   ZuiZ_evaluate_when)r   r   r   r   r„   °   s    zSecureHandler._refresh)rq   r}   r~   r   r   rˆ   r„   Ú__classcell__r   r   )rz   r   r‚   �   s   r‚   N)Ztraits.etsconfig.apir   Ztraitsui.apir   Zadapter_baser   Zpackage_globalsr   Zadaptersr   Ztoolkitr	   r
   r   r   r‚   r   r   r   r   Ú<module>   s   

{