3
AAd]s  ã               @   sH   d dl mZmZmZmZmZ ddlmZ ddlm	Z	 G dd„ deƒZ
dS )é    )ÚAnyÚBoolÚ	HasTraitsÚInstanceÚListé   )Úget_permissions_manager)Ú
Permissionc               @   s�   e Zd ZdZeZeeeƒƒZ	e
Ze
Ze
Zi Zedd„ ƒZe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d„ Zdd„ ZdS )ÚAdapterBasez4This is the base class for object specific adapters.c             G   s   x|D ]}|| j |< qW dS )z6Register an adapter type for one or more object types.N)Ú_adapter_types)ÚclsÚadapterÚtypesÚt© r   ú}/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/apptools-4.4.0-py3.6.egg/apptools/permissions/adapter_base.pyÚregister_adapter/   s    
zAdapterBase.register_adapterc             C   sX   x2t | jjƒ ƒD ]\}}t||ƒrP qW td| ƒ‚||||d�}tƒ jj|jdƒ |S )zËReturn an adapter for the proxied object.  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.
        z(no SecureProxy adapter registered for %s)ÚproxiedÚpermissionsÚshowZuser_authenticated)	Úlistr   ÚitemsÚ
isinstanceÚ	TypeErrorr   Zuser_managerZon_trait_eventÚ_refresh)r   r   r   r   Zobject_typeZadapter_typer   r   r   r   Úfactory6   s    
zAdapterBase.factoryc             C   s   dS )z”Try and adapt the proxied object and return the adapted object if
        successful.  If None is returned a proxy wrapper will be created.
        Nr   )Úselfr   r   r   ÚadaptN   s    zAdapterBase.adaptc             C   s   t | j||ƒ dS )zVThe default implementation to set an attribute of the proxied
        object.
        N)Úsetattrr   )r   ÚnameÚvaluer   r   r   r   U   s    zAdapterBase.setattrc             C   s   t ‚dS )z,Get the enabled state of the proxied object.N)ÚNotImplementedError)r   r   r   r   Úget_enabled\   s    zAdapterBase.get_enabledc             C   s   t ‚dS )z,Set the enabled state of the proxied object.N)r!   )r   r    r   r   r   Úset_enableda   s    zAdapterBase.set_enabledc             C   sP   t ƒ j| jŽ r,| j|ƒ | jsF| j| jƒ n| jdƒ | jsF| jdƒ || _dS )z_Update the proxied object after a possible new value of the enabled
        attribute.
        FN)r   Úcheck_permissionsr   r#   r   Úset_visibleÚ_desired_visibleÚ_desired_enabled)r   r    r   r   r   Úupdate_enabledf   s    


zAdapterBase.update_enabledc             C   s   t ‚dS )z,Get the visible state of the proxied object.N)r!   )r   r   r   r   Úget_visiblez   s    zAdapterBase.get_visiblec             C   s   t ‚dS )z,Set the visible state of the proxied object.N)r!   )r   r    r   r   r   r%      s    zAdapterBase.set_visiblec             C   s@   | j r| j|ƒ n$tƒ j| jŽ r,| j|ƒ n
| jdƒ || _dS )z_Update the proxied object after a possible new value of the visible
        attribute.
        FN)r   r%   r   r$   r   r&   )r   r    r   r   r   Úupdate_visible„   s    
zAdapterBase.update_visiblec             C   s"   | j s| j| jƒ | j| jƒ dS )z@Invoked whenever the current user's authorisation state changes.N)r   r*   r&   r(   r'   )r   Úuserr   r   r   r   ”   s    zAdapterBase._refreshN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r	   r   r   r   r'   r&   r   Úclassmethodr   r   r   r   r"   r#   r(   r)   r%   r*   r   r   r   r   r   r
      s$   r
   N)Z
traits.apir   r   r   r   r   Zpackage_globalsr   Z
permissionr	   r
   r   r   r   r   Ú<module>   s   