U
    (c:                     @   sV  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ddddddd	d
ddddddddddgZej	d dkZ
e Ze
re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
reZneZeedfddZe
reZeZeZeZeZeZnd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%W n2 ek
r   Y n e#k
r   e%d&Y nX zdd'lm&Z& W n e'k
rt   zdd(l(m)Z) W n" e'k
r   dd(l*m)Z) Y nX e+d)d*d+d,d-gZ,G d.d/ d/e-Z.efe/eee0e1dfe2e3e1e4fd0d1Z5d?d4dZ&Y nX zdd5l6m7Z7 W n, e'k
r   ej8ej9B dfd6dZ7Y nX zdd7l6m:Z: W n  e'k
r   d@d9dZ:Y nX zdd:l;m<Z= W n$ e'k
r   G d;d< d<Z=Y nX zdd=lm>Z> W n$ e'k
rP   ej?d>d Z>Y nX dS )AzModule 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   2/tmp/pip-unpacked-wheel-l83rk7k5/psutil/_compat.pyr   /   s    c                 C   s
   |  dS )Nzlatin-1)encoder   r   r   r   r	   2   s    c                 C   s
   t | dS )NZunicode_escape)r   r   r   r   r   r   :   s    c                 C   s   | S r   r   r   r   r   r   r	   =   s       c                 C   sb  | t krFt|}z|j|jjd  }W n  ttfk
rJ   tdY nX z
|j	}W nB t
tfk
r   z|jj	}W n t
k
r   tdY nX Y nX |D ]} | j D ]}zPt|tjst|tr|j}qz
|j}W q t
k
r   ||| }Y qX qW n t
tfk
r   Y qY nX |j|jkr q6qq qFqtd|t k	rZt| |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    







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                    sd   t |dkrNt|d  rN|d }t|D ] }|ds*t| |t|| q*nt | j|| 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   s   t | dttjkS Nerrno)r=   r   rZ   ENOENTrE   r   r   r   r      s    c                 C   s   t | dttjkS rY   )r=   r   rZ   ZESRCHr\   r   r   r   r      s    c                 C   s   t | dttjtjfkS rY   )r=   r   rZ   EACCESEPERMr\   r   r   r   r      s    
 c                 C   s   t | dttjkS rY   )r=   r   rZ   ZEINTRr\   r   r   r   r      s    c                 C   s   t | dttjkS rY   )r=   r   rZ   ZECHILDr\   r   r   r   r      s    c                 C   s   t | dttjkS rY   )r=   r   rZ   EEXISTr\   r   r   r   r      s    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   ri   )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)rM   rN   rO   	__slots__rl   r>   rm   r   r   r   r   rh      s   rh   c	                    s   | }	|r.||  }
|	|7 }	|
D ]}|	|7 }	q |rl|	| fdd| D 7 }	|r|	| fdd|
D 7 }	n$||	dkr |	d |kr|	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   )ro   krp   rq   r   r   rr      s     r   r   )itemsrh   )r@   kwdstypedkwd_mark	fasttypessortedtuplerQ   r9   keyZsorted_itemsitemr   rq   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rnfdd}nPd kr 
f	dd}n* 	
fdd} 	fdd	}	fd
d}|_||_||_t	|S )Nr   )r   r   )r   r      r   c                     s   | |}   d7  < |S rI   r   )r@   ru   result)MISSESstatsuser_functionr   r   wrapper  s    
z7lru_cache.<locals>.decorating_function.<locals>.wrapperc                     sX   | |}|}|k	r2   d7  < |S | |}||<   d7  < |S rI   r   )r@   ru   r{   r   )	HITSr   cache	cache_getmake_keyrootr   rv   r   r   r   r     s    

c                     sp  |sr
| |}n| }	   zv|}|d k	r\}|\}}}}||< ||< | }| |< |< ||< ||<    d7  < |W S W 5 	  X | |}	   z\}|krnkr"|}	||	< ||	< |	  }d< | }
d  |< |< |
= |	|< n,| }||||g}| |<  |< |<   d7  < W 5 	  X |S )Nr   r   )acquirerelease)r@   ru   r{   linkr   Z	link_prevZ	link_nextr   lastZoldrootZoldkey)r   KEYr   NEXTPREVRESULT_lenr   r   lockr   rf   nonlocal_rootr   rv   r   r   r   r     sN    



c                      s6      zt   tW S   X dS )zReport cache statisticsN)r   r   
_CacheInfor9   r   )r   r   r   r   rf   r   r   r   
cache_infoJ  s    z:lru_cache.<locals>.decorating_function.<locals>.cache_infoc                     sP      z8   d } | | ddg| dd< ddgdd< W 5   X dS )z$Clear the cache and cache statisticsr   N)r   r   clear)r   )r   r   r   r   r   r   cache_clearS  s    z;lru_cache.<locals>.decorating_function.<locals>.cache_clear)
dictr}   getr9   rb   __wrapped__r   r   	functoolsupdate_wrapper)r   r   r   r   rf   rv   )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   )rf   rv   r   r   r   r   r
      s    c)r   c                    s"  dd }t j r&| |r" S dS |dkr>t jdt j}|sFdS |t j}tj	dkrt j
|k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|}||kr|| |D ](}	t j||	}
||
|r|
    S qqd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ro   extcmdr   r   rr     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  s8    	




)r   P      c                 C   s~   zdd l }dd l}dd l}W n tk
r4   |  Y S X z*|d|d|jd}|d |d fW S  tk
rx   |  Y S X d S )Nr   hhr   Z1234)fcntlstructtermiosImportErrorunpackZioctl
TIOCGWINSZ	Exception)fallbackr   r   r   resr   r   r   r     s    
 )TimeoutExpiredc                   @   s   e Zd ZdS )SubprocessTimeoutExpiredN)rM   rN   rO   r   r   r   r   r     s   r   )r   c                 c   s$   t j}z| t _| V  W 5 |t _X d S r   )r   stderr)
new_targetoriginalr   r   r   r     s
    
)r~   F)r   )@rT   collections
contextlibrZ   r   r   r   r+   __all__version_infor   objectr   intr   r   xrangestrr   r   r   r	   r   r3   r   r   r   r   r   r   r   r   rX   EnvironmentErrorpython_implementationOSErrorr_   r$   r
   r   	threadingrb   Zdummy_threading
namedtupler   listrh   r   	frozensetrQ   ry   rz   r9   r}   shutilr   F_OKX_OKr   
subprocessr   r   r   contextmanagerr   r   r   r   <module>   s             

8






 
   
k1