a
    õ£BeÀ:  ã                   @   s$  d Z ddlZddlZddlZddlZddlZddlZddlZg d¢Zej	d dkZ
eƒ Ze
r‚eZeZeZeZeZdd„ Zdd„ Zn eZeZeZeZd	d„ Zd
d„ Ze
r¬eZneZeedfdd„Ze
rÞeZeZeZeZeZeZnÂddlZefdd„Z e e!ƒdd„ ƒZe e!ƒdd„ ƒZe e!ƒdd„ ƒZe e!ƒdd„ ƒZe e!ƒdd„ ƒZe e!ƒdd„ ƒZe "¡ dk�r ze#ej$dƒ‚W n. e�y„   Y n e#�yž   e%dƒ‚Y n0 zddlm&Z& W n˜ e'�yH   zdd l(m)Z) W n  e'�yð   dd l*m)Z) Y n0 e +d!g d"¢¡Z,G d#d$„ d$e-ƒZ.efe/eee0e1dƒfƒe2e3e1e4fd%d&„Z5d8d)d*„Z&Y n0 zdd+l6m7Z7 W n* e'�y„   ej8ej9B dfd,d-„Z7Y n0 zdd.l6m:Z: W n e'�y´   d9d0d1„Z:Y n0 zdd2l;m<Z= W n$ e'�yê   G d3d4„ d4eƒZ=Y n0 zdd5lm>Z> W n" e'�y   ej?d6d7„ ƒZ>Y n0 dS ):z¦Module which provides compatibility with older Python versions.
This is more future-compatible rather than the opposite (prefer latest
Python 3 way of doing things).
é    N)ÚPY3ÚlongÚrangeÚsuperÚunicodeÚ
basestringÚuÚbÚ	lru_cacheÚwhichÚget_terminal_sizeÚredirect_stderrÚFileNotFoundErrorÚPermissionErrorÚProcessLookupErrorÚInterruptedErrorÚChildProcessErrorÚFileExistsErroré   c                 C   s   | S ©N© ©Úsr   r   úQ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/psutil/_compat.pyr   /   s    r   c                 C   s
   |   d¡S )Nzlatin-1)Úencoder   r   r   r   r	   2   s    r	   c                 C   s
   t | dƒS )NÚunicode_escape)r   r   r   r   r   r   :   s    c                 C   s   | S r   r   r   r   r   r   r	   =   s    é   c                 C   sX  | t u �r<t |¡}z|j|jjd  }W n ttfyH   tdƒ‚Y n0 z
|j	}W n> t
tfy’   z|jj	}W n t
yŒ   tdƒ‚Y n0 Y n0 |D ]š} | j ¡ D ]‚}zNt|tjƒsöt|tƒrÊ|j}q¬z
|j}W q¬ t
yò   | || ¡}Y q¬0 q¬W n t
tf�y   Y q¦Y n0 |j|ju r¦ �q,q¦q˜ �q<q˜tdƒ‚|t u�rPt| |ƒS t| ƒS )zuLike Python 3 builtin super(). If called without any arguments
        it attempts to infer them at runtime.
        r   z'super() used in a function with no argsz$super() used in a non-newstyle classzsuper() called outside a method)Ú	_SENTINELÚsysÚ	_getframeÚf_localsÚf_codeÚco_varnamesÚ
IndexErrorÚKeyErrorÚRuntimeErrorÚ__mro__ÚAttributeErrorÚ	__class__Ú__dict__ÚvaluesÚ
isinstanceÚtypesÚFunctionTypeÚpropertyÚfgetÚ__func__Ú__get__Ú	TypeErrorÚ	func_codeÚ_builtin_super)Útype_Ztype_or_objZ
framedepthÚfÚmroÚmethr   r   r   r   L   sB    







r   c                    s   ‡ fdd„}|S )Nc                    s*   G ‡ ‡fdd„dˆƒ‰ ˆj ˆ _ ˆjˆ _ˆ S )Nc                       s2   e Zd Z‡‡ fdd„ZG ‡fdd„deƒZ‡  ZS )zE_instance_checking_exception.<locals>.wrapped.<locals>.TemporaryClassc                    sh   t |ƒdkrNt|d ˆ ƒrN|d }t|ƒD ] }| d¡s*t| |t||ƒƒ q*ntˆ | ƒj|i |¤Ž d S )Nr   r   Ú__)Úlenr+   ÚdirÚ
startswithÚsetattrÚgetattrr   Ú__init__)ÚselfÚargsÚkwargsZ	unwrap_meÚattr)ÚTemporaryClassr(   r   r   r?   ”   s    
zN_instance_checking_exception.<locals>.wrapped.<locals>.TemporaryClass.__init__c                       s    e Zd Z‡ fdd„Zdd„ ZdS )zS_instance_checking_exception.<locals>.wrapped.<locals>.TemporaryClass.__metaclass__c                    s   ˆ |ƒS r   r   )ÚclsÚinst©Úinstance_checkerr   r   Ú__instancecheck__ž   s    ze_instance_checking_exception.<locals>.wrapped.<locals>.TemporaryClass.__metaclass__.__instancecheck__c                 S   s   t  ¡ d }t|| ƒS ©Nr   )r   Úexc_infor+   )rE   Z	classinfoÚvaluer   r   r   Ú__subclasscheck__¡   s    ze_instance_checking_exception.<locals>.wrapped.<locals>.TemporaryClass.__metaclass__.__subclasscheck__N)Ú__name__Ú
__module__Ú__qualname__rI   rM   r   rG   r   r   Ú__metaclass__�   s   rQ   )rN   rO   rP   r?   ÚtyperQ   Ú__classcell__r   ©rD   rH   )r(   r   rD   ’   s   	rD   )rN   Ú__doc__rG   ©Úbase_exceptionrT   r   Úwrapped‘   s    z-_instance_checking_exception.<locals>.wrappedr   )rW   rX   r   rV   r   Ú_instance_checking_exception�   s    rY   c                 C   s   t | dtƒtjkS ©NÚerrno)r>   r   r[   ÚENOENT©rF   r   r   r   r   «   s    r   c                 C   s   t | dtƒtjkS rZ   )r>   r   r[   ZESRCHr]   r   r   r   r   ¯   s    r   c                 C   s   t | dtƒtjtjfv S rZ   )r>   r   r[   ÚEACCESÚEPERMr]   r   r   r   r   ³   s    
ÿr   c                 C   s   t | dtƒtjkS rZ   )r>   r   r[   ZEINTRr]   r   r   r   r   ¸   s    r   c                 C   s   t | dtƒtjkS rZ   )r>   r   r[   ZECHILDr]   r   r   r   r   ¼   s    r   c                 C   s   t | dtƒtjkS rZ   )r>   r   r[   ÚEEXISTr]   r   r   r   r   À   s    r   ÚCPythonÚpermzbbroken or incompatible Python implementation, see: https://github.com/giampaolo/psutil/issues/1659)r
   )ÚRLockÚ	CacheInfo)ÚhitsÚmissesÚmaxsizeÚcurrsizec                   @   s$   e Zd ZdZefdd„Zdd„ ZdS )Ú
_HashedSeq©Ú	hashvaluec                 C   s   || d d …< ||ƒ| _ d S r   rj   )r@   ÚtupÚhashr   r   r   r?   ã   s    z_HashedSeq.__init__c                 C   s   | j S r   rj   )r@   r   r   r   Ú__hash__ç   s    z_HashedSeq.__hash__N)rN   rO   rP   Ú	__slots__rm   r?   rn   r   r   r   r   ri   à   s   ri   c	                    s˜   | }	|r.||  ¡ ƒ}
|	|7 }	|
D ]}|	|7 }	q |rl|	|‡ fdd„| D ƒƒ7 }	|r�|	|‡ fdd„|
D ƒƒ7 }	n$||	ƒdkr�ˆ |	d ƒ|v r�|	d S t|	ƒS )Nc                 3   s   | ]}ˆ |ƒV  qd S r   r   )Ú.0Úv©rR   r   r   Ú	<genexpr>õ   ó    z_make_key.<locals>.<genexpr>c                 3   s   | ]\}}ˆ |ƒV  qd S r   r   )rp   Úkrq   rr   r   r   rs   ÷   rt   r   r   )Úitemsri   )rA   ÚkwdsÚtypedÚkwd_markÚ	fasttypesÚsortedÚtuplerR   r:   ÚkeyÚsorted_itemsÚitemr   rr   r   Ú	_make_keyê   s    
r€   éd   Fc                    s   ‡ ‡fdd„}|S )zLeast-recently-used cache decorator, see:
        http://docs.python.org/3/library/functools.html#functools.lru_cache.
        c                    s  i ‰ddg‰d\‰ ‰t ‰
ˆj‰t‰tƒ ‰	g ‰ˆˆd d gˆd d …< ˆg‰d\‰‰‰‰ˆdkrl‡‡‡fdd„}nPˆd u r’‡ ‡‡‡‡
‡‡‡‡f	dd„}n*‡ ‡‡‡‡‡‡‡‡‡	‡
‡‡‡‡‡fdd„}‡ ‡‡‡	‡‡fdd	„}‡‡	‡‡fd
d„}ˆ|_||_||_t |ˆ¡S )Nr   )r   r   )r   r   é   r   c                     s"   ˆ| i |¤Ž}ˆˆ   d7  < |S rJ   r   )rA   rw   Úresult)ÚMISSESÚstatsÚuser_functionr   r   Úwrapper  s    z7lru_cache.<locals>.decorating_function.<locals>.wrapperc                     s\   ˆ| |ˆƒ}ˆ|ˆƒ}|ˆur2ˆˆ   d7  < |S ˆ| i |¤Ž}|ˆ|< ˆˆ  d7  < |S rJ   r   )rA   rw   r}   rƒ   )	ÚHITSr„   ÚcacheÚ	cache_getÚmake_keyÚrootr…   rx   r†   r   r   r‡     s    
c                     sŠ  |sˆrˆ
| |ˆƒ}n| }ˆ	  ¡  z„ˆ|ƒ}|d urœˆ\}|\}}}}||ˆ< ||ˆ< |ˆ }| |ˆ< |ˆ< ||ˆ< ||ˆ< ˆˆ   d7  < |W ˆ	 ¡  S W ˆ	 ¡  n
ˆ	 ¡  0 ˆ| i |¤Ž}ˆ	  ¡  z²ˆ\}|ˆv rÚn†ˆˆƒˆk�r4|}	||	ˆ< ||	ˆ< |	ˆ  }ˆd< |ˆ }
d  |ˆ< |ˆ< ˆ|
= |	ˆ|< n,|ˆ }||||g}| |ˆ<  |ˆ< ˆ|< ˆˆ  d7  < W ˆ	 ¡  n
ˆ	 ¡  0 |S )Nr   r   )ÚacquireÚrelease)rA   rw   r}   ÚlinkrŒ   Z	link_prevZ	link_nextrƒ   ÚlastZoldrootZoldkey)rˆ   ÚKEYr„   ÚNEXTÚPREVÚRESULTÚ_lenr‰   rŠ   Úlockr‹   rg   Únonlocal_rootr…   rx   r†   r   r   r‡     sR    þ
c                      s<   ˆ  ¡  z$tˆˆ  ˆˆ ˆtˆƒƒW ˆ ¡  S ˆ ¡  0 dS )zReport cache statistics.N)r�   Ú
_CacheInfor:   rŽ   r   )rˆ   r„   r‰   r–   rg   r…   r   r   Ú
cache_infoJ  s    ÿýz:lru_cache.<locals>.decorating_function.<locals>.cache_infoc                     sX   ˆ  ¡  z@ˆ  ¡  ˆd } | | ddg| dd…< ddgˆdd…< W ˆ ¡  n
ˆ ¡  0 dS )z%Clear the cache and cache statistics.r   N)r�   ÚclearrŽ   )rŒ   )r‰   r–   r—   r…   r   r   Úcache_clearS  s    z;lru_cache.<locals>.decorating_function.<locals>.cache_clear)	r€   Úgetr:   rc   Ú__wrapped__r™   r›   Ú	functoolsÚupdate_wrapper)r†   r‡   r™   r›   ©rg   rx   )rˆ   r‘   r„   r’   r“   r”   r•   r‰   rŠ   r–   r‹   r—   rŒ   r…   r†   r   Údecorating_function   s,    *-	z&lru_cache.<locals>.decorating_functionr   )rg   rx   r¡   r   r    r   r
   ü   s    cr
   )r   c                    s"  dd„ }t j ˆ ¡r&|ˆ |ƒr"ˆ S dS |du r>t j dt j¡}|sFdS | t j¡}tj	dkr¼t j
|vrt| dt j
¡ t j dd¡ t j¡}t‡ fd	d
„|D ƒƒr¨ˆ g}qÂ‡ fdd„|D ƒ}nˆ g}tƒ }|D ]P}t j |¡}||vrÌ| |¡ |D ](}	t j ||	¡}
||
|ƒrò|
    S qòqÌdS )aJ  Given a command, mode, and a PATH string, return the path which
        conforms to the given mode on the PATH, or None if there is no such
        file.

        `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
        of os.environ.get("PATH"), or can be overridden with a custom search
        path.
        c                 S   s&   t j | ¡o$t  | |¡o$t j | ¡ S r   )ÚosÚpathÚexistsÚaccessÚisdir)ÚfnÚmoder   r   r   Ú_access_checks  s    ÿzwhich.<locals>._access_checkNÚPATHÚwin32r   ÚPATHEXTÚ c                 3   s    | ]}ˆ   ¡  |  ¡ ¡V  qd S r   )ÚlowerÚendswith©rp   Úext©Úcmdr   r   rs   ‡  rt   zwhich.<locals>.<genexpr>c                    s   g | ]}ˆ | ‘qS r   r   r°   r²   r   r   Ú
<listcomp>Š  rt   zwhich.<locals>.<listcomp>)r¢   r£   ÚdirnameÚenvironrœ   ÚdefpathÚsplitÚpathsepr   ÚplatformÚcurdirÚinsertÚanyÚsetÚnormcaseÚaddÚjoin)r³   r¨   r£   r©   ÚpathextÚfilesÚseenr;   ÚnormdirÚthefileÚnamer   r²   r   r   j  s8    	




r   )r   ©éP   é   c                 C   sz   zdd l }dd l}dd l}W n ty2   |  Y S 0 z*| d| d|jd¡¡}|d |d fW S  tyt   |  Y S 0 d S )Nr   Úhhr   Ú1234)ÚfcntlÚstructÚtermiosÚImportErrorÚunpackÚioctlÚ
TIOCGWINSZÚ	Exception)ÚfallbackrÍ   rÎ   rÏ   Úresr   r   r   r   ž  s    
ÿr   )ÚTimeoutExpiredc                   @   s   e Zd ZdS )ÚSubprocessTimeoutExpiredN)rN   rO   rP   r   r   r   r   rØ   ³  s   rØ   )r   c                 c   s*   t j}z| t _| V  W |t _n|t _0 d S r   )r   Ústderr)Ú
new_targetÚoriginalr   r   r   r   »  s
    r   )r�   F)rÈ   )@rU   ÚcollectionsÚ
contextlibr[   rž   r¢   r   r,   Ú__all__Úversion_infor   Úobjectr   Úintr   r   ÚxrangeÚstrr   r   r   r	   r   r4   r   r   r   r   r   r   rº   rÔ   rY   ÚEnvironmentErrorÚpython_implementationÚOSErrorr`   r%   r
   rÐ   Ú	threadingrc   Zdummy_threadingÚ
namedtupler˜   Úlistri   r¾   Ú	frozensetrR   r{   r|   r:   r€   Úshutilr   ÚF_OKÚX_OKr   Ú
subprocessr×   rØ   r   Úcontextmanagerr   r   r   r   Ú<module>   s¶   

8





ÿ
ÿý
k1