3
:Ad]H ã               @   sö  d Z ddlmZmZmZ ddlZddlZddlZddl	m
Z
mZ ddlZddlmZ ddlmZ ddlmZma dd	lmZmZmZmZmZmZmZmZmZ dd
lm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& ddl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/m0Z0m1Z1m2Z2 ddl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z; ddl<m=Z= ddl>m?Z? dZ@G dd„ deAƒZBdd„ ZCe+e,fZDejE�rrefZFefZGnefZFe
fZGe
fZHdZIdZJdZKdZLdZMdZNdZOdvZPg ZQdwZRejSdƒZTe ƒ jUƒ ZVdxd d!„ZWd"d#„ ZXd$d%„ ZYd&d'„ ZZd(d)„ Z[d*d+„ Z\d,d-„ Z]d.d/„ Z^d0d1„ Z_d2d3„ Z`G d4d5„ d5ƒZad6d7„ Zbd8d9„ Zcd:d;„ Zdd<d=„ Zed>d?„ Zfd@dA„ ZgdZhG dBdC„ dCeiƒZjdDdE„ ZkdFdG„ ZldHdI„ ZmdydLdM„ZndNdO„ ZodzdPdQ„ZpdRdS„ ZqejrejƒG dTdU„ dUeƒƒZsesZhG dVdW„ dWesƒZtG dXdY„ dYetƒZuG dZd[„ d[esƒZvyJddlwZwG d\d]„ d]ewjxejƒZyejreyƒG d^d_„ d_esƒƒZzG d`da„ daezƒZ{W n e|k
�rN   Y nX G dbdc„ dcesƒZ}G ddde„ deetƒZ~G dfdg„ dgevƒZG dhdi„ dietƒZ€e$e€ƒZ�G djdk„ dkeyƒZ‚ejre‚ƒG dldm„ dmesƒƒZƒdndo„ Z„dpdq„ Z…G drds„ dseƒƒZ†G dtdu„ due‡ƒZˆdS ){zc Defines the HasTraits class, along with several useful subclasses and
    associated metaclasses.
é    )Úabsolute_importÚdivisionÚprint_functionN)ÚFunctionTypeÚ
MethodTypeé   )Ú__version__)ÚAdaptationError)Ú
CHasTraitsÚ_HasTraits_monitors)	ÚCTraitÚForwardPropertyÚPropertyÚSpecialNamesÚTraitÚTraitFactoryÚ
__newobj__Úgeneric_traitÚtrait_factory)ÚAnyÚBoolÚDisallowÚEnumÚEventÚPythonÚThis)Ú ExtendedTraitChangeNotifyWrapperÚFastUITraitChangeNotifyWrapperÚNewTraitChangeNotifyWrapperÚ!StaticAnyTraitChangeNotifyWrapperÚStaticTraitChangeNotifyWrapperÚTraitChangeNotifyWrapper)Ú	TraitTypeÚMISSING_DEFAULT_VALUEÚTRAIT_LIST_OBJECT_DEFAULT_VALUEÚCALLABLE_DEFAULT_VALUE)ÚMissingÚSequenceTypesÚTraitsCacheÚ	UndefinedÚadd_articleÚis_noneÚ	not_eventÚ	not_false)Ú
TraitError)Ú
deprecatedc               @   s   e Zd ZdS )ÚViewElementN)Ú__name__Ú
__module__Ú__qualname__© r4   r4   úx/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/traits-5.1.2-py3.6-linux-x86_64.egg/traits/has_traits.pyr0   r   s   r0   c               C   s   d S )Nr4   r4   r4   r4   r5   ÚViewElementsv   s    r6   Ú__base_traits__Ú__class_traits__Ú__prefix_traits__Ú__listener_traits__Z__view_traits__Ú__instance_traits__Ztraits_viewÚeventÚdelegateÚconstantÚpropertyz.*[ :\+\-,\.\*\?\[\]]c             C   s@   t dƒ}|j| ƒ | jdk	r(| jjƒ |_|dk	r<|jj|ƒ |S )z+ Creates a clone of a specified trait.
    r   N)r   ÚcloneÚ__dict__ÚcopyÚupdate)r@   ÚmetadataÚtraitr4   r4   r5   Ú_clone_trait¯   s    

rF   c             C   s$   t | |d ƒ}|d k	r t|ƒr |S d S )N)ÚgetattrÚis_unbound_method_type)ÚclsÚmethodÚresultr4   r4   r5   Ú_get_methodÃ   s    rL   c             C   sŽ   |dd… dkrd| |f }|j |ƒ}|dk	rJt|ƒrJt|ddƒdkrJ|S x>|D ]6}t||dƒ}|dk	rPt|ƒrPttjddƒdkrP|S qPW dS )z9 Gets the definition of a specified method (if any).
    r   é   Ú__z_%s%sNÚon_trait_change)ÚgetÚis_function_typerG   rH   ÚsixÚget_unbound_function)Ú
class_nameÚ
class_dictÚbasesrJ   rK   Úbaser4   r4   r5   Ú_get_defÊ   s    

rX   c             C   s   dt t| ƒƒkS )z9 Test if the given input is a Cython method or function. Úcython_function_or_method)ÚstrÚtype)rJ   r4   r4   r5   Úis_cython_func_or_methodç   s    r\   c             C   s   t | tƒpt| ƒS )z@ Test if the given input is a Python method or a Cython method. )Ú
isinstanceÚBoundMethodTypesr\   )rJ   r4   r4   r5   Úis_bound_method_typeí   s    r_   c             C   s   t | tƒpt| ƒS )z@ Test if the given input is a Python method or a Cython method. )r]   ÚUnboundMethodTypesr\   )rJ   r4   r4   r5   rH   ô   s    rH   c             C   s   t | tƒpt| ƒS )zB Test if the given input is a Python function or a Cython method. )r]   ÚFunctionTypesr\   )Úfunctionr4   r4   r5   rQ   û   s    rQ   c             C   s~   t | ttfƒr,x| D ]}t|ƒsdS qW dS t | tƒrhx,| jƒ D ] \}}t|ƒ s\t|ƒ r@dS q@W dS t | tƒ p|| jtƒS )z? Returns whether or not a specified value is serializable.
    FT)	r]   ÚlistÚtupleÚ_is_serializableÚdictÚitemsÚ	HasTraitsÚhas_traits_interfaceÚISerializable)ÚvalueÚitemÚnamer4   r4   r5   re     s    

re   c             C   s  i }xn|D ]f}x`|j jtƒjƒ D ]L\}}|j|ƒ}|dkrL|dd… ||< q x|D ]}||krR|j|ƒ qRW q W q
W xž| jƒ D ]’\}}|dd… dkoœt|ƒr~d}	|jdƒ}
|
dk rÂd}	|jdƒ}
|
dkr~||
|	 d… }|d	kr~||d|
… f}|j|g ƒ}||kr~|j|ƒ q~W |S )
zX Returns a dictionary of potential 'Instance' or 'List(Instance)'
        handlers.
    Nr   Ú_é   Z_changed_for_rM   é   Z_fired_for_Ú )rA   rP   ÚInstanceTraitsrg   ÚappendrQ   ÚfindÚ
setdefault)rU   rV   Úinstance_traitsrW   rm   Zbase_arg_listsÚ	arg_listsÚarg_listrk   ÚnÚcolÚkeyr4   r4   r5   Ú_get_instance_handlers"  s0    




r|   c             C   sJ   |j }|dkr| }n(t|ƒdkr<|d dkr<|dd… |  }d|j|f S )zf Returns the correct 'delegate' listener pattern for a specified name and
        delegate trait.
    rq   r   Ú*Nz %s:%séÿÿÿÿr~   )Ú_prefixÚlenZ	_delegate)rm   rE   Úprefixr4   r4   r5   Úget_delegate_patternN  s    r‚   c               @   s   e Zd Zdd„ Zdd„ ZdS )Ú_SimpleTestc             C   s
   || _ d S )N)rk   )Úselfrk   r4   r4   r5   Ú__init__a  s    z_SimpleTest.__init__c             C   s
   || j kS )N)rk   )r„   Útestr4   r4   r5   Ú__call__d  s    z_SimpleTest.__call__N)r1   r2   r3   r…   r‡   r4   r4   r4   r5   rƒ   `  s   rƒ   c             C   sP   t | tƒr| S t | tƒr t| ƒS t | tƒr:t| tƒr:| ƒ } t | tƒrL| jƒ S | S )zl Returns either the original value or a valid CTrait if the value can be
        converted to a CTrait.
    )r]   r   r   r   r[   Ú
issubclassr"   Ú	as_ctrait)rE   r4   r4   r5   Ú_check_traitn  s    


rŠ   c             C   s   t | ƒ} t| tƒr| S t| ƒS )z; Returns the trait corresponding to a specified value.
    )rŠ   r]   r   r   )rE   r4   r4   r5   Ú
_trait_for†  s    
r‹   c             C   s>   | j ƒ d }y| jj|ƒ}W n   Y nX t|dddd�jƒ S )z? Returns the 'mapped trait' definition for a mapped trait.
    r   FT)Úis_baseÚ	transientÚeditable)Údefault_valueÚhandlerZmapped_valuer   r‰   )rE   r�   r4   r4   r5   Ú_mapped_trait_for•  s    r‘   c             C   s.   x(|D ] }t |tƒst|ƒ}| j|ƒ qW dS )z< Adds a list of handlers to a specified notifiers list.
    N)r]   ÚWrapperTypesr    rs   )Ú	notifiersÚhandlersr�   r4   r4   r5   Ú_add_notifiers¨  s    

r•   c             C   sZ   | j }|dk	rVt|tjƒr |g}x4|D ],}|jt|d| ƒƒ |jt|d| ƒƒ q&W dS )zG Adds any specified event handlers defined for a trait by a class.
    Nz_%s_changedz	_%s_fired)r<   r]   rR   Ústring_typesrs   rL   )rE   rI   r”   Úeventsr<   r4   r4   r5   Ú_add_event_handlers¶  s    
r˜   c             C   s
   | j |ƒS )zW Returns the method associated with a particular class property
    getter/setter.
    )rP   )rU   rm   r4   r4   r5   Ú_property_methodÈ  s    r™   c               @   s@   e Zd ZdZi Zdd„ Zd
dd„ZeeƒZddd„ZeeƒZd	S )ÚMetaHasTraitsa—   Controls the creation of HasTraits classes.

    The heavy work is done by the `create_traits_meta_dict` function, which
    takes the ``class_dict`` dictionary of class members and extracts and
    processes the trait declarations in it. The trait declarations are then
    added back to the class dictionary and passed off to the __new__ method
    of the type superclass, to be added to the class.

    c             C   st   t |||dd� tj| |||ƒ}d|j|jf }xtjj|g ƒD ]}||ƒ q@W xtjjdg ƒD ]}||ƒ q`W |S )NF)Úis_categoryz%s.%srq   )Úupdate_traits_class_dictr[   Ú__new__r2   r1   rš   Ú
_listenersrP   )rI   rT   rV   rU   Úklassrm   Úlistenerr4   r4   r5   r�   ç  s    zMetaHasTraits.__new__rq   c             C   s   t jj|g ƒj|ƒ dS )zž Adds a class creation listener.

        If the class name is the empty string then the listener will be called
        when *any* class is created.
        N)rš   rž   ru   rs   )rI   r    rT   r4   r4   r5   Úadd_listenerú  s    zMetaHasTraits.add_listenerc             C   s   t j| j|ƒ dS )z, Removes a class creation listener.
        N)rš   rž   Úremove)rI   r    rT   r4   r4   r5   Úremove_listener  s    zMetaHasTraits.remove_listenerN)rq   )rq   )	r1   r2   r3   Ú__doc__rž   r�   r¡   Úclassmethodr£   r4   r4   r4   r5   rš   ×  s   	

rš   c       /   	   C   s²  i }i }i }i }g }|}	t ƒ }
dd„ |D ƒ}dd„ |D ƒ}�xt|jƒ ƒD �]ð\}}t|ƒ}t|tƒ}| ott|tƒ�rd}t|d| ƒ}t|d| ƒ}|dkrÎ|dk	rÎt|dd	ƒr¼t	j
}nt|d
d	ƒrÎt	j}t|d| ƒ}|dkrê|j}t|||d|jf|jŽ}|�r||= |d*d… dk�rö| ||< ||< |j}|dk�r |j}|dk	�rô|j�r†t|jƒ |jƒ}|jdk�rzd|_|||d < |j�rôt|ƒ||d < nT|dk�rÊ|jd	k	�rôdt||ƒf||< n*|dk�r|j}t|tjƒ�rd|f||< n|dd+… }|j|ƒ |||< qJt|tƒ�s,t|ƒ�rPt|ddƒ}|dk	�r<d|f||< qJt|t ƒ�rft!||< qJt|t"ƒ�r¦||
j#k�rŠt$d| ƒ‚||
j#|< |j%|
ƒ ||= qJx”|D ]Œ}||k�r¬|| }|jt&k�ràt$d|j|f ƒ‚|}||ƒ ||< }|j't(|j)ƒ ||= g }	|j}|dk	�r4|j�r4t|ƒ||d < P �q¬W qJW i }g }�x¸|D �]®}|j}x8|j*t+ƒjƒ D ]&\}}||k�rl||k�rl|||< �qlW xr|j*t,ƒjƒ D ]`\}}||k�rò|j ƒ }|dk	�rèt-|ƒ} t.||||ƒ || < }|||< n|�r¦t$d| ƒ‚�q¦W x€|j*t/ƒjƒ D ]n\}}||k�rt|j ƒ }|dk	�rj|j*t-|ƒƒ}!|!dk	�r\|!}nt.||||ƒ}|||< n|�rt$d| ƒ‚�qW |j*t0ƒ}"xF|"d D ]:}||k�rÆ|j|ƒ |"| ||< n|�r t$d| ƒ‚�q W |j*t1ƒ}#|#dk	�rP|
j2j|#ƒ �qPW |j*dƒdk�r4| �r4|jdƒ t3ƒ j4ƒ |d< ||d< |j5dd„ d� t6||ƒ}$t7| ||dƒ}%|%dk	�r~t8|%ƒ}%|%|d < t9ƒ }&�xöt|j:ƒ ƒD �]ä}|| }'|%t7| ||d!| ƒt7| ||d"| ƒg}(|'j})|)dk	�râ||$k�s|)dk�r |d,d… dk�r |dd-… |$k�r |(jtt	|)ƒƒ |'j;}*|*dk	�r„t|*tjƒ�rD|*g}*x>|*D ]6}+|(jt7| ||d!|+ ƒƒ |(jt7| ||d"|+ ƒƒ �qJW d$d„ |(D ƒ}(t7| |g d%| ƒ},t<|(ƒd&k�s¼|,dk	�r||&k�rà|&j=|ƒ t|'ƒ ||< }'t<|(ƒd&k�rþt>|'j?dƒ|(ƒ |,dk	�r|'j't@|,ƒ |'jd'k�r”|'jAdk	�r”|'jB}-|-dk�rDtC| }-|'jA}.t|.tDƒ�rbd(jE|.ƒ}.nd)|. }.d'|-|.f||< �q”W ||t,< ||t/< |$|tF< ||t0< ||t+< |
|t1< dS ).ad   Processes all of the traits related data in the class dictionary.

    This is called during the construction of a new HasTraits class. The first
    three parameters have the same interpretation as the corresponding
    parameters of ``type.__new__``. This function modifies ``class_dict``
    in-place.

    Parameters
    ----------
    class_name : str or unicode
        The name of the HasTraits class.
    bases : tuple
        The base classes for the HasTraits class.
    class_dict : dict
        A dictionary of class members.
    is_category : bool
        Whether this is a Category subclass.

    c             S   s    g | ]}|j jtƒd k	r|‘qS )N)rA   rP   ÚClassTraits)Ú.0rW   r4   r4   r5   ú
<listcomp>,  s    z,update_traits_class_dict.<locals>.<listcomp>c             S   s   g | ]}|j jtƒ‘qS r4   )rA   rP   r¦   )r§   rW   r4   r4   r5   r¨   1  s    TÚ_get_Ú_set_NÚsettableFÚ	flushableÚ
_validate_r   rn   rE   Ú_list_changed_handlerÚ_list_items_changed_handlerÚ_itemsr=   r<   rO   rJ   z*Duplicate definition for view element '%s'ziCannot specify a default value for the %s trait '%s'. You must override the the trait definition instead.z3Cannot override '%s' trait definition in a categoryr}   z4Cannot override '%s_' trait definition in a categoryrq   c             S   s
   t | ƒ S )N)r€   )Úxr4   r4   r5   Ú<lambda>û  s    z*update_traits_class_dict.<locals>.<lambda>)r{   Z_anytrait_changedú@z_%s_changedz	_%s_firedé   c             S   s   g | ]}|d k	r|‘qS )Nr4   )r§   Úhr4   r4   r5   r¨   6  s    z_%s_defaultr   r?   ú,ú r~   r~   iúÿÿÿiúÿÿÿ)Gr6   rc   rg   rŠ   r]   r   r   r™   rG   rh   Ú_set_traits_cacheÚ_flush_traits_cacheÚvalidater   r�   rD   r[   Ú	has_itemsrF   Úitems_eventrA   Úinstance_handlerÚ	is_mappedr‘   Z_listenabler‚   rO   rR   r–   rs   r   r\   r?   r   r0   Úcontentr.   Zreplace_includeÚCantHaveDefaultValuer�   r#   ÚdefaultrP   ÚListenerTraitsÚ
BaseTraitsÚidÚmigrate_propertyr¦   ÚPrefixTraitsÚ
ViewTraitsÚparentsr   r‰   Úsortr|   rX   r   ÚsetÚkeysr<   r€   Úaddr•   Ú
_notifiersr%   Ú
depends_onÚcachedr(   r'   Újoinrr   )/rT   rV   rU   r›   Úbase_traitsÚclass_traitsÚprefix_traitsÚ	listenersÚprefix_listZoverride_basesÚview_elementsZhastraits_basesZinherited_class_traitsrm   rk   ÚrcÚgetterÚsetterrº   Z
value_typer�   Zitems_traitrO   ÚpatternÚctZictraitr�   Zmigrated_propertiesZ
implementsrW   Z	base_dictÚproperty_infor{   Ú	new_valueZbase_prefix_traitsZparent_view_elementsrv   ÚanytraitZclonedrE   r”   r½   r—   r<   rÁ   rÏ   rÎ   r4   r4   r5   rœ     sx   





































rœ   c       
      C   sp   t |d|  ƒ}t |d|  ƒ}t |d|  ƒ}|dk	sB|dk	sB|dk	rl|\}}}	t|pT||pZ||p`|	df|jŽS |S )zc Migrates an existing property to the class being defined
    (allowing for method overrides).
    r©   rª   r­   NT)r™   r   rA   )
rm   r?   rÜ   rU   rP   rÊ   ÚvalZold_getZold_setZold_valr4   r4   r5   rÅ   `  s    
rÅ   c             C   sx   t |ƒ}xjttƒD ]^\}}}|t |ƒkr|tks<dt|ƒkrd|jd k	rd|j|jkrp|j|jkrp|S q||kr|S qW dS )NrY   r   r~   )r[   Ú	enumerater   r   rZ   Ú__self__r1   )rI   r�   Ztype_handlerÚiÚ_clsZ_handlerr4   r4   r5   Ú_trait_monitor_indexy  s    
rä   FÚsamec                s   ‡ ‡‡fdd„}|S )aÌ   Marks the following method definition as being a handler for the
        extended trait change specified by *name(s)*.

        Refer to the documentation for the on_trait_change() method of
        the **HasTraits** class for information on the correct syntax for
        the *name* argument and the semantics of the *dispatch* keyword
        argument.

        A handler defined using this decorator is normally effective
        immediately. However, if *post_init* is **True**, then the handler only
        becomes effective after all object constructor arguments have been
        processed. That is, trait values assigned as part of object construction
        will not cause the handler to be invoked.
    c                s   ˆˆˆ dœ| _ | S )N)rÚ   Ú	post_initÚdispatch)rO   )rb   )rç   rm   ræ   r4   r5   Ú	decorator£  s    
z"on_trait_change.<locals>.decoratorr4   )rm   ræ   rç   rè   r4   )rç   rm   ræ   r5   rO   “  s    
rO   c                s*   t ˆ jdd…  ‰‡ ‡fdd„}d|_|S )a   Marks the following method definition as being a "cached property".
        That is, it is a property getter which, for performance reasons, caches
        its most recently computed result in an attribute whose name is of the
        form: *_traits_cache_name*, where *name* is the name of the property. A
        method marked as being a cached property needs only to compute and
        return its result. The @cached_property decorator automatically wraps
        the decorated method in cache management code, eliminating the need to
        write boilerplate cache management code explicitly. For example::

            file_name = File
            file_contents = Property( depends_on = 'file_name' )

            @cached_property
            def _get_file_contents(self):
                fh = open(self.file_name, 'rb')
                result = fh.read()
                fh.close()
                return result

        In this example, accessing the *file_contents* trait calls the
        _get_file_contents() method only once each time after the **file_name**
        trait is modified. In all other cases, the cached value
        **_file_contents**, which maintained by the @cached_property wrapper
        code, is returned.

        Note the use, in the example, of the **depends_on** metadata attribute
        to specify that the value of **file_contents** depends on **file_name**,
        so that _get_file_contents() is called only when **file_name** changes.
        For details, see the traits.traits.Property() function.
    é   Nc                s,   | j jˆtƒ}|tkr(ˆ | ƒ | j ˆ< }|S )N)rA   rP   r)   )r„   rK   )rb   rm   r4   r5   rè   Ñ  s    z"cached_property.<locals>.decoratorT)r(   r1   Úcached_property)rb   rè   r4   )rb   rm   r5   rê   °  s    rê   c                s   ‡ ‡‡fdd„}|S )a¤   Marks the following method definition as being a "cached property"
        that depends on the specified extended trait names. That is, it is a
        property getter which, for performance reasons, caches its most recently
        computed result in an attribute whose name is of the form:
        *_traits_cache_name*, where *name* is the name of the property. A method
        marked as being a cached property needs only to compute and return its
        result. The @property_depends_on decorator automatically wraps the
        decorated method in cache management code that will cache the most
        recently computed value and flush the cache when any of the specified
        dependencies are modified, thus eliminating the need to write
        boilerplate cache management code explicitly. For example::

            file_name = File
            file_contents = Property

            @property_depends_on( 'file_name' )
            def _get_file_contents(self):
                fh = open(self.file_name, 'rb')
                result = fh.read()
                fh.close()
                return result

        In this example, accessing the *file_contents* trait calls the
        _get_file_contents() method only once each time after the **file_name**
        trait is modified. In all other cases, the cached value
        **_file_contents**, which is maintained by the @cached_property wrapper
        code, is returned.
    c                s<   t ˆ jdd …  ‰‡ ‡fdd„}d|_ˆ|_ˆ|_ˆ|_|S )Nré   c                s,   | j jˆtƒ}|tkr(ˆ | ƒ | j ˆ< }|S )N)rA   rP   r)   )r„   rK   )rb   rm   r4   r5   Úwrapperþ  s    z7property_depends_on.<locals>.decorator.<locals>.wrapperT)r(   r1   rê   rÎ   r«   r¬   )rb   rë   )Ú
dependencyr¬   r«   )rb   rm   r5   rè   û  s    z&property_depends_on.<locals>.decoratorr4   )rì   r«   r¬   rè   r4   )rì   r¬   r«   r5   Úproperty_depends_onÝ  s    rí   c                s   t j| ƒ‰ ‡ fdd„}|S )z½ Create a weak reference to arg and wrap the function so that the
    dereferenced weakref is passed as the first argument. If arg has been
    deleted then the function is not called.
    c                s¤   ‡ ‡fdd„}‡ ‡fdd„}‡ ‡fdd„}‡ ‡fdd„}‡ ‡fd	d
„}‡ ‡fdd„}ˆ j jd }|dkrl|S |dkrx|S |dkr„|S |dkr�|S |dkrœ|S |S d S )Nc                 s   ˆƒ } | d k	rˆ | ƒS d S )Nr4   )Úarg)rb   Úweak_argr4   r5   Úwrapper0  s    z-weak_arg.<locals>.decorator.<locals>.wrapper0c                s   ˆƒ }|d k	rˆ || ƒS d S )Nr4   )Úarg1rî   )rb   rï   r4   r5   Úwrapper1   s    z-weak_arg.<locals>.decorator.<locals>.wrapper1c                s   ˆƒ }|d k	rˆ || |ƒS d S )Nr4   )rñ   Úarg2rî   )rb   rï   r4   r5   Úwrapper2%  s    z-weak_arg.<locals>.decorator.<locals>.wrapper2c                s    ˆƒ }|d k	rˆ || ||ƒS d S )Nr4   )rñ   ró   Úarg3rî   )rb   rï   r4   r5   Úwrapper3*  s    z-weak_arg.<locals>.decorator.<locals>.wrapper3c                s"   ˆƒ }|d k	rˆ || |||ƒS d S )Nr4   )rñ   ró   rõ   Zarg4rî   )rb   rï   r4   r5   Úwrapper4/  s    z-weak_arg.<locals>.decorator.<locals>.wrapper4c                 s    ˆƒ }|d k	rˆ |f| žŽ  d S )Nr4   )Úargsrî   )rb   rï   r4   r5   Úwrappern4  s    z-weak_arg.<locals>.decorator.<locals>.wrappernr   r   rM   é   é   )Ú__code__Úco_argcount)rb   rð   rò   rô   rö   r÷   rù   rø   )rï   )rb   r5   rè     s$    zweak_arg.<locals>.decorator)ÚweakrefÚref)rî   rè   r4   )rï   r5   rï     s    
1rï   c               @   sl  e Zd ZdZeddd�Zeeee	e	dœZ
eejd ƒZeZdd„ Zd¤d	d
„ZeeƒZdd„ ZeeƒZdd„ ZeeƒZdd„ ZeeƒZdd„ ZeeƒZd¥dd„ZeeƒZd¦dd„ZeeƒZdd„ ZeeƒZdd„ Zdd„ Zdd„ Zd§dd „Zd!d"„ Zed#ƒd$d%„ ƒZ eje _d¨d&d'„Z!ed(ƒd©d)d*„ƒZ"e!je"_d+d,„ Z#dªd.d/„Z$d0d1„ Z%d2d3„ Z&d4d5„ Z'd«d6d7„Z(d¬d8d9„Z)d:d;„ Z*d­d=d>„Z+d?d@„ Z,d®dAdB„Z-d¯dCdD„Z.ee.ƒZ.dEdF„ Z/ee/ƒZ/dGdH„ Z0dIdJ„ Z1ee1ƒZ1d°dKdL„Z2dMdN„ Z3dOdP„ Z4ee4ƒZ4d±dQdR„Z5dSdT„ Z6dUdV„ Z7ee7ƒZ7dWdX„ Z8dYdZ„ Z9ee9ƒZ9d²d[d\„Z:d³d^d_„Z;d´d`da„Z<e<Z=dµdbdc„Z>ddde„ Z?dfdg„ Z@dhdi„ ZAdjdk„ ZBdldm„ ZCdndo„ ZDd¶dpdq„ZEdrds„ ZFdtdu„ ZGdvdw„ ZHdxdy„ ZIeeIƒZIdzd{„ ZJd|d}„ ZKeeKƒZKd~d„ ZLd€d�„ ZMd‚dƒ„ ZNd·d„d…„ZOd¸d†d‡„ZPdˆd‰„ ZQdŠd‹„ ZRdŒd�„ ZSdŽd�„ ZTd�d‘„ ZUd’d“„ ZVd”d•„ ZWd–d—„ ZXd˜d™„ ZYdšd›„ ZZdœd�„ Z[dždŸ„ Z\d d¡„ Z]d¢d£„ Z^d-S )¹rh   aÛ   Enables any Python class derived from it to have trait attributes.

    Most of the methods of HasTraits operated by default only on the trait
    attributes explicitly defined in the class definition. They do not operate
    on trait attributes defined by way of wildcards or by calling
    **add_trait()**.
    For example::

        >>>class Person(HasTraits):
        ...    name = Str
        ...    age  = Int
        ...    temp_ = Any
        >>>bob = Person()
        >>>bob.temp_lunch = 'sandwich'
        >>>bob.add_trait('favorite_sport', Str('football'))
        >>>print(bob.trait_names())
        ['trait_added', 'age', 'name']

    In this example, the trait_names() method returns only the *age* and
    *name* attributes defined on the Person class. (The **trait_added**
    attribute is an explicit trait event defined on the HasTraits class.)
    The wildcard attribute *temp_lunch* and the dynamically-added trait
    attribute *favorite_sport* are not listed.
    T)Úprivater�   )rå   ÚextendedÚnewZfast_uiÚuir   c             C   s<   | j |ƒ}|jdkr8|dd… dkr8| j|dt||ƒƒ dS )z4 Handles a 'trait_added' event being fired.
        r=   r´   Nr°   iúÿÿÿ)rE   r[   Ú_init_trait_delegate_listenerr‚   )r„   rm   rE   r4   r4   r5   Ú_trait_added_changedˆ  s    
zHasTraits._trait_added_changedFc             C   s:   t | |ƒ}|r |dkrt|= dS |dk r6tj| |fƒ dS )aQ  Adds or removes the specified *handler* from the list of active
        monitors.

        Parameters
        ----------
        handler : function
            The function to add or remove as a monitor.
        remove : bool
            Flag indicating whether to remove (True) or add the specified
            handler as a monitor for this class.

        Description
        -----------
        If *remove* is omitted or False, the specified handler is added to
        the list of active monitors; if *remove* is True, the handler is
        removed from the active monitor list.

        r   N)rä   r   rs   )rI   r�   r¢   Úindexr4   r4   r5   Útrait_monitor™  s    
zHasTraits.trait_monitorc             G   sj   t |ƒdkrtdƒ‚t |ƒdkr*t|Ž }nt|d ƒ}| j||dƒ x | jdƒD ]}|j||dƒ qPW dS )a�   Adds a named trait attribute to this class.

        Parameters
        ----------
        name : str
            Name of the attribute to add.
        *trait :
            A trait or a value that can be converted to a trait using Trait()
            Trait definition of the attribute. It can be a single value or
            a list equivalent to an argument list for the Trait() function.

        r   z"No trait definition was specified.r   FTN)r€   Ú
ValueErrorr   r‹   Ú_add_class_traitÚtrait_subclasses)rI   rm   rE   Úsubclassr4   r4   r5   Úadd_class_trait½  s    
zHasTraits.add_class_traitc       
      C   sl  | j }|t }|dd … dkrr|d d… }||krF|r:d S td| ƒ‚|||< |d }|j|ƒ |jdd„ ƒ d S |t }|j|ƒd k	rœ|r�d S td| ƒ‚|j}|d k	rÞ|jrÄ| j	|d |j
ƒ ƒ |jrÞ| j	|d t|ƒƒ |jd	k	rô||t |< t| d
| ƒt| d| ƒg}	t|| |	ƒ |	j|jdƒƒ dd„ |	D ƒ}	t|	ƒdk�r`t|ƒ}t|jdƒ|	ƒ |||< d S )Nr   rn   z#The '%s_' trait is already defined.r}   c             S   s   t |ƒt | ƒ S )N)r€   )r±   Úyr4   r4   r5   r²   ñ  s    z,HasTraits._add_class_trait.<locals>.<lambda>z"The '%s' trait is already defined.r°   Fz_%s_changedz	_%s_firedr³   c             S   s   g | ]}|d k	r|‘qS )Nr4   )r§   rµ   r4   r4   r5   r¨     s    z.HasTraits._add_class_trait.<locals>.<listcomp>r   r~   r~   )rA   rÆ   r.   rs   rÉ   r¦   rP   r�   r»   r  r¼   r¾   r‘   rŒ   rÃ   rL   r˜   r€   rF   r•   rÍ   )
rI   rm   rE   Zis_subclassrU   rÓ   rÕ   rÒ   r�   r”   r4   r4   r5   r	  Þ  sF    

zHasTraits._add_class_traitc          
   C   s†   t |tƒrD| jt|tƒt|tƒt|tƒt|tƒt|tƒt|t	dƒƒ x<|j
D ]2}x,|jjƒ D ]\}}t| |ƒs\t| ||ƒ q\W qLW dS )z+ Adds a trait category to a class.
        N)rˆ   rh   Ú_add_trait_categoryrG   rÃ   r¦   rr   rÆ   rÂ   rÇ   Ú__mro__rA   rg   ÚhasattrÚsetattr)rI   ÚcategoryÚsubclsrm   rk   r4   r4   r5   Úadd_trait_category&  s    

zHasTraits.add_trait_categoryc             C   sÜ  �xd| g| j dƒ D �]N}t|tƒ}x |jƒ D ]\}	}
|j|	|
ƒ q.W t|tƒ}x |jƒ D ]\}	}
|j|	|
ƒ qZW t|tƒ}xX|jƒ D ]L\}	}|j|	ƒ}|d kr²|d d … ||	< q†x|D ]}||kr¸|j|ƒ q¸W q†W t|t	ƒ}|d }d}x2|jƒ D ]&\}	}
|	|krö|
||	< |j|	ƒ d}qöW |�r6|j
dd„ d� t|tƒ}x"|jƒ D ]\}	}
|j|	|
ƒ �qJW qW |d k	�rØ|j}t|ƒdk�rØt| td ƒ}|d k�r®tƒ }t| t|ƒ |j}x"|jƒ D ]\}	}
|j|	|
ƒ �q¾W d S )NTr}   Fc             S   s
   t | ƒ S )N)r€   )r±   r4   r4   r5   r²   l  s    z/HasTraits._add_trait_category.<locals>.<lambda>)r{   r   )r
  rG   rÃ   rg   ru   r¦   rr   rP   rs   rÆ   rÉ   rÂ   r¿   r€   rÇ   r6   r  )rI   rÑ   rÒ   rv   rÓ   rÔ   rÖ   r  Zsubclass_traitsrm   rk   rw   Zsubclass_arg_listsrx   Zsubclass_listÚchangedr¿   Zbase_veZbase_ve_contentr4   r4   r5   r  ?  sL    










zHasTraits._add_trait_categoryc             C   s^   y8t |tƒr6| r(|| jkr(td| ƒ‚|| j|< dS W n tk
rL   Y nX td| ƒ‚dS )z5 Sets a trait notification dispatch handler.
        z8A dispatch handler called '%s' has already been defined.Nz1%s is not a subclass of TraitChangeNotifyWrapper.)rˆ   r!   Úwrappersr.   Ú	TypeError)rI   rm   rŸ   Úoverrider4   r4   r5   Úset_trait_dispatch_handler…  s    

z$HasTraits.set_trait_dispatch_handlerc             C   s   |s| j ƒ S | jg ƒS )a   Returns a list of the immediate (or all) subclasses of this class.

        Parameters
        ----------
        all : bool
            Indicates whether to return all subclasses of this class. If
            False, only immediate subclasses are returned.

        )Ú__subclasses__Ú_trait_subclasses)rI   Úallr4   r4   r5   r
  �  s    
zHasTraits.trait_subclassesc             C   s2   x,| j ƒ D ] }||kr
|j|ƒ |j|ƒ q
W |S )N)r  rs   r  )rI   Z
subclassesr  r4   r4   r5   r  ­  s
    
zHasTraits._trait_subclassesc             G   s
   t | |ƒS )a¯  Returns whether the object implements a specified traits interface.

           Parameters
           ----------
           *interfaces :
                One or more traits Interface (sub)classes.

           Description
           -----------
           Tests whether the object implements one or more of the interfaces
           specified by *interfaces*. Return **True** if it does, and **False**
           otherwise.
        )r]   )r„   Z
interfacesr4   r4   r5   ri   º  s    zHasTraits.has_traits_interfacec                s†   | j td�}| j‰ |jt‡ fdd„| jddd�D ƒƒƒ | jtƒrvx2|jƒ D ]&\}}t	|ƒsLt
d|| jj|f ƒ‚qLW |jdtƒ |S )	au   Returns a dictionary of traits to pickle.

        In general, avoid overriding __getstate__ in subclasses. Instead, mark
        traits that should not be pickled with 'transient = True' metadata.

        In cases where this strategy is not sufficient, override __getstate__
        in subclasses using the following pattern to remove items that should
        not be persisted::

            def __getstate__(self):
                state = super(X,self).__getstate__()
                for key in ['foo', 'bar']:
                    if key in state:
                        del state[key]
                return state
        )r�   c                s    g | ]}|ˆ kr|ˆ | f‘qS r4   r4   )r§   rm   )Údicr4   r5   r¨   è  s   z*HasTraits.__getstate__.<locals>.<listcomp>r=   F)r[   r�   zGThe '%s' trait of a '%s' instance contains the unserializable value: %sÚ__traits_version__)Ú	trait_getr+   rA   rC   rf   Útrait_namesri   rj   rg   re   r.   Ú	__class__r1   ru   ÚTraitsVersion)r„   rK   rm   rk   r4   )r  r5   Ú__getstate__Î  s    


zHasTraits.__getstate__c             C   s   t | jf| jƒ fS )N)r   r!  r#  )r„   Úprotocolr4   r4   r5   Ú__reduce_ex__  s    zHasTraits.__reduce_ex__c                sŒ   |j ‰ ˆ ddƒdkrR‡ fdd„ˆ dg ƒD ƒ}| jj|ƒ | jf d|it|ƒ—Ž n,| jƒ  | jf d|i|—Ž | jƒ  | jƒ  | jdƒ dS )z= Restores the previously pickled state of an object.
        r  Nc                s   g | ]}|ˆ |ƒf‘qS r4   r4   )r§   rm   )Úpopr4   r5   r¨     s    z*HasTraits.__setstate__.<locals>.<listcomp>Z__HasTraits_restore__Útrait_change_notifyT)	r&  rA   rC   Ú	trait_setrf   Ú_init_trait_listenersÚ_post_init_trait_listenersÚtraits_initÚtraits_inited)r„   Ústater'  Úvaluesr4   )r&  r5   Ú__setstate__
  s    zHasTraits.__setstate__c             O   sp   i }t |ƒ}|dkr.t|d ƒtkr.|d }n|dkrB| jf |Ž}x(|D ] }t| |tƒ}|tk	rH|||< qHW |S )a7   Shortcut for getting object trait attributes.

        Parameters
        ----------
        names : list of strings
            A list of trait attribute names whose values are requested.

        Returns
        -------
        result : dict
            A dictionary whose keys are the names passed as arguments and whose
            values are the corresponding trait values.

        Description
        -----------
        Looks up the value of each trait whose name is passed as an argument
        and returns a dictionary containing the resulting name/value pairs.
        If any name does not correspond to a defined trait, it is not included
        in the result.

        If no names are specified, the result is a dictionary containing
        name/value pairs for *all* traits defined on the object.
        r   r   )r€   r[   r'   r   rG   r&   )r„   ÚnamesrD   rK   ry   rm   rk   r4   r4   r5   r  %  s    

zHasTraits.trait_getz!use "HasTraits.trait_get" insteadc             O   s   | j ||ŽS )N)r  )r„   r0  rD   r4   r4   r5   rP   M  s    zHasTraits.getc             K   sj   |sD| j dƒ z&x |jƒ D ]\}}t| ||ƒ qW W d| j dƒ X n"x |jƒ D ]\}}t| ||ƒ qNW | S )a`   Shortcut for setting object trait attributes.

        Parameters
        ----------
        trait_change_notify : bool
            If **True** (the default), then each value assigned may generate a
            trait change notification. If **False**, then no trait change
            notifications will be generated. (see also: trait_setq)
        **traits :
            Key/value pairs, the trait attributes and their values to be
            set

        Returns
        -------
        self :
            The method returns this object, after setting attributes.

        Description
        -----------
        Treats each keyword argument to the method as the name of a trait
        attribute and sets the corresponding trait attribute to the value
        specified. This is a useful shorthand when a number of trait attributes
        need to be set on an object, or a trait attribute value needs to be set
        in a lambda function. For example, you can write::

            person.trait_set(name='Bill', age=27)

        instead of::

            person.name = 'Bill'
            person.age = 27

        FNT)Z_trait_change_notifyrg   r  )r„   r'  Útraitsrm   rk   r4   r4   r5   r(  W  s    "
zHasTraits.trait_setz!use "HasTraits.trait_set" insteadc             K   s   | j f d|i|—ŽS )Nr'  )r(  )r„   r'  r1  r4   r4   r5   rÊ   ‡  s    zHasTraits.setc             K   s   | j f ddi|—ŽS )aÍ   Shortcut for setting object trait attributes.

        Parameters
        ----------
        **traits :
            Key/value pairs, the trait attributes and their values to be set.
            No trait change notifications will be generated for any values
            assigned (see also: trait_set).

        Returns
        -------
        self :
            The method returns this object, after setting attributes.

        Description
        -----------
        Treats each keyword argument to the method as the name of a trait
        attribute and sets the corresponding trait attribute to the value
        specified. This is a useful shorthand when a number of trait attributes
        need to be set on an object, or a trait attribute value needs to be set
        in a lambda function. For example, you can write::

            person.trait_setq(name='Bill', age=27)

        instead of::

            person.name = 'Bill'
            person.age = 27

        r'  F)r(  )r„   r1  r4   r4   r5   Ú
trait_setq�  s    zHasTraits.trait_setqNc             K   s\   g }|dkr| j f |Ž}x>|D ]6}yt| |ƒ W q ttfk
rR   |j|ƒ Y qX qW |S )at   Resets some or all of an object's trait attributes to their default
        values.

        Parameters
        ----------
        traits : list of strings
            Names of trait attributes to reset.

        Returns
        -------
        unresetable : list of strings
            A list of attributes that the method was unable to reset, which is
            empty if all the attributes were successfully reset.

        Description
        -----------
        Resets each of the traits whose names are specified in the *traits*
        list to their default values. If *traits* is None or omitted, the
        method resets all explicitly-defined object trait attributes to their
        default values. Note that this does not affect wildcard trait
        attributes or trait attributes added via add_trait(), unless they are
        explicitly named in *traits*.

        N)r   ÚdelattrÚAttributeErrorr.   rs   )r„   r1  rD   Zunresetablerm   r4   r4   r5   Úreset_traits´  s    
zHasTraits.reset_traitsc             K   s   |j ddd„ ƒ | jf |ŽS )zF Returns the list of trait names to copy or clone by default.
        r�   c             S   s   | dk	S )NTr4   )Útr4   r4   r5   r²   â  s    z0HasTraits.copyable_trait_names.<locals>.<lambda>)ru   r   )r„   rD   r4   r4   r5   Úcopyable_trait_namesÞ  s    zHasTraits.copyable_trait_namesc             C   s   t | jjƒ ƒS )z_ Returns the list of all trait names, including implicitly defined
            traits.
        )rc   r8   rË   )r„   r4   r4   r5   Úall_trait_namesê  s    zHasTraits.all_trait_namesc             C   s:   | j ƒ }dd„ | j| ƒD ƒ}tt| jƒjƒ ƒ}|| | S )z‹ Returns the list of trait names when calling the dir() builtin on
            the object. This enables tab-completion in IPython.
        c             S   s   g | ]}|‘qS r4   r4   )r§   rJ   r4   r4   r5   r¨   ú  s    z%HasTraits.__dir__.<locals>.<listcomp>)r   Ú_each_trait_methodrc   Úvarsr!  rË   )r„   r   Zmethod_namesZclass_attrsr4   r4   r5   Ú__dir__õ  s    zHasTraits.__dir__c             K   sê  |dkr| j f |Ž}n,|dks*t|ƒdkrB| jƒ }|dk	rBd|d< g }g }|dk}|dk}	xÖ|D ]Î}
y²| j|
ƒ}|jtkr†|j|
ƒ w`|j|
ƒ}|jdkrœw`t||
ƒ}|j	}|dkrÀt
j	|ƒ}nH|dkrÊn>|dksÖ|rø|dkrêt
j|ƒ}nt
j||ƒ}n|	�rt
j	|ƒ}t| |
|ƒ W q`   |j|
ƒ Y q`X q`W x²|D ]ª}
yŒt||
ƒ}|j|
ƒj	}|dk�rjt
j	|ƒ}nP|dk�rvnD|dk�s†|�rª|dk�rœt
j|ƒ}nt
j||ƒ}n|	�rºt
j	|ƒ}t| |
|ƒ W n   |j|
ƒ Y nX �q8W |S )	aÑ   Copies another object's trait attributes into this one.

        Parameters
        ----------
        other : object
            The object whose trait attribute values should be copied.
        traits : list of strings
            A list of names of trait attributes to copy. If None or
            unspecified, the set of names returned by trait_names() is used.
            If 'all' or an empty list, the set of names returned by
            all_trait_names() is used.
        memo : dict
            A dictionary of objects that have already been copied.
        copy : None | 'deep' | 'shallow'
            The type of copy to perform on any trait that does not have
            explicit 'copy' metadata. A value of None means 'copy reference'.

        Returns
        -------
        unassignable : list of strings
            A list of attributes that the method was unable to copy, which is
            empty if all the attributes were successfully copied.

        Nr  r   Útraits_to_copyÚdeepZshallowr<   rÿ   )r7  r€   r8  rE   r[   ÚDeferredCopyrs   Ú
base_traitrG   rB   Úcopy_moduleÚdeepcopyr  )r„   Úotherr1  ÚmemorB   rD   ZunassignableÚdeferredZ	deep_copyZshallow_copyrm   rE   r?  rk   Z	copy_typer4   r4   r5   Úcopy_traits  sh    













zHasTraits.copy_traitsc             K   s    |dkri }|dkr"| j f |Ž}n$|dks6t|ƒdkrF| jƒ }d|d< ||d< | j| jƒ}||t| ƒ< |jƒ  |j| |||f|Ž |jƒ  |j	ƒ  |j
dƒ |S )a   Clones a new object from this one, optionally copying only a
        specified set of traits.

        Parameters
        ----------
        traits : list of strings
            The list of names of the trait attributes to copy.
        memo : dict
            A dictionary of objects that have already been copied.
        copy : str
            The type of copy ``deep`` or ``shallow`` to perform on any trait
            that does not have explicit 'copy' metadata. A value of None means
            'copy reference'.

        Returns
        -------
        new :
            The newly cloned object.

        Description
        -----------
        Creates a new object that is a clone of the current object. If *traits*
        is None (the default), then all explicit trait attributes defined
        for this object are cloned. If *traits* is 'all' or an empty list, the
        list of traits returned by all_trait_names() is used; otherwise,
        *traits* must be a list of the names of the trait attributes to be
        cloned.
        Nr  r   r<  Útraits_copy_modeT)r7  r€   r8  r�   r!  rÄ   r)  rE  r*  r+  r,  )r„   r1  rC  rB   rD   r  r4   r4   r5   Úclone_traitsb  s     
zHasTraits.clone_traitsc             C   s8   t | ƒ}||kr|| S | j||jdƒ|jdƒd�}|S )z, Creates a deep copy of the object.
        r<  rF  )rC  r1  rB   )rÄ   rG  rP   )r„   rC  Zid_selfrK   r4   r4   r5   Ú__deepcopy__—  s    zHasTraits.__deepcopy__rq   c       	   	   K   s2   |dkr| }| j |ƒ}|j|||| jƒ ||||ƒS )a9   Displays a user interface window for editing trait attribute values.

        Parameters
        ----------
        view : View or string
            A View object (or its name) that defines a user interface for
            editing trait attribute values of the current object. If the view is
            defined as an attribute on this class, use the name of the attribute.
            Otherwise, use a reference to the view object. If this attribute is
            not specified, the View object returned by trait_view() is used.
        parent : toolkit control
            The reference to a user interface component to use as the parent
            window for the object's UI window.
        kind : str
            The type of user interface window to create. See the
            **traitsui.view.kind_trait** trait for values and
            their meanings. If *kind* is unspecified or None, the **kind**
            attribute of the View object is used.
        context : object or dictionary
            A single object or a dictionary of string/object pairs, whose trait
            attributes are to be edited. If not specified, the current object is
            used.
        handler : Handler
            A handler object used for event handling in the dialog box. If
            None, the default handler for Traits UI is used.
        id : str
            A unique ID for persisting preferences about this user interface,
            such as size and position. If not specified, no user preferences
            are saved.
        scrollable : bool
            Indicates whether the dialog box should be scrollable. When set to
            True, scroll bars appear on the dialog box if it is not large enough
            to display all of the items in the view at one time.

        Returns
        -------
        A UI object.
        N)Ú
trait_viewr  Útrait_view_elements)	r„   ÚviewÚparentÚkindÚcontextr�   rÄ   Ú
scrollablerø   r4   r4   r5   Úedit_traitsª  s    1
zHasTraits.edit_traitsc             C   s   d| iS )z[ Returns the default context to use for editing or configuring
            traits.
        Úobjectr4   )r„   r4   r4   r5   Útrait_contextï  s    zHasTraits.trait_contextc             C   s   | j j||| j| j| j| ƒS )aÛ   Gets or sets a ViewElement associated with an object's class.

        Parameters
        ----------
        name : str
            Name of a view element
        view_element : ViewElement
            View element to associate

        Returns
        -------
        A view element.

        Description
        -----------
        If both *name* and *view_element* are specified, the view element is
        associated with *name* for the current object's class. (That is,
        *view_element* is added to the ViewElements object associated with
        the current object's class, indexed by *name*.)

        If only *name* is specified, the function returns the view element
        object associated with *name*, or None if *name* has no associated
        view element. View elements retrieved by this function are those that
        are bound to a class attribute in the class definition, or that are
        associated with a name by a previous call to this method.

        If neither *name* nor *view_element* is specified, the method returns a
        View object, based on the following order of preference:

        1. If there is a View object named ``traits_view`` associated with the
           current object, it is returned.
        2. If there is exactly one View object associated the current
           object, it is returned.
        3. Otherwise, it returns a View object containing items for all the
           non-event trait attributes on the current object.

        )r!  Ú_trait_viewÚdefault_traits_viewrJ  Úvisible_traits)r„   rm   Úview_elementr4   r4   r5   rI  ù  s    &zHasTraits.trait_viewc             C   s   | j ||| j| j| jd ƒS )N)rS  Úclass_default_traits_viewÚclass_trait_view_elementsÚclass_visible_traits)rI   rm   rV  r4   r4   r5   Úclass_trait_view(  s    zHasTraits.class_trait_viewc             C   s  t |tƒr|S |ƒ }|dkr dS |rr|dkrd|j|ƒ}|dkr`|dk	r`t||dƒ}t|ƒr`|ƒ }|S ||j|< dS |ƒ }t |tƒr†|S |jƒ }	||	kr |j|ƒS |dk	rÐt||dƒ}t|ƒrÐ|ƒ }t |tƒrÐ|S t|	ƒdkrê|j|	d ƒS ddlm	}
 |
|ƒ ddgd�S )zG Gets or sets a ViewElement associated with an object's class.
        Nr   r   )ÚViewÚOKZCancel)Zbuttons)
r]   r0   rt   rG   Úcallabler¿   Ú	filter_byr€   Útraitsui.apir[  )rI   rm   rV  Zdefault_namerÖ   Ztrait_selector_fr�   rK   rJ   r0  r[  r4   r4   r5   rS  8  s>    





zHasTraits._trait_viewc             C   s
   | j jƒ S )zM Returns the name of the default traits view for the object's class.
        )r!  rW  )r„   r4   r4   r5   rT  †  s    zHasTraits.default_traits_viewc             C   s   t S )zD Returns the name of the default traits view for the class.
        )ÚDefaultTraitsView)rI   r4   r4   r5   rW  �  s    z#HasTraits.class_default_traits_viewc             C   s   | j jt j|ƒS )a_   Returns a list of the names of all view elements associated with the
        current object's class.

        Parameters
        ----------
        klass : class
            A class, such that all returned names must correspond to instances
            of this class. Possible values include:

            * Group
            * Item
            * View
            * ViewElement
            * ViewSubElement

        Description
        -----------
        If *klass* is specified, the list of names is filtered such that only
        objects that are instances of the specified class are returned.
        )r!  rA   rÇ   r^  )r„   rŸ   r4   r4   r5   Útrait_views›  s    zHasTraits.trait_viewsc             C   s
   | j jƒ S )zÁ Returns the ViewElements object associated with the object's
        class.

        The returned object can be used to access all the view elements
        associated with the class.
        )r!  rX  )r„   r4   r4   r5   rJ  ¶  s    zHasTraits.trait_view_elementsc             C   s
   | j t S )z° Returns the ViewElements object associated with the class.

        The returned object can be used to access all the view elements
        associated with the class.
        )rA   rÇ   )rI   r4   r4   r5   rX  ¿  s    z#HasTraits.class_trait_view_elementsc	             K   s¬   |dk	r4t |dƒ�}
| jtjj|
ƒjƒ ƒ W dQ R X |r¨ddlm} |dkrP| }|ƒ j|| j	|ƒ|||||	ƒ}|r¤|dk	r¤t |dƒ�}
tjj
|
dƒj| ƒ W dQ R X |S dS )aG  Creates and displays a dialog box for editing values of trait
        attributes, as if it were a complete, self-contained GUI application.

        Parameters
        ----------
        filename : str
            The name (including path) of a file that contains a pickled
            representation of the current object. When this parameter is
            specified, the method reads the corresponding file (if it exists)
            to restore the saved values of the object's traits before displaying
            them. If the user confirms the dialog box (by clicking **OK**),
            the new values are written to the file. If this parameter is not
            specified, the values are loaded from the in-memory object, and are
            not persisted when the dialog box is closed.
        view : View or str
            A View object (or its name) that defines a user interface for
            editing trait attribute values of the current object. If the view is
            defined as an attribute on this class, use the name of the attribute.
            Otherwise, use a reference to the view object. If this attribute is
            not specified, the View object returned by trait_view() is used.
        kind : str
            The type of user interface window to create. See the
            **traitsui.view.kind_trait** trait for values and
            their meanings. If *kind* is unspecified or None, the **kind**
            attribute of the View object is used.
        edit : bool
            Indicates whether to display a user interface. If *filename*
            specifies an existing file, setting *edit* to False loads the
            saved values from that file into the object without requiring
            user interaction.
        context : object or dictionary
            A single object or a dictionary of string/object pairs, whose trait
            attributes are to be edited. If not specified, the current object is
            used
        handler : Handler
            A handler object used for event handling in the dialog box. If
            None, the default handler for Traits UI is used.
        id : str
            A unique ID for persisting preferences about this user interface,
            such as size and position. If not specified, no user preferences
            are saved.
        scrollable : bool
            Indicates whether the dialog box should be scrollable. When set to
            True, scroll bars appear on the dialog box if it is not large enough
            to display all of the items in the view at one time.

        Returns
        -------
        True on success.

        Description
        -----------
        This method is intended for use in applications that do not normally
        have a GUI. Control does not resume in the calling application until
        the user closes the dialog box.

        The method attempts to open and unpickle the contents of *filename*
        before displaying the dialog box. When editing is complete, the method
        attempts to pickle the updated contents of the object back to *filename*.
        If the file referenced by *filename* does not exist, the object is not
        modified before displaying the dialog box. If *filename* is unspecified
        or None, no pickling or unpickling occurs.

        If *edit* is True (the default), a dialog box for editing the
        current object is displayed. If *edit* is False or None, no
        dialog box is displayed. You can use ``edit=False`` if you want the
        object to be restored from the contents of *filename*, without being
        modified by the user.
        NÚrbr   )ÚtoolkitÚwbT)ÚopenrE  ÚsmÚcPickleÚ	UnpicklerÚloadr_  rc  Zview_applicationrI  ÚPicklerÚdump)r„   ÚfilenamerK  rM  ZeditrN  r�   rÄ   rO  rø   Úfdrc  r×   r4   r4   r5   Úconfigure_traitsÍ  s(    S zHasTraits.configure_traitsc             C   s   | j ttd�}|jƒ  |S )z…Returns an alphabetically sorted list of the names of non-event
        trait attributes associated with the current object.
        )r[   rŽ   )r   r,   r-   rÉ   )r„   r0  r4   r4   r5   Úeditable_traits=	  s    zHasTraits.editable_traitsc             C   s   | j ttd�}|jƒ  |S )z„Returns an alphabetically sorted list of the names of non-event
        trait attributes associated with the current class.
        )r[   rŽ   )Úclass_trait_namesr,   r-   rÉ   )rI   r0  r4   r4   r5   Úclass_editable_traitsE	  s    zHasTraits.class_editable_traitsc             C   s   | j ttd�S )z Returns an alphabetically sorted list of the names of non-event
        trait attributes associated with the current object, that should be GUI visible
        )r[   Úvisible)r   r,   r-   )r„   r4   r4   r5   rU  O	  s    zHasTraits.visible_traitsc             C   s   | j ttd�S )zŸReturns an alphabetically sorted list of the names of non-event
        trait attributes associated with the current class, that should be GUI visible
        )r[   rr  )rp  r,   r-   )rI   r4   r4   r5   rY  U	  s    zHasTraits.class_visible_traitsc       
      K   s6  t |ƒdkr| jf |Ž}n| jtd�}t |ƒdkr>tdƒ dS g }tdd„ |D ƒƒd }d| }|jƒ  xº|D ]²}yTtt| |ƒƒjd	d
ƒ}t |ƒ|krÄd|d|d d … ||d d  d… f }W n   d}Y nX |d j	|ƒ}	|�r|j
d|	|| j|ƒjjƒ f ƒ qn|j
d|	|f ƒ qnW td	j|ƒƒ dS )a  Prints the values of all explicitly-defined, non-event trait
        attributes on the current object, in an easily readable format.

        Parameters
        ----------
        show_help : bool
            Indicates whether to display additional descriptive information.
        r   )r[   rq   Nc             S   s   g | ]}t |ƒ‘qS r4   )r€   )r§   r±   r4   r4   r5   r¨   u	  s    z*HasTraits.print_traits.<locals>.<listcomp>r   éN   Ú
z\nz%s...%srM   rú   z<undefined>ú:z%s %s
   The value must be %s.z%s %s)r€   r   r,   ÚprintÚmaxrÉ   ÚreprrG   ÚreplaceÚljustrs   r?  rÙ   ÚinforÐ   )
r„   Z	show_helprD   r0  rK   ÚpadZmaxvalrm   rk   Úlnamer4   r4   r5   Úprint_traitsa	  s4    


zHasTraits.print_traitsrå   c             C   s$  t |ƒtkr2x |D ]}| j||||||ƒ qW dS |p8d}|r°|dkrR| jdƒ}n"| j|dƒ}	|	dkrjdS |	jdƒ}|dk	r¬x.t|ƒD ]"\}
}|j|ƒr†||
= |jƒ  P q†W dS |dkrÄ| jdƒ}n| j|dƒjdƒ}xH|D ]}|j|ƒrÜP qÜW | j| |||ƒ}|�r|j	d|ƒ n
|j
|ƒ dS )ad  Causes the object to invoke a handler whenever a trait attribute
        is modified, or removes the association.

        Parameters
        ----------
        handler : function
            A trait notification function for the attribute specified by *name*.
        name : str
            Specifies the trait attribute whose value changes trigger the
            notification.
        remove : bool
            If True, removes the previously-set association between
            *handler* and *name*; if False (the default), creates the
            association.

        Description
        -----------
        Multiple handlers can be defined for the same object, or even for the
        same trait attribute on the same object. If *name* is not specified or
        is None, *handler* is invoked when any trait attribute on the
        object is changed.
        NrÞ   r   r   rM   )r[   rc   Ú_on_trait_changerÍ   Ú_traitrà   ÚequalsÚdisposer  Úinsertrs   )r„   r�   rm   r¢   rç   ÚpriorityÚtargetÚname_ir“   rE   râ   Znotifierrë   r4   r4   r5   r  •	  s<     




zHasTraits._on_trait_changec          
   C   s¶  t |tjƒrtj|ƒdks"|dkr:| j||||||ƒ dS ddlm}m}	m	}
m
} t |tƒr†x$|D ]}| j|||||||d� qbW dS |pŒdjƒ }|�r*| jj|ƒ}|dk	�r²|j|ƒ}|dk	�r²xît|ƒD ]X\}}|j|ƒrÌ||= t|ƒdk�r||= t|ƒdk�r| j|= |jj| ƒ |jƒ  P qÌW nˆ| jj|i ƒ}|j|g ƒ}xl|D ]}|j|ƒ�rJP �qJW |	|ƒj}||| |||ƒ}|j|ƒ |j|
|ƒtj|ƒ|j|||d� |j| ƒ dS )aï,  Causes the object to invoke a handler whenever a trait attribute
        matching a specified pattern is modified, or removes the association.

        Parameters
        ----------
        handler : function
            A trait notification function for the *name* trait attribute, with
            one of the signatures described below.
        name : str
            The name of the trait attribute whose value changes trigger the
            notification. The *name* can specify complex patterns of trait
            changes using an extended *name* syntax, which is described below.
        remove : bool
            If True, removes the previously-set association between
            *handler* and *name*; if False (the default), creates the
            association.
        dispatch : str
            A string indicating the thread on which notifications must be run.
            Possible values are:

            =========== =======================================================
            value       dispatch
            =========== =======================================================
            ``same``    Run notifications on the same thread as this one.
            ``ui``      Run notifications on the UI thread. If the current
                        thread is the UI thread, the notifications are executed
                        immediately; otherwise, they are placed on the UI
                        event queue.
            ``fast_ui`` Alias for ``ui``.
            ``new``     Run notifications in a new thread.
            =========== =======================================================

        Description
        -----------
        Multiple handlers can be defined for the same object, or even for the
        same trait attribute on the same object. If *name* is not specified or
        is None, *handler* is invoked when any trait attribute on the
        object is changed.

        The *name* parameter is a single *xname* or a list of *xname* names,
        where an *xname* is an extended name of the form::

            xname2[('.'|':') xname2]*

        An *xname2* is of the form::

            ( xname3 | '['xname3[','xname3]*']' ) ['*']

        An *xname3* is of the form::

             xname | ['+'|'-'][name] | name['?' | ('+'|'-')[name]]

        A *name* is any valid Python attribute name. The semantic meaning of
        this notation is as follows:

        ================================ ======================================
        expression                       meaning
        ================================ ======================================
        ``item1.item2``                  means *item1* is a trait containing an
                                         object (or objects if *item1* is a
                                         list or dict) with a trait called
                                         *item2*. Changes to either *item1* or
                                         *item2* cause a notification to be
                                         generated.
        ``item1:item2``                  means *item1* is a trait containing an
                                         object (or objects if *item1* is a
                                         list or dict) with a trait called
                                         *item2*. Changes to *item2* cause a
                                         notification to be generated, while
                                         changes to *item1* do not (i.e., the
                                         ':' indicates that changes to the
                                         *link* object should not be reported).
        ``[ item1, item2, ..., itemN ]`` A list which matches any of the
                                         specified items. Note that at the
                                         topmost level, the surrounding square
                                         brackets are optional.
        ``name?``                        If the current object does not have an
                                         attribute called *name*, the reference
                                         can be ignored. If the '?' character
                                         is omitted, the current object must
                                         have a trait called *name*, otherwise
                                         an exception will be raised.
        ``prefix+``                      Matches any trait on the object whose
                                         name begins with *prefix*.
        ``+metadata_name``               Matches any trait on the object having
                                         *metadata_name* metadata.
        ``-metadata_name``               Matches any trait on the object which
                                         does not have *metadata_name*
                                         metadata.
        ``prefix+metadata_name``         Matches any trait on the object whose
                                         name begins with *prefix* and which
                                         has *metadata_name* metadata.
        ``prefix-metadata_name``         Matches any trait on the object
                                         whose name begins with *prefix* and
                                         which does not have *metadata_name*
                                         metadata.
        ``+``                            Matches all traits on the object.
        ``pattern*``                     Matches object graphs where *pattern*
                                         occurs one or more times (useful for
                                         setting up listeners on recursive data
                                         structures like trees or linked
                                         lists).
        ================================ ======================================

        Some examples of valid names and their meaning are as follows:

        ======================= ===============================================
        example                 meaning
        ======================= ===============================================
        ``foo,bar,baz``         Listen for trait changes to *object.foo*,
                                *object.bar*, and *object.baz*.
        ``['foo','bar','baz']`` Equivalent to 'foo,bar,baz', but may be more
                                useful in cases where the individual items are
                                computed.
        ``foo.bar.baz``         Listen for trait changes to
                                *object.foo.bar.baz* and report changes to
                                *object.foo*, *object.foo.bar* or
                                *object.foo.bar.baz*.
        ``foo:bar:baz``         Listen for changes to *object.foo.bar.baz*, and
                                only report changes to *object.foo.bar.baz*.
        ``foo.[bar,baz]``       Listen for trait changes to *object.foo.bar*
                                and *object.foo.baz*.
        ``[left,right]*.name``  Listen for trait changes to the *name* trait of
                                each node of a tree having *left* and *right*
                                links to other tree nodes, and where *object*
                                the method is applied to the root node of the
                                tree.
        ``+dirty``              Listen for trait changes on any trait in the
                                *object* which has the 'dirty' metadata set.
        ``foo.+dirty``          Listen for trait changes on any trait in
                                *object.foo* which has the 'dirty' metadata
                                set.
        ``foo.[bar,-dirty]``    Listen for trait changes on *object.foo.bar* or
                                any trait on *object.foo* which does not have
                                'dirty' metadata set.
        ======================= ===============================================


        Note that any of the intermediate (i.e., non-final) links in a
        pattern can be traits of type Instance, List or Dict. In the case
        of List and Dict traits, the subsequent portion of the pattern is
        applied to each item in the list, or value in the dictionary.

        For example, if the self.children is a list, 'children.name'
        listens for trait changes to the *name* trait for each item in the
        self.children list.

        Note that items added to or removed from a list or dictionary in
        the pattern will cause the *handler* routine to be invoked as well,
        since this is treated as an *implied* change to the item's trait
        being monitored.

        The signature of the *handler* supplied also has an effect on
        how changes to intermediate traits are processed. The five valid
        handler signatures are:

        1. handler()
        2. handler(new)
        3. handler(name,new)
        4. handler(object,name,new)
        5. handler(object,name,old,new)

        For signatures 1, 4 and 5, any change to any element of a path
        being listened to invokes the handler with information about the
        particular element that was modified (e.g., if the item being
        monitored is 'foo.bar.baz', a change to 'bar' will call *handler*
        with the following information:

        - object: object.foo
        - name:   bar
        - old:    old value for object.foo.bar
        - new:    new value for object.foo.bar

        If one of the intermediate links is a List or Dict, the call to
        *handler* may report an *_items* changed event. If in the previous
        example, *bar* is a List, and a new item is added to *bar*, then
        the information passed to *handler* would be:

        - object: object.foo
        - name:   bar_items
        - old:    Undefined
        - new:    TraitListEvent whose *added* trait contains the new item
                  added to *bar*.

        For signatures 2 and 3, the *handler* does not receive enough
        information to discern between a change to the final trait being
        listened to and a change to an intermediate link. In this case,
        the event dispatcher will attempt to map a change to an
        intermediate link to its effective change on the final trait. This
        only works if all of the intermediate links are single values (such
        as an Instance or Any trait) and not Lists or Dicts. If the modified
        intermediate trait or any subsequent intermediate trait preceding
        the final trait is a List or Dict, then a TraitError is raised,
        since the effective value for the final trait cannot in general be
        resolved unambiguously. To prevent TraitErrors in this case, use the
        ':' separator to suppress notifications for changes to any of the
        intermediate links.

        Handler signature 1 also has the special characteristic that if a
        final trait is a List or Dict, it will automatically handle '_items'
        changed events for the final trait as well. This can be useful in
        cases where the *handler* only needs to know that some aspect of the
        final trait has been changed. For all other *handler* signatures,
        you must explicitly specify the 'xxx_items' trait if you want to
        be notified of changes to any of the items of the 'xxx' trait.

        Nr   )ÚTraitsListenerÚListenerParserÚListenerHandlerÚListenerNotifyWrapper)rm   r¢   rç   r„  rD  r…  rÞ   r   )r�   Zwrapped_handler_refr[   rç   r„  rD  )r]   rR   r–   Úextended_trait_patÚmatchr  Ztraits_listenerr‡  rˆ  r‰  rŠ  rc   rO   ÚstriprA   rP   rà   r�  r€   r    Ú
unregisterr‚  ru   rs   r(  rþ   rÿ   r[   Úregister)r„   r�   rm   r¢   rç   r„  rD  r…  r‡  rˆ  r‰  rŠ  r†  rf   rÔ   râ   rë   r    Zlnwr4   r4   r5   rO   é	  sh     ]








zHasTraits.on_trait_changec                sh  |dkr|}| j |ƒo|j |ƒ}|r°| jƒ ‰ˆj|ƒ}|dk	r–t|ƒ|f}||kr–||= t|ƒdkr–ˆ|= | j| j|dd� |r–| j| j|d dd� |r¬|j|| |ddƒ dS dd„ ‰ | jƒ ‰ˆj	|i ƒ}t|ƒ|f}‡ ‡fd	d
„}	t
j||	ƒ|f}
||k�rNt|ƒdk�r4| j| j|ƒ |�r4| j| j|d ƒ |
||< t||t| |ƒƒ |�rd|j|| |dƒ dS )a™  Synchronizes the value of a trait attribute on this object with a
        trait attribute on another object.

        Parameters
        ----------
        name : str
            Name of the trait attribute on this object.
        object : object
            The object with which to synchronize.
        alias : str
            Name of the trait attribute on *other*; if None or omitted, same
            as *name*.
        mutual : bool or int
            Indicates whether synchronization is mutual (True or non-zero)
            or one-way (False or zero)
        remove : bool or int
            Indicates whether synchronization is being added (False or zero)
            or removed (True or non-zero)

        Description
        -----------
        In mutual synchronization, any change to the value of the specified
        trait attribute of either object results in the same value being
        assigned to the corresponding trait attribute of the other object.
        In one-way synchronization, any change to the value of the attribute
        on this object causes the corresponding trait attribute of *object* to
        be updated, but not vice versa.
        Nr   T)r¢   r°   Fc             S   sd   x^t |jƒ ƒD ]N\}}|dkrx*t |jƒ ƒD ]\}}| |d kr,||= q,W t|ƒdkr||= qW d S )Nrq   r   )rc   rg   r€   )rÿ   r{  r{   r  rm   rk   r4   r4   r5   Ú_sync_trait_listener_deletedU  s    
z:HasTraits.sync_trait.<locals>._sync_trait_listener_deletedc                s
   ˆ | ˆƒS )Nr4   )rÿ   )r�  r{  r4   r5   r²   b  s    z&HasTraits.sync_trait.<locals>.<lambda>)Ú_is_list_traitÚ_get_sync_trait_inforP   rÄ   r€   r  Ú_sync_trait_modifiedÚ_sync_trait_items_modifiedÚ
sync_traitru   rþ   rÿ   r  rG   )r„   Ú
trait_namerQ  ÚaliasZmutualr¢   Úis_listr  r{   Úcallbackrk   r4   )r�  r{  r5   r•    sN    
	
zHasTraits.sync_traitc             C   s.   t | dd ƒ}|d kr*i  | jd< }i |d< |S )NÚ__sync_trait__rq   )rG   rA   )r„   r{  r4   r4   r5   r’  r  s
    zHasTraits._get_sync_trait_infoc             C   sz   | j }||krd S |d }d ||< xL|| jƒ D ]<\}}|ƒ }||jƒ d kr0yt|||ƒ W q0   Y q0X q0W ||= d S )Nrq   )rš  r.  r’  r  )r„   rQ  rm   Úoldr  r{  ÚlockedÚobject_namer4   r4   r5   r“  z  s    
zHasTraits._sync_trait_modifiedc       
      C   s–   |j }|t|jƒ }|d d… }| j}|d }d ||< xT|| jƒ D ]D\}}	|ƒ }|	|jƒ d krDy|jt||	ƒ||…< W qD   Y qDX qDW ||= d S )Nr´   rq   iúÿÿÿ)r  r€   Úremovedrš  r.  r’  ÚaddedrG   )
r„   rQ  rm   r›  r<   Zn0Zn1r{  rœ  r�  r4   r4   r5   r”  Š  s    
z$HasTraits._sync_trait_items_modifiedc             C   s   | j |ƒj}|d k	o|jtkS )N)r?  r�   Zdefault_value_typer$   )r„   r–  r�   r4   r4   r5   r‘  ›  s    zHasTraits._is_list_traitc       	      G   sH  t |ƒdkrtdƒ‚t |ƒdkr*t|Ž }nt|d ƒ}|j}|dk	rx|jr^| j|d |jƒ ƒ |jrx| j|d t	|ƒƒ | j
|dƒ}| jƒ }t|ƒ ||< }|dk	rÈ|jdƒ}|dk	rÆ|jdƒj|ƒ nl| j}t|d| ƒt|d| ƒg}t|||ƒ |j| jjd	ƒƒ d
d„ |D ƒ}t |ƒdk�r4t|jdƒ|ƒ |dk�rD|| _dS )a‹  Adds a trait attribute to this object.

        Parameters
        ----------
        name : str
            Name of the attribute to add.
        *trait :
            Trait or a value that can be converted to a trait by Trait().
            Trait definition for *name*. If more than one value is specified,
            it is equivalent to passing the entire list of values to Trait().

        r   z"No trait definition was specified.r   Nr°   rn   z_%s_changedz	_%s_firedr³   c             S   s   g | ]}|d k	r|‘qS )Nr4   )r§   rµ   r4   r4   r5   r¨   å  s    z'HasTraits.add_trait.<locals>.<listcomp>)r€   r  r   r‹   r�   r»   Ú	add_traitr¼   r¾   r‘   r€  Ú_instance_traitsrF   rÍ   Úextendr!  rL   r˜   rs   r9   rP   r•   Útrait_added)	r„   rm   rE   r�   Z	old_traitÚitrait_dictZold_notifiersrI   r”   r4   r4   r5   r   ¦  s8    


zHasTraits.add_traitc             C   sz   | j |dƒ}|dk	rv|j}|dk	rJ|jr6| j|d ƒ |jrJ| j|d ƒ || jkr\| j|= | jƒ }||krv||= dS dS )a
  Removes a trait attribute from this object.

        Parameters
        ----------
        name : str
            Name of the attribute to remove.

        Returns
        -------
        result : bool
            True if the trait was successfully removed.
        r   Nr°   rn   TF)r€  r�   r»   Úremove_traitr¾   rA   r¡  )r„   rm   rE   r�   r¤  r4   r4   r5   r¥  ó  s    
zHasTraits.remove_traitc             C   s2   d}|rd}| j ||ƒ}| s&|dkr*|S t|ƒS )a   Returns the trait definition for the *name* trait attribute.

        Parameters
        ----------
        name : str
            Name of the attribute whose trait definition is to be returned.
        force : bool
            Indicates whether to return a trait definition if *name* is
            not explicitly defined.
        copy : bool
            Indicates whether to return the original trait definition or a
            copy.

        Description
        -----------
        If *force* is False (the default) and *name* is the name of an
        implicitly defined trait attribute that has never been referenced
        explicitly (i.e., has not yet been defined), the result is None. In
        all other cases, the result is the trait definition object associated
        with *name*.

        If *copy* is True, and a valid trait definition is found for *name*,
        a copy of the trait found is returned. In all other cases, the trait
        definition found is returned unmodified (the default).
        r   r   Nr~   )r€  rF   )r„   rm   ÚforcerB   ÚmoderK   r4   r4   r5   rE     s    zHasTraits.traitc             C   s   | j |dƒS )ad  Returns the base trait definition for a trait attribute.

        Parameters
        ----------
        name : str
            Name of the attribute whose trait definition is returned.

        Description
        -----------
        This method is similar to the trait() method, and returns a
        different result only in the case where the trait attribute defined by
        *name* is a delegate. In this case, the base_trait() method follows the
        delegation chain until a non-delegated trait attribute is reached, and
        returns the definition of that attribute's trait as the result.
        rM   éþÿÿÿ)r€  )r„   rm   r4   r4   r5   r?  E  s    zHasTraits.base_traitc             C   s   | j |ƒj| ||ƒS )zn Validates whether a value is legal for a trait.

        Returns the validated value if it is valid.
        )r?  rº   )r„   rm   rk   r4   r4   r5   Úvalidate_trait\  s    zHasTraits.validate_traitc       	      K   s   | j jƒ }x0| jƒ jƒ D ] \}}|dd… dkr|||< qW x4| jjƒ D ]&}||krH| j|ƒ}|dk	rH|||< qHW t|ƒdkr‚|S x0t|jƒ ƒD ] \}}t	|ƒt
k	r�t|ƒ||< q�W i }xB|jƒ D ]6\}}x,|jƒ D ]\}}|t||ƒƒsÔP qÔW |||< qÂW |S )aô  Returns a dictionary containing the definitions of all of the trait
        attributes of this object that match the set of *metadata* criteria.

        Parameters
        ----------
        **metadata :
            Criteria for selecting trait attributes.

        Description
        -----------
        The keys of the returned dictionary are the trait attribute names, and
        the values are their corresponding trait definition objects.

        If no *metadata* information is specified, then all explicitly defined
        trait attributes defined for the object are returned.

        Otherwise, the *metadata* keyword dictionary is assumed to define a set
        of search criteria for selecting trait attributes of interest. The
        *metadata* dictionary keys correspond to the names of trait metadata
        attributes to examine, and the values correspond to the values the
        metadata attribute must have in order to be included in the search
        results.

        The *metadata* values either may be simple Python values like strings or
        integers, or may be lambda expressions or functions that return True
        if the trait attribute is to be included in the result. A lambda
        expression or function must receive a single argument, which is the
        value of the trait metadata attribute being tested. If more than one
        metadata keyword is specified, a trait attribute must match the metadata
        values of all keywords to be included in the result.
        r´   Nr°   r   iúÿÿÿ)r7   rB   r¡  rg   rA   rË   rE   r€   rc   r[   r   rƒ   rG   )	r„   rD   r1  rm   ZtrtrE   Ú	meta_nameÚ	meta_evalrK   r4   r4   r5   r1  g  s*     

zHasTraits.traitsc             K   s–   t |ƒdkr| jjƒ S i }x0t|jƒ ƒD ] \}}t|ƒtk	r(t|ƒ||< q(W xD| jjƒ D ]6\}}x,|jƒ D ]\}}|t||ƒƒsjP qjW |||< qXW |S )aõ  Returns a dictionary containing the definitions of all of the trait
        attributes of the class that match the set of *metadata* criteria.

        Parameters
        ----------
        **metadata :
            Criteria for selecting trait attributes.

        Description
        -----------
        The keys of the returned dictionary are the trait attribute names, and
        the values are their corresponding trait definition objects.

        If no *metadata* information is specified, then all explicitly defined
        trait attributes defined for the class are returned.

        Otherwise, the *metadata* keyword dictionary is assumed to define a set
        of search criteria for selecting trait attributes of interest. The
        *metadata* dictionary keys correspond to the names of trait metadata
        attributes to examine, and the values correspond to the values the
        metadata attribute must have in order to be included in the search
        results.

        The *metadata* values either may be simple Python values like strings or
        integers, or may be lambda expressions or functions that return **True**
        if the trait attribute is to be included in the result. A lambda
        expression or function must receive a single argument, which is the
        value of the trait metadata attribute being tested. If more than one
        metadata keyword is specified, a trait attribute must match the metadata
        values of all keywords to be included in the result.
        r   )	r€   r7   rB   rc   rg   r[   r   rƒ   rG   )rI   rD   rK   rª  r«  rm   rE   r4   r4   r5   rÒ   ©  s     
zHasTraits.class_traitsc             K   s   t | jf |Žjƒ ƒS )a·  Returns a list of the names of all trait attributes whose definitions
        match the set of *metadata* criteria specified.

        Parameters
        ----------
        **metadata :
            Criteria for selecting trait attributes.

        Description
        -----------
        This method is similar to the traits() method, but returns only the
        names of the matching trait attributes, not the trait definitions.
        )rc   r1  rË   )r„   rD   r4   r4   r5   r   á  s    zHasTraits.trait_namesc             K   s   t | jf |Žjƒ ƒS )a·  Returns a list of the names of all trait attributes whose definitions
        match the set of *metadata* criteria specified.

        Parameters
        ----------
        **metadata :
            Criteria for selecting trait attributes.

        Description
        -----------
        This method is similar to the traits() method, but returns only the
        names of the matching trait attributes, not the trait definitions.
        )rc   rÒ   rË   )rI   rD   r4   r4   r5   rp  ñ  s    zHasTraits.class_trait_namesc             C   s:   t | }| jj|tƒ}|| j|< ||kr6| j|||ƒ dS )z9 Explicitly sets the value of a cached property.
        N)r(   rA   rP   r)   Útrait_property_changed)r„   rm   rk   rÏ   Ú	old_valuer4   r4   r5   r¸     s
    
zHasTraits._set_traits_cachec             C   s   | j || jjt| tƒƒ dS )z< Explicitly flushes the value of a cached property.
        N)r¬  rA   r&  r(   r)   )r„   rm   rk   r4   r4   r5   r¹     s    zHasTraits._flush_traits_cachec             C   sH  |d d… dkrH|dd … dkrH|dkr,t S |r4tS td| jj|f ƒ‚|dd … dkr†| j|d d… dƒ}|d k	r†|jdkr†t|ƒS | j}x¢|d	 D ]–}||d t	|ƒ… kr–|| }| j}t
|d
| ƒt
|d| ƒg}t|||ƒ |j|jdƒƒ dd„ |D ƒ}t	|ƒdk�r(t|ƒ}t|jdƒ|ƒ |S q–W td|| jjf ƒ‚d S )NrM   rN   r!  z!'%s' object has no attribute '%s'r   rn   r   r=   r}   z_%s_changedz	_%s_firedr³   c             S   s   g | ]}|d k	r|‘qS )Nr4   )r§   rµ   r4   r4   r5   r¨   M  s    z.HasTraits.__prefix_trait__.<locals>.<listcomp>zHTrait class look-up failed for attribute '%s' for an object of type '%s'r¨  r~   r~   )r   Ú	any_traitr4  r!  r1   r€  r[   rF   r9   r€   rL   r˜   rs   rP   r•   rÍ   ÚSystemError)r„   rm   Úis_setrE   rÓ   r�   rI   r”   r4   r4   r5   Ú__prefix_trait__   s:     zHasTraits.__prefix_trait__c             C   s   | j ||dƒ d S )NF)Ú_trait_listener)r„   rQ  r�   r4   r4   r5   Úadd_trait_listenerb  s    zHasTraits.add_trait_listenerc             C   s   | j ||dƒ d S )NT)r²  )r„   rQ  r�   r4   r4   r5   Úremove_trait_listenere  s    zHasTraits.remove_trait_listenerc             C   s   |d	d … dkr|d7 }t |ƒ}| j}xÔ| j|ƒD ]Æ}|d |… |kr2|d
d … dkr ||d… }||kr‚| jt||ƒ||d� n|dkrž| jt||ƒ|d� q2|d d… dkr2||d… }||krÜ| jt||ƒ||d� q2|dkr2| jt||ƒ|d� q2W d S )Nr   rn   é   Z_changed)r¢   rÞ   r´   Z_firedr~   iøÿÿÿiøÿÿÿiúÿÿÿiúÿÿÿ)r€   r7   r9  r  rG   )r„   rQ  r�   r¢   ry   r1  rm   Z
short_namer4   r4   r5   r²  h  s,    zHasTraits._trait_listenerc             c   sT   i }xJ|j jD ]>}x8|jjƒ D ]*\}}t|ƒtkr||krd||< |V  qW qW dS )zD Generates each (name, method) pair for a specified object.
        TN)r!  r  rA   rg   r[   r   )r„   rQ  r  rŸ   rm   rJ   r4   r4   r5   r9  ˆ  s    zHasTraits._each_trait_methodc             C   sT   | j |ƒ}|dk	r0x|D ]}|j|ddiŽ qW |dk	rPx|D ]}|j|Ž  q>W dS )zK Handles adding/removing listeners for a generic 'Instance' trait.
        Nr¢   T)r|   rO   )r„   rm   r›  r  rw   rø   r4   r4   r5   Ú_instance_changed_handler–  s    


z#HasTraits._instance_changed_handlerc             C   s`   | j |ƒ}x*|D ]"}x|D ]}|j|ddiŽ qW qW x$|D ]}x|D ]}|j|Ž  qFW q<W dS )z_ Handles adding/removing listeners for a generic 'List( Instance )'
            trait.
        r¢   TN)r|   rO   )r„   rm   r›  r  rw   rl   rø   r4   r4   r5   r®   §  s    




zHasTraits._list_changed_handlerc             C   sl   | j |dd… ƒ}x,|jD ]"}x|D ]}|j|ddiŽ q$W qW x&|jD ]}x|D ]}|j|Ž  qRW qHW dS )z_ Handles adding/removing listeners for a generic 'List( Instance )'
            trait.
        Nr´   r¢   Tiúÿÿÿ)r|   rž  rO   rŸ  )r„   rm   Únot_usedr<   rw   rl   rø   r4   r4   r5   r¯   µ  s    

z%HasTraits._list_items_changed_handlerc                s   ‡ fdd„ˆ j j| D ƒS )z{ Returns a list of ( name, method ) pairs for a specified 'Instance'
            or 'List( Instance )' trait name:
        c                s   g | ]\}}t ˆ |ƒ|f‘qS r4   )rG   )r§   Úmethod_nameÚ	item_name)r„   r4   r5   r¨   Í  s   z4HasTraits._get_instance_handlers.<locals>.<listcomp>)r!  r;   )r„   rm   r4   )r„   r5   r|   È  s    
z HasTraits._get_instance_handlersc             C   sZ   xT| j jjƒ D ]D\}}|d dkr|d }|d r| jt| |ƒ|d d|d d� qW d	S )
z¬ Initializes the object's statically parsed, but dynamically
            registered, traits listeners (called at object creation and
            unpickling times).
        r   rJ   r   ræ   rÚ   Trç   )rD  rç   N)r!  r:   rg   rO   rG   )r„   rm   ÚdataÚconfigr4   r4   r5   r*  Ø  s    z$HasTraits._post_init_trait_listenersc             C   s:   x4| j jjƒ D ]$\}}t| d|d  ƒ|f|žŽ  qW dS )z¬ Initializes the object's statically parsed, but dynamically
            registered, traits listeners (called at object creation and
            unpickling times).
        z_init_trait_%s_listenerr   N)r!  r:   rg   rG   )r„   rm   rº  r4   r4   r5   r)  è  s    zHasTraits._init_trait_listenersc             C   s,   |d s(| j t| |ƒ|d d|d d� dS )z\ Sets up the listener for a method with the @on_trait_change
            decorator.
        ræ   rÚ   Trç   )rD  rç   N)rO   rG   )r„   rm   rM  r»  r4   r4   r5   Ú_init_trait_method_listenerð  s    z%HasTraits._init_trait_method_listenerc                s(   t | ƒ‡ fdd„ƒ}| j||| d� dS )zJ Sets up the listener for an event with on_trait_change metadata.
        c                s   t | ˆ dƒ d S )NT)r  )r„   )rm   r4   r5   Únotify   s    z4HasTraits._init_trait_event_listener.<locals>.notify)r…  N)rï   rO   )r„   rm   rM  rÚ   r½  r4   )rm   r5   Ú_init_trait_event_listenerü  s    z$HasTraits._init_trait_event_listenerc                sx   ˆ dkrt | ƒ‡fdd„ƒ}nFˆ d ‰t | ƒ‡ ‡fdd„ƒ}| j||d| d� t | ƒ‡‡fd	d„ƒ}| j||| d
� dS )zI Sets up the listener for a property with 'depends_on' metadata.
        Nc                s   | j ˆ d ƒ d S )N)r¬  )r„   )rm   r4   r5   r½    s    z7HasTraits._init_trait_property_listener.<locals>.notifyz:oldc                s.   | j }|jˆtƒ}|tkr*|jˆ d ƒ|ˆ< d S )N)rA   rP   r)   r&  )r„   rf   r›  )rÏ   Ú
cached_oldr4   r5   Ú
pre_notify  s    z;HasTraits._init_trait_property_listener.<locals>.pre_notifyT)r„  r…  c                s&   | j jˆ tƒ}|tk	r"| jˆ|ƒ d S )N)rA   r&  r)   r¬  )r„   r›  )r¿  rm   r4   r5   r½    s    )r…  )rï   rO   )r„   rm   rM  rÏ   rÚ   r½  rÀ  r4   )rÏ   r¿  rm   r5   Ú_init_trait_property_listener  s    z'HasTraits._init_trait_property_listenerc                sZ   | j ˆ |ƒ}t|jdƒd ƒ‰t| ƒ‡ ‡fdd„ƒ}| j||| d� || jjti ƒˆ < dS )z4 Sets up the listener for a delegate trait.
        ru  r   c                s   | j ˆ |ˆd …  ||ƒ d S )N)r¬  )r„   rQ  Znotify_namer›  r  )rm   Útarget_name_lenr4   r5   r½  +  s    z7HasTraits._init_trait_delegate_listener.<locals>.notify)r…  Nr~   )Ú_trait_delegate_namer€   Úsplitrï   rO   rA   ru   rÂ   )r„   rm   rM  rÚ   Zname_patternr½  r4   )rm   rÂ  r5   r  %  s
    z'HasTraits._init_trait_delegate_listenerc             C   s†   | j jti ƒ}|r`||kr\| j|| | j|| jj| d ƒdd� ||= t|ƒdkr\| j t= dS ||kr‚| j|d| jj| d ƒ dS )zK Removes a delegate listener when the local delegate value is set.
        r   T)r¢   r   N)	rA   ru   rÂ   rO   rÃ  r!  r:   r€   r  )r„   rm   r¢   rf   r4   r4   r5   Ú_remove_trait_delegate_listener4  s    z)HasTraits._remove_trait_delegate_listenerc             C   s*   |d dkr&d|dd… | j j|f }|S )z_ Returns the fully-formed 'on_trait_change' name for a specified
            delegate.
        r   r}   z%s%s%sNr~   r~   )r!  Z
__prefix__)r„   rm   rÚ   r4   r4   r5   rÃ  R  s    
zHasTraits._trait_delegate_name)F)F)F)T)T)T)N)NNN)NNN)NNNNNrq   N)NN)NN)N)NNNTNNrq   N)F)NFrå   FN)NFrå   FFN)NTF)FF)rq   )rq   )_r1   r2   r3   r¤   r   Z_traits_cache__r!   r   r   r   r  r   rR   r–   r£  Ztrait_modifiedr  r  r¥   r  r	  r  r  r  r
  r  ri   r#  r%  r/  r  r/   rP   r(  rÊ   r2  r5  r7  r8  r;  rE  rG  rH  rP  rR  rI  rZ  rS  rT  rW  ra  rJ  rX  rn  ro  rq  rU  rY  r~  r  rO   Zon_trait_eventr•  r’  r“  r”  r‘  r   r¥  rE   r?  r©  r1  rÒ   r   rp  r¸   r¹   r±  r³  r´  r²  r9  r¶  r®   r¯   r|   r*  r)  r¼  r¾  rÁ  r  rÅ  rÃ  r4   r4   r4   r5   rh   P  s  
B@

5
(
0%
*
_
5      
=

/

H	
	       
g
7    
P     
  
_M+
'B2B

 
rh   c               @   s   e Zd ZdZeZdS )ÚHasStrictTraitsaÀ   This class guarantees that any object attribute that does not have an
    explicit or wildcard trait definition results in an exception.

    This feature can be useful in cases where a more rigorous software
    engineering approach is being used than is typical for Python programs. It
    also helps prevent typos and spelling mistakes in attribute names from
    going unnoticed; a misspelled attribute name typically causes an exception.
    N)r1   r2   r3   r¤   r   rn   r4   r4   r4   r5   rÆ  h  s   rÆ  c                   s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚHasRequiredTraitsað   This class builds on the functionality of HasStrictTraits and ensures
    that any object attribute with `required=True` in its metadata must be
    passed as an argument on object initialization.

    This can be useful in cases where an object has traits which are required
    for it to function correctly.

    Raises
    ------
    TraitError
        If a required trait is not passed as an argument.

    Usage
    -----
    A class with required traits:

    >>> class RequiredTest(HasRequiredTraits):
    ...     required_trait = Any(required=True)
    ...     non_required_trait = Any()

    Creating an instance of a HasRequiredTraits subclass:

    >>> test_instance = RequiredTest(required_trait=13, non_required_trait=11)
    >>> test_instance2 = RequiredTest(required_trait=13)

    Forgetting to specify a required trait:

    >>> test_instance = RequiredTest(non_required_trait=11)
    traits.trait_errors.TraitError: The following required traits were not
    provided: required_trait.
    c                sL   ‡ fdd„| j dd�D ƒ}|r6tdjdjt|ƒƒƒƒ‚tt| ƒjf ˆ Ž d S )Nc                s   g | ]}|ˆ kr|‘qS r4   r4   )r§   rm   )r1  r4   r5   r¨   ž  s   z.HasRequiredTraits.__init__.<locals>.<listcomp>T)Úrequiredz4The following required traits were not provided: {}.z, )r   r.   ÚformatrÐ   ÚsortedÚsuperrÇ  r…   )r„   r1  Zmissing_required_traits)r!  )r1  r5   r…   ›  s    
zHasRequiredTraits.__init__)r1   r2   r3   r¤   r…   Ú__classcell__r4   r4   )r!  r5   rÇ  z  s   rÇ  c               @   s    e Zd ZdZeddd�ZeZdS )ÚHasPrivateTraitsaJ   This class ensures that any public object attribute that does not have
    an explicit or wildcard trait definition results in an exception, but
    "private" attributes (whose names start with '_') have an initial value of
    **None**, and are not type-checked.

    This feature is useful in cases where a class needs private attributes to
    keep track of its internal object state, which are not part of the class's
    public API. Such attributes do not need to be type-checked, because they are
    manipulated only by the (presumably correct) methods of the class itself.
    T)r   r�   N)r1   r2   r3   r¤   r   rN   r   rn   r4   r4   r4   r5   rÍ  °  s   
rÍ  c               @   s   e Zd ZdZdS )ÚABCMetaHasTraitsz× A MetaHasTraits subclass which also inherits from
        abc.ABCMeta.

        .. note:: The ABCMeta class is cooperative and behaves nicely
            with MetaHasTraits, provided it is inherited first.
        N)r1   r2   r3   r¤   r4   r4   r4   r5   rÎ  Ê  s   rÎ  c               @   s   e Zd ZdZdS )ÚABCHasTraitsz­ A HasTraits subclass which enables the features of Abstract
        Base Classes (ABC). See the 'abc' module in the standard library
        for more information.

        N)r1   r2   r3   r¤   r4   r4   r4   r5   rÏ  Ô  s   rÏ  c               @   s   e Zd ZdZeZdS )ÚABCHasStrictTraitszÓ A HasTraits subclass which behaves like HasStrictTraits but
        also enables the features of Abstract Base Classes (ABC). See the
        'abc' module in the standard library for more information.

        N)r1   r2   r3   r¤   r   rn   r4   r4   r4   r5   rÐ  Ü  s   rÐ  c               @   s   e Zd ZdZdd„ ZdS )ÚSingletonHasTraitsz4 Singleton class that support trait attributes.
    c             O   s$   d| j krtj| f|ž|Ž| _| jS )NÚ_the_instance)rA   rh   r�   rÒ  )rI   rø   r1  r4   r4   r5   r�   ö  s    
zSingletonHasTraits.__new__N)r1   r2   r3   r¤   r�   r4   r4   r4   r5   rÑ  ò  s   rÑ  c               @   s   e Zd ZdZdd„ ZdS )ÚSingletonHasStrictTraitszq Singleton class that supports strict trait attributes.

        Non-trait attributes generate an exception.
    c             O   s   t j| f|ž|ŽS )N)rÑ  r�   )rI   rø   r1  r4   r4   r5   r�     s    z SingletonHasStrictTraits.__new__N)r1   r2   r3   r¤   r�   r4   r4   r4   r5   rÓ  ü  s   rÓ  c               @   s   e Zd ZdZdd„ ZdS )ÚSingletonHasPrivateTraitszf Singleton class that supports trait attributes, with private attributes
        being unchecked.
    c             O   s   t j| f|ž|ŽS )N)rÑ  r�   )rI   rø   r1  r4   r4   r5   r�     s    z!SingletonHasPrivateTraits.__new__N)r1   r2   r3   r¤   r�   r4   r4   r4   r5   rÔ    s   rÔ  c               @   s    e Zd ZdZedƒZdd„ ZdS )ÚVetoablezB Defines a 'vetoable' request object and an associated event.
    Fc             C   s   | j |ƒ d S )N)Z_trait_veto_notify)r„   r-  r4   r4   r5   Ú_veto_changed  s    zVetoable._veto_changedN)r1   r2   r3   r¤   r   ZvetorÖ  r4   r4   r4   r5   rÕ    s   rÕ  c               @   s$   e Zd ZdZedƒefdd„ƒZdS )ÚMetaInterfacezæ Meta class for interfaces.

    Interfaces are simple ABCs with the following features:-

    1) They cannot be instantiated (they are interfaces, not implementations!).
    2) Calling them is equivalent to calling 'adapt'.

    z'use "adapt(adaptee, protocol)" instead.c             C   s   ddl m} ||| |d�S )z  Attempt to adapt the adaptee to this interface.

        Note that this means that (intentionally ;^) that interfaces
        cannot be instantiated!

        r   )Úadapt)rÁ   )Ztraits.adaptation.apirØ  )r„   ZadapteerÁ   rØ  r4   r4   r5   r‡   0  s    	zMetaInterface.__call__N)r1   r2   r3   r¤   r/   r	   r‡   r4   r4   r4   r5   r×  &  s   r×  c               @   s   e Zd ZdZdS )Ú	Interfacez( The base class for all interfaces.
    N)r1   r2   r3   r¤   r4   r4   r4   r5   rÙ  C  s   rÙ  c                 sT   ddl m} tˆ ƒdkr dd„ S x"ˆ D ]}tt|ƒ|ƒs&tdƒ‚q&W ‡ fdd„}|S )zà Class decorator to declare the protocols that a class provides.

    Parameters
    ----------
    *protocols :
        A list of protocols (Interface classes or Python ABCs) that the
        decorated class provides.

    r   )ÚABCMetac             S   s   | S )Nr4   )rŸ   r4   r4   r5   r²   ]  s    zprovides.<locals>.<lambda>zOAll arguments to 'provides' must be subclasses of Interface or be a Python ABC.c                s>   xˆ D ]}t |ƒj|| ƒ qW tr:ddlm} || ˆ tƒ | S )Nr   )Úcheck_implements)r[   r�  ÚCHECK_INTERFACESZinterface_checkerrÛ  )rŸ   r$  rÛ  )Ú	protocolsr4   r5   Úwrapped_classg  s    
zprovides.<locals>.wrapped_class)ÚabcrÚ  r€   rˆ   r[   r.   )rÝ  rÚ  r$  rÞ  r4   )rÝ  r5   ÚprovidesN  s    

rà  c             C   s
   t | tƒS )z+ Return True if the class is an Interface. )r]   r×  )rŸ   r4   r4   r5   Úisinterface}  s    rá  c               @   s   e Zd ZdZdS )rj   z‘ A class that implemented ISerializable requires that all HasTraits
        objects saved as part of its state also implement ISerializable.
    N)r1   r2   r3   r¤   r4   r4   r4   r5   rj   ˆ  s   rj   c                   s$   e Zd Z‡ fdd„Zdd„ Z‡  ZS )Útraits_superc          	      s"   yt t| ƒj|ƒS    | jS d S )N)rË  râ  Ú__getattribute__Ú_noop)r„   rm   )r!  r4   r5   rã  ”  s    ztraits_super.__getattribute__c             O   s   d S )Nr4   )r„   rø   Úkwr4   r4   r5   rä  š  s    ztraits_super._noop)r1   r2   r3   rã  rä  rÌ  r4   r4   )r!  r5   râ  “  s   râ  )r<   r=   r>   )r=   r?   )N)Frå   )FF)‰r¤   Ú
__future__r   r   r   rB   r@  rþ   ÚreÚtypesr   r   rR   rq   r   r"  Zadaptation.adaptation_errorr	   Zctraitsr
   r   r1  r   r   r   r   r   r   r   r   r   Ztrait_typesr   r   r   r   r   r   r   Ztrait_notifiersr   r   r   r   r    r!   Ztrait_handlersr"   r#   r$   r%   Z
trait_baser&   r'   r(   r)   r*   r+   r,   r-   Ztrait_errorsr.   Zutil.deprecatedr/   rÜ  rQ  r0   r6   r’   ÚPY2r^   r`   ra   rÃ   r¦   rÆ   rÂ   rÇ   rr   r`  rÀ   Z	EmptyListr>  Úcompiler‹  r‰   r®  rF   rL   rX   r\   r_   rH   rQ   re   r|   r‚   rƒ   rŠ   r‹   r‘   r•   r˜   r™   Z
_HasTraitsr[   rš   rœ   rÅ   rä   rO   rê   rí   rï   Úadd_metaclassrh   rÆ  rÇ  rÍ  rß  rÚ  rÎ  rÏ  rÐ  ÚImportErrorrÑ  rÓ  rÔ  rÕ  ZVetoableEventr×  rÙ  rà  rá  rj   rË  râ  r4   r4   r4   r5   Ú<module>   sâ   ,$ 	(	


,5  V
-
2A                    $6




/