o
    ˆ¶¹aÃ:  ã                   @   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
rAe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
rVeZn
eZeedfdd„Ze
roeZeZeZeZeZeZnZd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ƒ‚ ey¾   Y n e#yÈ   e%dƒ‚w zddlm&Z& W nL e'�y   zdd l(m)Z) W n e'yð   dd l*m)Z) Y nw 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w zdd+l6m7Z7 W n e'�y;   ej8ej9B dfd,d-„Z7Y nw zdd.l6m:Z: W n e'�yS   d9d0d1„Z:Y nw zdd2l;m<Z= W n e'�ym   G d3d4„ d4ƒZ=Y nw z	dd5lm>Z> W dS  e'�y‰   ej?d6d7„ ƒZ>Y dS w ):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 ©N© ©Úsr   r   ú0/usr/lib/python3/dist-packages/psutil/_compat.pyr   /   ó   r   c                 C   s
   |   d¡S )Nzlatin-1)Úencoder   r   r   r   r	   2   ó   
r	   c                 C   s
   t | dƒS )NÚunicode_escape)r   r   r   r   r   r   :   r   c                 C   r   r   r   r   r   r   r   r	   =   r   é   c                 C   sJ  | t u r˜t |¡}z|j|jjd  }W n ttfy!   tdƒ‚w z|j	}W n t
tfyD   z|jj	}W n t
yA   tdƒ‚w Y nw |D ]L} | j ¡ D ]B}z,t|tjƒs{t|tƒr`|j}nz|j}W n t
yt   | || ¡}Y nw t|tjƒrWW n t
tfy‡   Y qNw |j|ju r� nqNqG ntdƒ‚|t ur¡t| |ƒ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_Útype_or_objÚ
framedepthÚfÚmroÚmethr   r   r   r   L   sT   
ÿ
ÿÿþ

ÿ÷€ÿÿ
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                    sj   t |ƒdkr(t|d ˆ ƒr(|d }t|ƒD ]}| d¡s%t| |t||ƒƒ qd S tˆ | ƒj|i |¤Ž d S )Nr   r   Ú__)Úlenr.   ÚdirÚ
startswithÚsetattrÚgetattrr   Ú__init__)ÚselfÚargsÚkwargsÚ	unwrap_meÚattr)ÚTemporaryClassr+   r   r   rD   ”   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.   )rK   Ú	classinfoÚvaluer   r   r   Ú__subclasscheck__¡   s   
ze_instance_checking_exception.<locals>.wrapped.<locals>.TemporaryClass.__metaclass__.__subclasscheck__N)Ú__name__Ú
__module__Ú__qualname__rO   rT   r   rM   r   r   Ú__metaclass__�   s    rX   )rU   rV   rW   rD   ÚtyperX   Ú__classcell__r   ©rJ   rN   )r+   r   rJ   ’   s    	rJ   )rU   Ú__doc__rM   ©Úbase_exceptionr[   r   Úwrapped‘   s   z-_instance_checking_exception.<locals>.wrappedr   )r^   r_   r   r]   r   Ú_instance_checking_exception�   s   r`   c                 C   ó   t | dtƒtjkS ©NÚerrno)rC   r    rc   ÚENOENT©rL   r   r   r   r   «   ó   r   c                 C   ra   rb   )rC   r    rc   ÚESRCHre   r   r   r   r   ¯   rf   r   c                 C   s   t | dtƒtjtjfv S rb   )rC   r    rc   ÚEACCESÚEPERMre   r   r   r   r   ³   s   
ÿr   c                 C   ra   rb   )rC   r    rc   ÚEINTRre   r   r   r   r   ¸   rf   r   c                 C   ra   rb   )rC   r    rc   ÚECHILDre   r   r   r   r   ¼   rf   r   c                 C   ra   rb   )rC   r    rc   ÚEEXISTre   r   r   r   r   À   rf   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   ©rv   )rE   ÚtupÚhashr   r   r   rD   ã   s   z_HashedSeq.__init__c                 C   s   | j S r   rw   )rE   r   r   r   Ú__hash__ç   s   z_HashedSeq.__hash__N)rU   rV   rW   Ú	__slots__ry   rD   rz   r   r   r   r   ru   à   s    ru   c	                    sž   | }	|r||  ¡ ƒ}
|	|7 }	|
D ]}|	|7 }	q|r9|	|‡ fdd„| D ƒƒ7 }	|r5|	|‡ fdd„|
D ƒƒ7 }	t|	ƒS ||	ƒdkrKˆ |	d ƒ|v rK|	d S t|	ƒS )Nc                 3   s   � | ]}ˆ |ƒV  qd S r   r   )Ú.0Úv©rY   r   r   Ú	<genexpr>õ   s   € z_make_key.<locals>.<genexpr>c                 3   s   � | ]	\}}ˆ |ƒV  qd S r   r   )r|   Úkr}   r~   r   r   r   ÷   s   € r   r   )Úitemsru   )rF   ÚkwdsÚtypedÚkwd_markÚ	fasttypesÚsortedÚtuplerY   r?   ÚkeyÚsorted_itemsÚitemr   r~   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  t ƒ ‰ddg‰d\‰ ‰t‰
ˆj‰t‰tƒ ‰	g ‰ˆˆd d gˆd d …< ˆg‰d\‰‰‰‰ˆdkr7‡‡‡fdd„}n(ˆd u rJ‡ ‡‡‡‡
‡‡‡‡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 rP   r   )rF   r‚   Úresult)ÚMISSESÚstatsÚuser_functionr   r   Úwrapper  s   z7lru_cache.<locals>.decorating_function.<locals>.wrapperc                     s\   ˆ| |ˆƒ}ˆ|ˆƒ}|ˆurˆˆ   d7  < |S ˆ| i |¤Ž}|ˆ|< ˆˆ  d7  < |S rP   r   )rF   r‚   rˆ   rŽ   )	ÚHITSr�   ÚcacheÚ	cache_getÚmake_keyÚrootr�   rƒ   r‘   r   r   r’     s   
c                     s†  |sˆrˆ
| |ˆƒ}n| }ˆ	  ¡  zBˆ|ƒ}|d urNˆ\}|\}}}}||ˆ< ||ˆ< |ˆ }| |ˆ< |ˆ< ||ˆ< ||ˆ< ˆˆ   d7  < |W ˆ	 ¡  S W ˆ	 ¡  nˆ	 ¡  w ˆ| i |¤Ž}ˆ	  ¡  zYˆ\}|ˆv rmnBˆˆƒˆkr™|}	||	ˆ< ||	ˆ< |	ˆ  }ˆd< |ˆ }
d  |ˆ< |ˆ< ˆ|
= |	ˆ|< n|ˆ }||||g}| |ˆ<  |ˆ< ˆ|< ˆˆ  d7  < W ˆ	 ¡  |S ˆ	 ¡  w )Nr   r   )ÚacquireÚrelease)rF   r‚   rˆ   Úlinkr—   Ú	link_prevÚ	link_nextrŽ   ÚlastÚoldrootÚoldkey)r“   ÚKEYr�   ÚNEXTÚPREVÚRESULTÚ_lenr”   r•   Úlockr–   rs   Únonlocal_rootr�   rƒ   r‘   r   r   r’     sT   
ô

ÿc                      s8   ˆ  ¡  ztˆˆ  ˆˆ ˆtˆƒƒW ˆ ¡  S ˆ ¡  w )zReport cache statistics)r˜   Ú
_CacheInfor?   r™   r   )r“   r�   r”   r¥   rs   r�   r   r   Ú
cache_infoJ  s   ÿz:lru_cache.<locals>.decorating_function.<locals>.cache_infoc                     sV   ˆ  ¡  z!ˆ  ¡  ˆd } | | ddg| dd…< ddgˆdd…< W ˆ ¡  dS ˆ ¡  w )z$Clear the cache and cache statisticsr   N)r˜   Úclearr™   )r—   )r”   r¥   r¦   r�   r   r   Úcache_clearS  s   z;lru_cache.<locals>.decorating_function.<locals>.cache_clear)
Údictr‹   Úgetr?   ro   Ú__wrapped__r¨   rª   Ú	functoolsÚupdate_wrapper)r‘   r’   r¨   rª   ©rs   rƒ   )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   )rs   rƒ   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¡}|s#dS | t j¡}tj	dkr^t j
|vr:| dt j
¡ t j dd¡ t j¡}t‡ fd	d
„|D ƒƒrTˆ g}n‡ fdd„|D ƒ}nˆ g}tƒ }|D ](}t j |¡}||vrŽ| |¡ |D ]}	t j ||	¡}
||
|ƒr�|
    S qyqfd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©r|   Úext©Úcmdr   r   r   ‡  s   €  zwhich.<locals>.<genexpr>c                    s   g | ]}ˆ | ‘qS r   r   rÀ   rÂ   r   r   Ú
<listcomp>Š  s    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  s<   	




ÿ€r   )r   ©éP   é   c                 C   sv   zdd l }dd l}dd l}W n ty   |  Y S w z| d| d|jd¡¡}|d |d fW S  ty:   |  Y S w )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)rU   rV   rW   r   r   r   r   rè   ³  s    rè   )r   c              
   c   s@   � t tdƒ}zttd| ƒ | V  W ttd|ƒ d S ttd|ƒ w )NÚstderr)rC   r!   rB   )Ú
new_targetÚoriginalr   r   r   r   »  s   €
r   )rŒ   F)rØ   )@r\   ÚcollectionsÚ
contextlibrc   r®   r²   r!   r/   Ú__all__Úversion_infor   Úobjectr    Úintr   r   ÚxrangeÚstrr   r   r   r	   r   r7   r   r   r   r   r   r   rÊ   rä   r`   ÚEnvironmentErrorÚpython_implementationÚOSErrorrl   r(   r
   rà   Ú	threadingro   Údummy_threadingÚ
namedtupler§   Úlistru   rÎ   Ú	frozensetrY   r†   r‡   r?   r‹   Úshutilr   ÚF_OKÚX_OKr   Ú
subprocessrç   rè   r   Úcontextmanagerr   r   r   r   Ú<module>   sÈ   

8





ÿÿÿÿ
ýÛ ÿ2ÿÿþ