3
ˆdv'  ã               @   s¤  d Z ddlZddlZddlZddlmZ ddlmZmZmZ ddl	m
Z
 ddlmZ eefZeefZeefZeeeeeeeefZdZd	ZdZG d
d„ deƒZeƒ ZdZG dd„ deƒZeƒ ZG dd„ deƒZ e ƒ Z G dd„ deƒZ!e!ƒ Z!dd„ Z"eeeefZ#dd„ Z$dd„ Z%dd„ Z&dd„ Z'dd„ Z(da)dd„ Z*d d!„ Z+d9d#d$„Z,d:d%d&„Z-efd'd(„Z.d)d*„ Z/d+d,„ Z0G d-d.„ d.eƒZ1d/d0„ Z2d1d2„ Z3d3d4„ Z4d5d6„ Z5d7d8„ Z6dS );zF Defines common, low-level capabilities needed by the Traits package.
é    N)Úgetcwd)ÚdirnameÚexistsÚjoin)Úrefé   )Ú	ETSConfigZ__trait_notifier__Z_traits_cache_c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú_Uninitializedzò The singleton value of this class represents the uninitialized state
        of a trait and is specified as the 'old' value in the trait change
        notification that occurs when the value of a trait is read before being
        set.
    c             C   s   t d k	rt S tj| ƒ}|S d S )N)ÚUninitializedÚobjectÚ__new__)ÚclsÚself© r   ú3/tmp/pip-build-7vycvbft/traits/traits/trait_base.pyr   :   s    
z_Uninitialized.__new__c             C   s   dS )Nz<uninitialized>r   )r   r   r   r   Ú__repr__A   s    z_Uninitialized.__repr__c             C   s   t f fS )N)r	   )r   Úprotocolr   r   r   Ú__reduce_ex__D   s    z_Uninitialized.__reduce_ex__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r	   3   s   r	   c               @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )Ú
_UndefinedzS Singleton 'Undefined' object (used as undefined trait name and/or
    value).
    c             C   s   t d k	rt S tj| ƒ}|S d S )N)Ú	Undefinedr   r   )r   r   r   r   r   r   Z   s    
z_Undefined.__new__c             C   s   dS )Nz<undefined>r   )r   r   r   r   r   a   s    z_Undefined.__repr__c             C   s   t f fS )N)r   )r   r   r   r   r   r   d   s    z_Undefined.__reduce_ex__c             C   s   t | ƒt |ƒkS )N)Útype)r   Úotherr   r   r   Ú__eq__g   s    z_Undefined.__eq__c             C   s   t t| ƒƒS )N)Úhashr   )r   r   r   r   Ú__hash__j   s    z_Undefined.__hash__c             C   s   t | ƒt |ƒk	S )N)r   )r   r   r   r   r   Ú__ne__m   s    z_Undefined.__ne__N)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   U   s   r   c               @   s   e Zd ZdZdd„ ZdS )ÚMissingzJ Singleton 'Missing' object (used as missing method argument marker).
    c             C   s   dS )Nz	<missing>r   )r   r   r   r   r   ~   s    zMissing.__repr__N)r   r   r   r   r   r   r   r   r   r    z   s   r    c               @   s   e Zd ZdZdd„ ZdS )ÚSelfzM Singleton 'Self' object (used as object reference to current 'object').
    c             C   s   dS )Nz<self>r   )r   r   r   r   r   ‹   s    zSelf.__repr__N)r   r   r   r   r   r   r   r   r   r!   ‡   s   r!   c             C   s   t | tƒrt| ƒS t‚dS )zq Wraps the built-in str() function to raise a TypeError if the
    argument is not of a type in StringTypes.
    N)Ú
isinstanceÚStringTypesÚstrÚ	TypeError)Úargr   r   r   Ústrx“   s    
r'   c             C   s   | S )zE Item validator which accepts any item and returns it unaltered.
    r   )Úitemr   r   r   Ú_validate_everything¢   s    r)   c             C   s>   t |tjƒrt | tjƒsdS y| |kS  tk
r8   dS X dS )a   Perform "in" containment check, allowing for TypeErrors.

    This is required because in some circumstances ``x in y`` can raise a
    TypeError.  In these cases we make the (reasonable) assumption that the
    value is _not_ contained in the container.
    FN)r"   ÚenumÚEnumMetaÚEnumr%   )ÚvalueÚ	containerr   r   r   Úsafe_contains¨   s    	r/   c             C   s   t | tƒrt| ƒS t| jjƒS )z§ Returns a string containing the class name of an object with the
    correct indefinite article ('a' or 'an') preceding it (e.g., 'an Image',
    'a PlotValue').
    )r"   r$   Úadd_articleÚ	__class__r   )r   r   r   r   Úclass_of»   s    
r2   c             C   s$   | dd… j ƒ dkrd|  S d|  S )zt Returns a string containing the correct indefinite article ('a' or
    'an') prefixed to the specified string.
    Nr   Zaeiouzan za )Úlower)Únamer   r   r   r0   Æ   s    r0   c             C   sN   | j ddƒ} d}d}x0| D ](}|jƒ r2|r2|d7 }|jƒ }||7 }qW |jƒ S )zÞ Returns a "user-friendly" version of a string, with the first letter
    capitalized and with underscore characters replaced by spaces. For example,
    ``user_name_for('user_name_for')`` returns ``'User name for'``.
    Ú_ú Ú F)ÚreplaceÚisupperÚislowerÚ
capitalize)r4   ÚresultZ
last_lowerÚcr   r   r   Úuser_name_forÐ   s    
r>   c               C   s   t dkrtttjdƒƒa t S )z1 Gets the path to the Traits home directory.
    NZtraits)Ú_traits_homeÚverify_pathr   r   Zapplication_datar   r   r   r   Útraits_homeå   s    rA   c          	   C   s(   t | ƒs$ytj| ƒ W n   Y nX | S )z] Verify that a specified path exists, and try to create it if it
        does not exist.
    )r   ÚosÚmkdir)Úpathr   r   r   r@   ð   s    r@   é   c             C   s   t j| ƒjjddƒS )zL Returns the name of the module that the caller's caller is located in.
    r   Ú__main__)ÚsysÚ	_getframeÚ	f_globalsÚget)Úlevelr   r   r   Úget_module_nameý   s    rL   c          
   C   sü   t j| ƒjjddƒ}d}|dkrHyttt jj|ƒdƒƒ}W n   Y nX |dkrxx&tt jd ƒtƒ gD ]}t	|ƒrfP qfW tt ddƒ}|røt
t dƒršt j}n:|d	kr®tjd
 }n&|dkrÆtjjt jƒ}ntjjt jƒ}d|krø|jdƒ\}}tjj||ƒ}|S )z@Returns a resource path calculated from the caller's stack.
    r   rF   NÚ__file__r   ÚfrozenFÚ_MEIPASSZ
macosx_appZRESOURCEPATHÚdllÚwindows_exeÚconsole_exez.zip/)rP   rQ   rR   )rG   rH   rI   rJ   r   ÚgetattrÚmodulesÚargvr   r   ÚhasattrrO   rB   ÚenvironrD   Ú
executableÚsplitr   )rK   ÚmodulerD   rN   ÚrootÚzippathZ
image_pathr   r   r   Úget_resource_path  s0    	
r]   c             C   sr   |j dƒ}x@|dd… D ]0}|tkr0t| |ƒ} qt| |dƒ} | dkr|S qW |tkrbt| |d ƒS t| |d |ƒS )zj Returns the value of an extended object attribute name of the form:
        name[.name2[.name3...]].
    Ú.Nr   éÿÿÿÿr_   r_   )rY   r   rS   )r   ÚxnameÚdefaultÚnamesr4   r   r   r   Úxgetattr1  s    
rc   c             C   s>   |j dƒ}x|dd… D ]}t| |ƒ} qW t| |d |ƒ dS )zg Sets the value of an extended object attribute name of the form:
        name[.name2[.name3...]].
    r^   Nr   r_   r_   )rY   rS   Úsetattr)r   r`   r-   rb   r4   r   r   r   ÚxsetattrD  s    
re   c                s   ‡ ‡fdd„}|S )Nc                s    ˆƒ }|d k	r|j ˆ td ƒ d S )N)Ztrait_property_changedr   )Z	value_refr   )r4   Ú
object_refr   r   Ú_value_freedR  s    z0_make_value_freed_callback.<locals>._value_freedr   )rf   r4   rg   r   )r4   rf   r   Ú_make_value_freed_callbackQ  s    rh   c               @   s   e Zd Zdd„ ZdS )ÚHandleWeakRefc             C   s.   t |ƒ}t||ƒ}|| _|| _t ||ƒ| _d S )N)r   rh   r   r4   r-   )r   r   r4   r-   rf   rg   r   r   r   Ú__init__[  s
    
zHandleWeakRef.__init__N)r   r   r   rj   r   r   r   r   ri   Z  s   ri   c             C   s   | d kS )Nr   )r-   r   r   r   Úis_nonec  s    rk   c             C   s   | d k	S )Nr   )r-   r   r   r   Únot_noneg  s    rl   c             C   s   | dk	S )NFr   )r-   r   r   r   Ú	not_falsek  s    rm   c             C   s   | dkS )NÚeventr   )r-   r   r   r   Ú	not_evento  s    ro   c             C   s
   t | tƒS )N)r"   r$   )r-   r   r   r   Úis_strs  s    rp   )rE   )rE   )7r   r*   rB   rG   r   Úos.pathr   r   r   Úweakrefr   Zetsconfig.apir   ÚlistÚtupleZSequenceTypesÚfloatÚintZComplexTypesZ
RangeTypesr$   ÚcomplexÚdictÚboolZ	TypeTypesZTraitNotifierZTraitsCacher
   r   r	   r   r   r    r!   r'   r#   r)   r/   r2   r0   r>   r?   rA   r@   rL   r]   rc   re   rh   ri   rk   rl   rm   ro   rp   r   r   r   r   Ú<module>   sf   "
	


.		