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rz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 ):zModule 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 )NZ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 rt|}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rt| |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__	TypeErrorZ	func_code_builtin_super)Ztype_Ztype_or_objZ
framedepthfmroZ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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-   )rD   Z	classinfovaluer   r   r   __subclasscheck__   s   
ze_instance_checking_exception.<locals>.wrapped.<locals>.TemporaryClass.__metaclass__.__subclasscheck__N)__name__
__module____qualname__rH   rL   r   rF   r   r   __metaclass__   s    rP   )rM   rN   rO   r>   typerP   __classcell__r   rC   rG   )r*   r   rC      s    	rC   )rM   __doc__rF   base_exceptionrS   r   wrapped   s   z-_instance_checking_exception.<locals>.wrappedr   )rV   rW   r   rU   r   _instance_checking_exception   s   rX   c                 C      t | dttjkS Nerrno)r=   r   r[   ENOENTrE   r   r   r   r         r   c                 C   rY   rZ   )r=   r   r[   ZESRCHr]   r   r   r   r      r^   r   c                 C   s   t | dttjtjfv S rZ   )r=   r   r[   ZEACCESEPERMr]   r   r   r   r      s   
r   c                 C   rY   rZ   )r=   r   r[   ZEINTRr]   r   r   r   r      r^   r   c                 C   rY   rZ   )r=   r   r[   ZECHILDr]   r   r   r   r      r^   r   c                 C   rY   rZ   )r=   r   r[   EEXISTr]   r   r   r   r      r^   r   ZCPythonZ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   rh   )r?   tuphashr   r   r   r>      s   z_HashedSeq.__init__c                 C   s   | j S r   ri   )r?   r   r   r   __hash__   s   z_HashedSeq.__hash__N)rM   rN   rO   	__slots__rk   r>   rl   r   r   r   r   rg      s    rg   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rQ   r   r   	<genexpr>   s    z_make_key.<locals>.<genexpr>c                 3   s    | ]	\}} |V  qd S r   r   )rn   kro   rp   r   r   rq      s    r   r   )itemsrg   )r@   kwdstypedkwd_mark	fasttypessortedtuplerQ   r9   keyZsorted_itemsitemr   rp   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 rI   r   )r@   rt   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 rI   r   )r@   rt   rz   r   )	HITSr   cache	cache_getmake_keyrootr   ru   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)r@   rt   rz   linkr   Z	link_prevZ	link_nextr   ZlastZoldrootZoldkey)r   KEYr   NEXTPREVRESULT_lenr   r   lockr   re   nonlocal_rootr   ru   r   r   r   r     sT   


c                      s8      zt   tW   S   w )zReport cache statistics)r   
_CacheInfor9   r   r   )r   r   r   r   re   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|   getr9   ra   __wrapped__r   r   	functoolsupdate_wrapper)r   r   r   r   re   ru   )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   )re   ru   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rn   extcmdr   r   rq     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   Zhhr   Z1234)fcntlstructtermiosImportErrorunpackZioctlZ
TIOCGWINSZ	Exception)fallbackr   r   r   resr   r   r   r     s   r   )TimeoutExpiredc                   @   s   e Zd ZdS )SubprocessTimeoutExpiredN)rM   rN   rO   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)r=   r    r<   )
new_targetZoriginalr   r   r   r     s   
r   )r}   F)r   )@rT   collections
contextlibr[   r   r   r    r.   __all__version_infor   objectr   intr   r   Zxrangestrr   r   r   r	   r   r5   r   r   r   r   r   r   r   r   rX   EnvironmentErrorZpython_implementationOSErrorr`   r'   r
   r   Z	threadingra   Zdummy_threading
namedtupler   listrg   r   	frozensetrQ   rx   ry   r9   r|   shutilr   F_OKX_OKr   
subprocessr   r   r   contextmanagerr   r   r   r   <module>   s   

8






 2