a
    ¦ˆcv'  ã                   @   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 urt S t | ¡}|S d S ©N)ÚUninitializedÚobjectÚ__new__©ÚclsÚself© r   úT/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/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 dfS ©Nr   )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 urt S t | ¡}|S d S r
   )Ú	Undefinedr   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 dfS r   )r   r   r   r   r   r   d   s    z_Undefined.__reduce_ex__c                 C   s   t | ƒt |ƒu S r
   ©Útype©r   Úotherr   r   r   Ú__eq__g   s    z_Undefined.__eq__c                 C   s   t t| ƒƒS r
   )Úhashr    r   r   r   r   Ú__hash__j   s    z_Undefined.__hash__c                 C   s   t | ƒt |ƒuS 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__Nr(   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    r1   c                 C   s@   t |tjƒrt | tjƒsdS z
| |v W S  ty:   Y dS 0 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    	
r7   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    
r:   c                 C   s$   | dd…   ¡ dv 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   r8   Æ   s    r8   c                 C   sJ   |   dd¡} d}d}| D ](}| ¡ r0|r0|d7 }| ¡ }||7 }q| ¡ 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)r<   ÚresultZ
last_lowerÚcr   r   r   Úuser_name_forÐ   s    
rF   c                   C   s   t du 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    rI   c                 C   s(   t | ƒs$zt | ¡ W n   Y n0 | S )z] Verify that a specified path exists, and try to create it if it
        does not exist.
    )r   ÚosÚmkdir)Úpathr   r   r   rH   ð   s    rH   é   c                 C   s   t  | ¡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    rT   c                 C   sú   t  | ¡j dd¡}d}|dkrHzttt j |¡dƒƒ}W n   Y n0 |du rvtt jd ƒtƒ fD ]}t	|ƒrd qvqdtt ddƒ}|röt
t dƒr˜t j}n:|d	kr¬tjd
 }n&|dv rÄtj t j¡}ntj t j¡}d|v rö| d¡\}}tj ||¡}|S )z@Returns a resource path calculated from the caller's stack.
    r   rN   NÚ__file__r   ÚfrozenFÚ_MEIPASSZ
macosx_appZRESOURCEPATH)ÚdllZwindows_exeZconsole_exez.zip/)rO   rP   rQ   rR   r   ÚgetattrÚmodulesÚargvr   r   ÚhasattrrW   rJ   ÚenvironrL   Ú
executableÚsplitr   )rS   ÚmodulerL   rV   ÚrootÚzippathZ
image_pathr   r   r   Úget_resource_path  s0    	
rc   c                 C   sr   |  d¡}|dd… D ]4}|tu r.t| |ƒ} qt| |dƒ} | du r|  S q|tu rbt| |d ƒS t| |d |ƒS )zj Returns the value of an extended object attribute name of the form:
        name[.name2[.name3...]].
    Ú.Néÿÿÿÿ)r_   r   rY   )r   ÚxnameÚdefaultÚnamesr<   r   r   r   Úxgetattr1  s    

ri   c                 C   s:   |  d¡}|dd… D ]}t| |ƒ} qt| |d |ƒ dS )zg Sets the value of an extended object attribute name of the form:
        name[.name2[.name3...]].
    rd   Nre   )r_   rY   Úsetattr)r   rf   r5   rh   r<   r   r   r   ÚxsetattrD  s    
rk   c                    s   ‡ ‡fdd„}|S )Nc                    s    ˆƒ }|d ur|  ˆ td ¡ d S r
   )Ztrait_property_changedr   )Z	value_refr   ©r<   Ú
object_refr   r   Ú_value_freedR  s    z0_make_value_freed_callback.<locals>._value_freedr   )rm   r<   rn   r   rl   r   Ú_make_value_freed_callbackQ  s    ro   c                   @   s   e Zd Zdd„ ZdS )ÚHandleWeakRefc                 C   s.   t |ƒ}t||ƒ}|| _|| _t ||ƒ| _d S r
   )r   ro   r   r<   r5   )r   r   r<   r5   rm   rn   r   r   r   Ú__init__[  s
    
zHandleWeakRef.__init__N)r   r   r   rq   r   r   r   r   rp   Z  s   rp   c                 C   s   | d u S r
   r   ©r5   r   r   r   Úis_nonec  s    rs   c                 C   s   | d uS r
   r   rr   r   r   r   Únot_noneg  s    rt   c                 C   s   | duS )NFr   rr   r   r   r   Ú	not_falsek  s    ru   c                 C   s   | dkS )NÚeventr   rr   r   r   r   Ú	not_evento  s    rw   c                 C   s
   t | tƒS r
   )r*   r,   rr   r   r   r   Úis_strs  s    rx   )rM   )rM   )7r   r2   rJ   rO   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+   r1   r7   r:   r8   rF   rG   rI   rH   rT   rc   ri   rk   ro   rp   rs   rt   ru   rw   rx   r   r   r   r   Ú<module>   sh   ø"
	


.		