B
    چ\                  @   s  d 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g	Zejd dkZerne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yddlmZ W n ek
r>   y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eedfeeee fddZ!d!dd
ZY nX yddl"m#Z# W n, ek
r|   ej$ej%B dfd dZ#Y nX dS )"z?Module which provides compatibility with older Python versions.    NPY3longxrangeunicode
basestringub	lru_cachewhich   c             C   s   | S )N )sr   r   -lib/python3.7/site-packages/psutil/_compat.pyr      s    c             C   s
   |  dS )Nzlatin-1)encode)r   r   r   r   r      s    c             C   s
   t | dS )NZunicode_escape)r   )r   r   r   r   r   "   s    c             C   s   | S )Nr   )r   r   r   r   r   %   s    )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 )N)r   )selftuphashr   r   r   __init__=   s    z_HashedSeq.__init__c             C   s   | j S )N)r   )r   r   r   r   __hash__A   s    z_HashedSeq.__hash__N)__name__
__module____qualname__	__slots__r   r   r   r   r   r   r   r   :   s   r   c	                s   | }	|r2||  }
|	|7 }	x|
D ]}|	|7 }	q"W |rp|	| 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 )Nr   ).0v)typer   r   	<genexpr>O   s    z_make_key.<locals>.<genexpr>c             3   s   | ]\}} |V  qd S )Nr   )r!   kr"   )r#   r   r   r$   Q   s       r   )itemsr   )argskwdstypedkwd_mark	fasttypessortedtupler#   lenkeyZsorted_itemsitemr   )r#   r   	_make_keyD   s    
r2   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 )Nr&   r   )r(   r)   result)MISSESstatsuser_functionr   r   wrapperg   s    
z7lru_cache.<locals>.decorating_function.<locals>.wrapperc                 sX   | |}|}|k	r2   d7  < |S | |}||<   d7  < |S )Nr&   r   )r(   r)   r0   r5   )	HITSr6   cache	cache_getmake_keyrootr7   r*   r8   r   r   r9   l   s    

c                 sl  |sr
| |}n| }	   zr|}|d k	r\}|\}}}}||< ||< | }| |< |< ||< ||<    d7  < |S W d 	  X | |}	   z\}|krnkr|}	||	< ||	< |	  }d< | }
d  |< |< |
= |	|< n,| }||||g}| |<  |< |<   d7  < W d 	  X |S )Nr&   r   )acquirerelease)r(   r)   r0   linkr>   Z	link_prevZ	link_nextr5   ZlastZoldrootZoldkey)r:   KEYr6   NEXTPREVRESULT_lenr;   r<   lockr=   r   nonlocal_rootr7   r*   r8   r   r   r9   w   sN    



c                  s2      zt   tS   X dS )zReport cache statisticsN)r?   
_CacheInfor/   r@   r   )r:   r6   r;   rG   r   r7   r   r   
cache_info   s
    
z:lru_cache.<locals>.decorating_function.<locals>.cache_infoc                 sP      z8   d } | | ddg| dd< ddgdd< W d  X dS )z$Clear the cache and cache statisticsr   N)r?   clearr@   )r>   )r;   rG   rH   r7   r   r   cache_clear   s    z;lru_cache.<locals>.decorating_function.<locals>.cache_clear)
dictr2   getr/   r   __wrapped__rJ   rL   	functoolsupdate_wrapper)r8   r9   rJ   rL   )r   r*   )r:   rB   r6   rC   rD   rE   rF   r;   r<   rG   r=   rH   r>   r7   r8   r   decorating_functionZ   s,    *-	z&lru_cache.<locals>.decorating_functionr   )r   r*   rR   r   )r   r*   r   r	   V   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 }xT|D ]L}t j|}||kr|| x(|D ] }	t j||	}
||
|r|
S qW qW 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 )N)ospathexistsaccessisdir)fnmoder   r   r   _access_check   s    zwhich.<locals>._access_checkNPATHZwin32r   ZPATHEXT c             3   s    | ]}   |  V  qd S )N)lowerendswith)r!   ext)cmdr   r   r$      s    zwhich.<locals>.<genexpr>c                s   g | ]} | qS r   r   )r!   r_   )r`   r   r   
<listcomp>   s    zwhich.<locals>.<listcomp>)rS   rT   dirnameenvironrN   defpathsplitpathsepsysplatformcurdirinsertanysetnormcaseaddjoin)r`   rY   rT   rZ   ZpathextfilesseendirZnormdirZthefilenamer   )r`   r   r
      s8    	






)r3   F)&__doc__collectionsrP   rS   rg   __all__version_infor   intr   ranger   strr   r   r   r   r	   ImportErrorZ	threadingr   Zdummy_threading
namedtuplerI   listr   objectrl   	frozensetr#   r-   r.   r/   r2   Zshutilr
   F_OKX_OKr   r   r   r   <module>   sL   

k