[ Avaa Bypassed ]




Upload:

Command:

hmhc3928@18.117.99.230: ~ $
U

�=�_���E@s�dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZddlmZddlZddlmZddlmZdd	lmZdd
lm Z ddlm!Z!ddlm"Z"dd
lm#Z#ddl$m%Z%ddl$m&Z&ddl$m'Z'ddl(m)Z)ddl(m*Z*ddl(m+Z+ddl(m,Z,ddl(m-Z-ddl(m.Z.ddl(m/Z/ddl(m0Z0e+�r�ddl1Z1nddl2Z1zddl1m3Z3Wn<e4k
�r(e�5��e�6d�ddl3Z3W5QRXYnXej7dk�r@ddl8Z8ndZ8ddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`gEZ9daej:kZ;de
j<kZ=dbe
j<k�p�dce
j<kZ>e=�pe>Z?ej@ddkZAdeZBdfZCdgZDdhZEe?�rFeBdi9ZBeEdi9ZEeCdi9ZCeDdi9ZDe
jFdjk�r`dke
�G�ZHndle
�G�ZHe.dm�ZIe+�r�dn�Jdodp�ZKndqZKe�L��M�drkZNe
jO�Pe
jO�Qe
jO�ReS�dsds��ZTe
jO�QeTdt�ZUe
jO�Pe
jO�ReS��ZVe!�o�e"ZWeXejYdu�ZZeXedv�Z[eXedw�Z\eXejYdx�Z]eXejYdy�Z^eXejYdz�Z_eXed{�Z`eXejYd|�ZaeXejYd}�ZbeXejYd~�ZceXed�Zdzed�oxeee�f��ZgWnehk
�r�d�ZgYnXeXed��ZieXed��ZjeXejYd��Zke �s�e�o�e
�l�dkZmd�d��Znen�Zoepe
jqd��Zre�serjt�d�d��eue�D�Zvewed�ex��Zyez�Z{ez�Z|Gd�d��d�ej}�Z~d�d��Zed�d�d<��Z�ed�d>��Z�d�d=�Z�ed�d9��Z�ed�d���Z�ej�eEfd�d:�Z�d�d�d;�Z�d�dQ�Z�d�dP�Z�Gd�d��d�ex�Z�e�ej�deEd�d��d�dS��Z�e�e*e�fdeEd�d��d�d�dT��Z�e�e�deEd�d��d�dR��Z�d�dK�Z�d�d��Z�ej�d�dJ��Z�d�d�dL�Z�d�d�dO�Z�Gd�d��d�e1j��Z�e�e1_�Gd�dD�dDe��Z�e1��e;d��Gd�dC�dCe���Z�d�dG�Z�d�d��Z�Gd�dE�dE�Z�Gd�dF�dF�Z�d�d��Z�eBfd�dB�Z�d�d�d@�Z�d�d�dA�Z�d�d�dV�Z�eedfd�dW�Z�ejfd�dX�Z�d�d�dY�Z�d�dZ�Z�ej�d�d[��Z�d�dU�Z�d�d��Z�d�d\�Z�d�d]�Z�d�d^�Z�d�d`�Z�e!�rZej�d�d�d_��Z�nej�d�d�d_��Z�ejsd�dȄ�Z�e!�r�e�ej�d�dʄ�dS)�z
Test utilities.
�)�print_functionN)�AF_INET)�AF_INET6)�SOCK_STREAM)�AIX)�FREEBSD)�LINUX)�MACOS)�POSIX)�SUNOS)�WINDOWS)�bytes2human)�print_color)�
supports_ipv6)�FileExistsError)�FileNotFoundError)�PY3)�range)�super)�u)�unicode)�which)�mock�ignore����APPVEYOR�DEVNULL�GLOBAL_TIMEOUT�TOLERANCE_SYS_MEM�
NO_RETRIES�PYPY�
PYTHON_EXE�ROOT_DIR�SCRIPTS_DIR�
TESTFN_PREFIX�UNICODE_SUFFIX�INVALID_UNICODE_SUFFIX�
CI_TESTING�VALID_PROC_STATUSES�TOLERANCE_DISK_USAGE�IS_64BIT�HAS_CPU_AFFINITY�HAS_CPU_FREQ�HAS_ENVIRON�HAS_PROC_IO_COUNTERS�
HAS_IONICE�HAS_MEMORY_MAPS�HAS_PROC_CPU_NUM�
HAS_RLIMIT�HAS_SENSORS_BATTERY�HAS_BATTERY�HAS_SENSORS_FANS�HAS_SENSORS_TEMPERATURESZHAS_MEMORY_FULL_INFO�pyrun�	terminate�
reap_children�spawn_testproc�spawn_zombie�spawn_children_pairZThreadTaskunittest�skip_on_access_denied�skip_on_not_implemented�retry_on_failure�TestMemoryLeak�PsutilTestCase�process_namespace�system_namespace�
print_sysinfoZinstall_pipZinstall_test_deps�chdir�safe_rmpath�
create_exeZdecode_pathZencode_path�
get_testfn�
get_winver�kernel_version�
call_until�wait_for_pid�
wait_for_file�check_net_address�
get_free_port�bind_socket�bind_unix_socket�tcp_socketpair�unix_socketpair�create_sockets�
reload_module�import_module_by_path�warn�copyload_shared_lib�
is_namedtupleZ__pypy__�GITHUB_ACTIONSZCIBUILDWHEELl�
iPi��r�javaz$psutil-%s-z@psutil-%s-u-ƒőősf���utf8�surrogateescapeufÀ€)�asciizus-asciiz..Zscripts�cpu_affinity�cpu_freq�
getloadavg�environ�ionice�memory_maps�net_io_counters�cpu_num�io_counters�rlimit�sensors_batteryF�sensors_fans�sensors_temperatures�threadscCs�dd�}tr@tr$trtd�Std�Str6tj�tj	�Std�Sn�t
r�|tj	�p�|tj�tj	��p�|tdtjdd���p�|t�
����}|s�td��|Stj�tj	�}tj�|�s�t|��|SdS)	NcSs<ztj|dgtjtjd�Wntk
r2YdSX|SdS)Nz-V)�stdout�stderr)�
subprocess�
check_call�PIPE�	Exception)�exe�rx�H/opt/alt/python38/lib64/python3.8/site-packages/psutil/tests/__init__.py�attempt�s�
z_get_py_exe.<locals>.attemptZpypy3�pypy�pythonzpython%s.%s�z"can't find python exe real abspath)r\r"rrr�os�path�realpath�sys�
executabler	�version_info�psutil�Processrw�
ValueError�exists�AssertionError)rzrwrxrxry�_get_py_exe�s*	

���r�zr+cCs g|]}|�d�rtt|��qS)ZSTATUS_��
startswith�getattrr���.0�xrxrxry�
<listcomp>�s
�r��AF_UNIXcsPeZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
�ZS)�
ThreadTaskz6A thread task which does nothing expect staying alive.cs$t���d|_d|_t��|_dS)NF���MbP?)r�__init__�_running�	_interval�	threadingZEvent�_flag��self��	__class__rxryr��s
zThreadTask.__init__cCs|jj}d||jt|�fS)Nz<%s running=%s at %#x>)r��__name__r��id)r��namerxrxry�__repr__�szThreadTask.__repr__cCs|��|S�N)�startr�rxrxry�	__enter__szThreadTask.__enter__cOs|��dSr�)�stop)r��args�kwargsrxrxry�__exit__szThreadTask.__exit__cCs(|jrtd��tj�|�|j��dS)zStart thread and keep it running until an explicit
        stop() request. Polls for shutdown every 'timeout' seconds.
        zalready startedN)r�r�r��Threadr�r��waitr�rxrxryr�szThreadTask.startcCs(d|_|j��|jr$t�|j�qdS)NT)r�r��set�time�sleepr�r�rxrxry�runs
zThreadTask.runcCs |jstd��d|_|��dS)z8Stop thread execution and and waits until it is stopped.zalready stoppedFN)r�r��joinr�rxrxryr�szThreadTask.stop)r��
__module__�__qualname__�__doc__r�r�r�r�r�r�r��
__classcell__rxrxr�ryr��s	r�cst����fdd��}|S)Ncs.z�||�WStk
r(t��YnXdSr�)rvr;�r�r���funrxry�wrapper%s
z&_reap_children_on_err.<locals>.wrapper��	functools�wraps�r�r�rxr�ry�_reap_children_on_err$sr�cKs�|�dt�|�dt�|�dt���|�dtj�trJd}|�d|�|dkr�t�}zDt|�d|}td	|g}t	j
|f|�}t�|�t
|d
d
d�W5t|�Xn"t	j
|f|�}t�|�t|j�|S)a}Creates a python subprocess which does nothing for 60 secs and
    return it as a subprocess.Popen instance.
    If "cmd" is specified that is used instead of python.
    By default stdin and stdout are redirected to /dev/null.
    It also attemps to make sure the process is in a reasonably
    initialized state.
    The process is registered for cleanup on reap_children().
    �stdinrq�cwd�env��
creationflagsNz:from time import sleep;open(r'%s', 'w').close();sleep(60);z-cT��delete�empty)�
setdefaultrr~�getcwdrfrrJrHr#rs�Popen�_subprocesses_started�addrOrN�pid)�cmd�kwdsZCREATE_NO_WINDOW�testfnZpyline�sprocrxrxryr</s.
�



cCs�d}tt��d�}zzt�dtj�|�tf�}t	rDt
|dd�\}}nt
|�\}}t�|j
�}tt|ddd��}t�|�t�|�}||fW�St|�|dk	r�t|�XdS)	aCreate a subprocess which creates another one as in:
    A (us) -> B (child) -> C (grandchild).
    Return a (child, grandchild) tuple.
    The 2 processes are fully initialized and will live for 60 secs
    and are registered for cleanup on reap_children().
    N��dira;            import subprocess, os, sys, time
            s = "import os, time;"
            s += "f = open('%s', 'w');"
            s += "f.write(str(os.getpid()));"
            s += "f.close();"
            s += "time.sleep(60);"
            p = subprocess.Popen([r'%s', '-c', s])
            p.wait()
            r)r�TFr�)rJr~r�rH�textwrap�dedentr�basenamer#rr9r�r�r��intrO�
_pids_startedr�)�tfiler��s�subpZchildZgrandchild_pidZ
grandchildrxrxryr>Ws"	�


cs�tjs
t�t�}t�d|�}d}t|�}z�|�	t
�t|�\}}|��\}}zZt
�
|��gggt
�t|�d��}t�|�t�|��t�fdd�d�|�fW�W�S|��XW5|��t|�|dk	r�t|�XdS)z�Create a zombie process and return a (parent, zombie) process tuple.
    In order to kill the zombie parent must be terminate()d first, then
    zombie must be wait()ed on.
    a        import os, sys, time, socket, contextlib
        child_pid = os.fork()
        if child_pid > 0:
            time.sleep(3000)
        else:
            # this is the zombie process
            s = socket.socket(socket.AF_UNIX)
            with contextlib.closing(s):
                s.connect('%s')
                if sys.version_info < (3, ):
                    pid = str(os.getpid())
                else:
                    pid = bytes(str(os.getpid()), 'ascii')
                s.sendall(pid)
        N�cs���Sr�)�statusrx��zombierxry�<lambda>��zspawn_zombie.<locals>.<lambda>zret == psutil.STATUS_ZOMBIE)r�r
r�rJr�r�rS�closerHZ
settimeoutrr9�accept�select�filenor�Zrecvr�r�r�rM)Z	unix_file�srcr��sock�parent�conn�_Zzpidrxr�ryr=~s.
�


c	Ks�|�dd�|�dd�t�}zFt|d��}|�|�W5QRXtt|jgf|�}t|j�||fWSt	k
r�t
|��YnXdS)z�Run python 'src' code string in a separate interpreter.
    Returns a subprocess.Popen instance and the test file where the source
    code was written.
    rqNrr�wt)r�rJ�open�writer<r#r�rNr�rvrH)r�r��srcfile�fr�rxrxryr9�s

cKs�t|ttf�rdnd}tr"|r"dnd}|�d|�|�dtj�|�dtj�|�dd�|�d	|�tj|f|�}t�	|�t
r�|jtd
�\}}n|��\}}|j
dkr�t|��|r�t|�|�d�r�|dd
�}|S)zUrun cmd in a subprocess and return its output.
    raises RuntimeError on error.
    TFr�r�shellrqrrZuniversal_newlinesr���timeout�
N���)�
isinstance�strrrr�rsrur�r�r�rZcommunicater�
returncode�RuntimeErrorrY�endswith)r�r�r��flags�prqrrrxrxry�sh�s&


r�c
strddlm�dd��dd�����fdd�}���fd	d
����fdd�}d
d�}|}zbt|t�rt|||�W�LSt|tjtjf�r��||�W�,St|tj�r�|||�W�Std|��W5t|tjtjf�r�||�t|t�r�|n|j}t�	|��rt
|��XdS)a�Terminate a process and wait() for it.
    Process can be a PID or an instance of psutil.Process(),
    subprocess.Popen() or psutil.Popen().
    If it's a subprocess.Popen() or psutil.Popen() instance also closes
    its stdin / stdout / stderr fds.
    PID is wait()ed even if the process is already gone (kills zombies).
    Does nothing if the process does not exist.
    Return process exit status.
    r)�wait_pidcSsdt|tj�rts|��n
|�|�tr`t|tj�r`zt�|j��|�WStj	k
r^YnXdSr�)
r�rsr�rr�rr�r�r��
NoSuchProcess��procr�rxrxryr��s

zterminate.<locals>.waitcSs6trtrtj}tr(|tjkr(|�tj�|�|�dSr�)r	r\�signal�SIGKILLr
�send_signal�SIGCONT)r��sigrxrxry�sendsig�s
zterminate.<locals>.sendsigc
sZz�|��Wn@tk
rN}z"tr0|jdkr0n|jtjkr>�W5d}~XYnX�||�S)N�)�OSErrorrZwinerror�errnoZESRCH)r�r��err�rrr�rxry�term_subproc�szterminate.<locals>.term_subproccs0z�|��Wntjk
r$YnX�||�Sr�)r�r�r�rrxry�term_psprocs
zterminate.<locals>.term_psproccsFzt�|�}Wn(tjk
r6tr2�||�YSYnX�||�SdSr�)r�r�r�r
)r�r�r�)r	r�rxry�term_pidszterminate.<locals>.term_pidcSs4|jr|j��|jr |j��|jr0|j��dSr�)rqr�rrr�)r�rxrxry�flush_popens

zterminate.<locals>.flush_popenz
wrong type %rN)
r
Zpsutil._psposixr�r�rsr�r�r�r��
pid_existsr�r��	TypeError)Zproc_or_pidr�wait_timeoutrr
rr�r�rx)rrr	r�r�ryr:�s*



	
cCs�t��j|d�}tr&t��}t|�qtr<t��}t|�q&|r�|D]}t|dd�qDtj|td�\}}|D]}t	d|�t|t
jd�qldS)aTerminate and wait() any subprocess started by this test suite
    and any children currently running, ensuring that no processes stick
    around to hog resources.
    If resursive is True it also tries to terminate and wait()
    all grandchildren started by this process.
    ��	recursiveN)rr�z0couldn't terminate process %r; attempting kill())r)r�r��childrenr��popr:r��
wait_procsrrYr�r�)rrr�r�r�ZgoneZaliverxrxryr;3s


cCs�tstd��d}t��d}|D]"}|��s4|dkr>||7}q qDq |sTtd|��d}d}|�d�}t|d�}t|�dkr�t|d�}t|�dkr�t|d�}|||fS)	z"Return a tuple such as (2, 6, 36).z	not POSIX�r}�.zcan't parse %rr�r)	r
�NotImplementedErrorr~�uname�isdigitr��splitr��len)r�r�c�minor�microZnums�majorrxrxryrLXs&

cCsdtstd��t��}t|d�r*|jp&d}n(t�d|d�}|rNt|�	d��}nd}|d|d|fS)Nznot WINDOWS�service_pack_majorrz\s\d$rr)
rrr�Zgetwindowsversion�hasattrr �re�searchr��group)ZwvZsp�rrxrxryrKps
c@s<eZdZdZeddddfdd�Zdd�Zdd	�Zd
d�ZdS)�retryzA retry decorator.Nr�cCs2|r|rtd��||_||_||_||_||_dS)Nz/timeout and retries args are mutually exclusive)r��	exceptionr��retries�interval�logfun)r�r'r�r(r)r*rxrxryr��szretry.__init__ccsT|jr*t��|j}t��|krPdVqn&|jrHt|j�D]
}dVq:ndVqHdSr�)r�r�r(r)r��stop_atr�rxrxry�__iter__�s

zretry.__iter__cCs|jdk	rt�|j�dSr�)r)r�r�r�rxrxryr��s
zretry.sleepcs"t�����fdd��}�|_|S)Ncs|d}�D]b}z�||�WS�jk
rh}z,|}�jdk	rH��|����WY�qW5d}~XYqXqtrv|�n�dSr�)r'r*r�r)r�r��excr��r�r�rxryr��s

zretry.__call__.<locals>.wrapper)r�r��	decorator)r�r�r�rxr.ry�__call__�szretry.__call__)	r�r�r�r�rvr�r,r�r0rxrxrxryr&�s�
r&r�)r'r*r�r)cCst�|�trt�d�dS)z�Wait for pid to show up in the process list then return.
    Used in the test suite to give time the sub process to initialize.
    �{�G�z�?N)r�r�rr�r�)r�rxrxryrN�s
Tc	Cs:t|d��}|��}W5QRX|s*|s*t�|r6t|�|S)z8Wait for a file to be written on disk with some content.�rb)r��readr�rH)�fnamer�r�r��datarxrxryrO�scCs|�}t|�st�|S)zVKeep calling function for timeout secs and exit if eval()
    expression is True.
    )�evalr�)r��expr�retrxrxryrM�scCsndd�}zLt�|�}t�|j�r0t�tj|�}nt�tj|�}t	rJ|�n||�Wnt
k
rhYnXdS)z>Convenience function for removing temporary test files or dirsc
Ss~t��t}t��|krvz|�WStk
r4Yn6tk
rh}z|}tdt|��W5d}~XYnXt�d�q|�dS)Nzignoring %sr1)r�rrZWindowsErrorrYr�r�)r�r+r�rrxrxry�	retry_fun�s"zsafe_rmpath.<locals>.retry_funN)r~�stat�S_ISDIR�st_moder��partial�shutilZrmtree�remover
r)rr9�str�rxrxryrH�s
cCs(zt�|�Wntk
r"YnXdS)z-Convenience function for creating a directoryN)r~�mkdirrr�rxrxry�
safe_mkdirsrBc	cs.t��}zt�|�dVW5t�|�XdS)z@Context manager which temporarily changes the current directory.N)r~r�rG)�dirname�curdirrxrxryrGs


c	Cs�tj�|�rt|��|r�td�s(td��t|t�r<t�	d�}t|t
�sNt|��ttdd�d��}|�
|�W5QRXzt�d|jd|g�W5t|j�Xn.t�t|�tr�t�|�}t�||jtjB�dS)	z1Creates an executable file in the given location.�gcczgcc is not installedz�
                #include <unistd.h>
                int main() {
                    pause();
                    return 1;
                }
                z.c��suffixr�z-oN)r~rr�r�rr�r��boolr�r�r�r�rJr�rHr�rsrtr>�copyfiler#r
r:�chmodr<�S_IEXEC)ZoutpathZc_coder�r@rxrxryrIs$
�
rcCs.tjt||d�}tj�|�stj�|�SqdS)z�Return an absolute pathname of a file or dir that did not
    exist at the time this call is made. Also schedule it for safe
    deletion at interpreter exit. It's technically racy but probably
    not really due to the time variant.
    )�prefixrGr�N)�tempfileZmktempr&r~rr�r�)rGr�r�rxrxryrJ9sc@s4eZdZdd�Zeejd�s$ejjZe	s0dd�Z
dS)�TestCasecCs.|jj}|�d�sd|}d||jj|jfS)Nzpsutil.z
psutil.tests.z%s.%s.%s)r�r�r�r�Z_testMethodName)r�Zfqmodrxrxry�__str__Ns
�zTestCase.__str__�assertRaisesRegexcCsdSr�rxr�rxrxry�runTest\szTestCase.runTestN)r�r�r�rOr!�unittestrNZassertRaisesRegexprPrrQrxrxrxryrNJs
	rNc@sBeZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)rCzUTest class providing auto-cleanup wrappers on top of process
    test utilities.
    rNcCst||d�}|�t|�|S)N)rGr�)rJ�
addCleanuprH)r�rGr�r4rxrxryrJiszPsutilTestCase.get_testfncOst||�}|�t|�|Sr�)r<rSr:)r�r�r�r�rxrxryr<ns
zPsutilTestCase.spawn_testproccCs*t�\}}|�t|�|�t|�||fSr�)r>rSr:)r�Zchild1Zchild2rxrxryr>ss
z"PsutilTestCase.spawn_children_paircCs*t�\}}|�t|�|�t|�||fSr�)r=rSr:)r�r�r�rxrxryr=ys
zPsutilTestCase.spawn_zombiecOs*t||�\}}|�t|�|�t|�|Sr�)r9rSrHr:)r�r�r�r�r�rxrxryr9szPsutilTestCase.pyruncCs�|�tjtj|j�t|tjtjf�rn|��r2t�z|�	�}Wntjk
rTYnXtd|��|j
dd�t�|j�r�t|j��|�|jt�
��dS)Nz3Process.status() didn't raise exception (status=%s)rr�)�assertRaisesr�r�r�r�r�r��
is_runningr�r�r�rZassertNotIn�pids)r�r�r�rxrxry�assertProcessGone�s�z PsutilTestCase.assertProcessGone)rN)
r�r�r�r�rJr<r>r=r9rWrxrxrxryrCds
zunreliable on PYPYc@s~eZdZdZdZdZdZer dndZdZ	e
��Zdd�Z
d	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Zddd�Zdd�ZdS)rBa�Test framework class for detecting function memory leaks,
    typically functions implemented in C which forgot to free() memory
    from the heap. It does so by checking whether the process memory
    usage increased before and after calling the function many times.

    Note that this is hard (probably impossible) to do reliably, due
    to how the OS handles memory, the GC and so on (memory can even
    decrease!). In order to avoid false positives, in case of failure
    (mem > 0) we retry the test for up to 5 times, increasing call
    repetitions each time. If the memory keeps increasing then it's a
    failure.

    If available (Linux, OSX, Windows), USS memory is used for comparison,
    since it's supposed to be more precise, see:
    https://gmpy.dev/blog/2016/real-process-memory-and-environ-in-python
    If not, RSS memory is used. mallinfo() on Linux and _heapwalk() on
    Windows may give even more precision, but at the moment are not
    implemented.

    PyPy appears to be completely unstable for this framework, probably
    because of its JIT, so tests on PYPY are skipped.

    Usage:

        class TestLeaks(psutil.tests.TestMemoryLeak):

            def test_fun(self):
                self.execute(some_function)
    ��r]rr^TcCs|j��}t|d|j�S)NZuss)�	_thisproc�memory_full_infor�Zrss)r��memrxrxry�_get_mem�s
zTestMemoryLeak._get_memcCstr|j��S|j��SdSr�)r
rY�num_fds�num_handlesr�rxrxry�_get_num_fds�s
zTestMemoryLeak._get_num_fdscCs|jrt|dtjd�dS)NZyellow)Zcolor�file)�verboserr�rr)r��msgrxrxry�_log�szTestMemoryLeak._logcCsx|��}|�|�|��}||}|dkr8|�d|��|dkrttrHdnd}|dkr\|d7}d|||f}|�|��dS)	z�Makes sure num_fds() (POSIX) or num_handles() (Windows) does
        not increase after calling a function.  Used to discover forgotten
        close(2) and CloseHandle syscalls.
        rzHnegative diff %r (gc probably collected a resource from a previous test)�fdZhandlerr�z%s unclosed %s after calling %rN)r_�call�failr
)r�r�ZbeforeZafter�diffZtype_rbrxrxry�
_check_fds�s
�zTestMemoryLeak._check_fdscCs^tjdd�|��}t|�D]}|�|�}~~qtjdd�|��}|�tjg�||}|S)z�Get 2 distinct memory samples, before and after having
        called fun repeadetly, and return the memory difference.
        r)Z
generation)�gcZcollectr\rreZassertEqualZgarbage)r�r��timesZmem1r�r8Zmem2rgrxrxry�_call_ntimes�s
zTestMemoryLeak._call_ntimesc
Cs�g}d}|}td|d�D]�}	|�||�}
d|	t|
�t|
|�|f}|�|�|
|kp^|
|k}|r||	dkrv|�|�dS|	dkr�t�|�|�||7}|
}q|�d�|���dS)Nrrz,Run #%s: extra-mem=%s, per-call=%s, calls=%sz. )rrkr
�appendrc�printrfr�)
r�r�rj�warmup_timesr(�	toleranceZmessagesZprev_memZincrease�idxr[rb�successrxrxry�
_check_mem�s.
�


zTestMemoryLeak._check_memcCs|�Sr�rx)r�r�rxrxryreszTestMemoryLeak.callNc
Cs�|dk	r|n|j}|dk	r|n|j}|dk	r0|n|j}|dk	rB|n|j}zD|dksZtd��|dksjtd��|dksztd��|dks�td��Wn.tk
r�}ztt|���W5d}~XYnX|�||�|�|�|j	|||||d�dS)	zTest a callable.Nrztimes must be >= 1rzwarmup_times must be >= 0zretries must be >= 0ztolerance must be >= 0)rjrnr(ro)
rjrnr(ror�r�r�rkrhrr)r�r�rjrnr(rorrxrxry�execute	s&�

�zTestMemoryLeak.executecs"���fdd�}�j|f|�dS)znConvenience method to test a callable while making sure it
        raises an exception on every call.
        cs�����dSr�)rTrx�r-r�r�rxryre"sz*TestMemoryLeak.execute_w_exc.<locals>.callN)rs)r�r-r�r�rerxrtry�
execute_w_excszTestMemoryLeak.execute_w_exc)NNNN)r�r�r�r�rjrnror)r(rar�r�rYr\r_rcrhrkrrrersrurxrxrxryrB�s$�
cCs�ddl}ddl}ddl}ddl}ddl}ddl}zddl}Wntk
rTd}YnXzddl}Wntk
rzd}YnX|�	�}t
jr�td�r�t
d�|d<n~t
jr�d|��d|d<nbt
j�rdd�tt|����|d<t|d��r|dd	|��7<nd
|��|��f|d<d	�t|���|��g�|d<t
j�rV|��d|d
<d	�|��|��|� �g�|d<t!|dd�|d<|dk	�r�|dd|j"7<t
j�r�td��r�t
ddg�}	t|	��#d�d|d<nd|d<|�$�d}
|
�r�|
|d<t%�&�|d<|�'�}d|d|df|d<|j�(t
�)���*d�|d<|j�+��*d�|d<|�,�|d<t-j.�/d�|d <t-�0�|d!<t1|d"<|�2�|d#<t-�3�|d$<t
�4�|d%<d&t5d'd(�t
�6�D��|d)<t
�7�}d*t8|j9�t:|j;�t:|j<�f|d+<t
�=�}
d*t8|
j9�t:|
j;�t:|
j<�f|d,<t>t
�?��|d-<t
�@��A�}|�Bd.d�|�C|�|d/<tDd0t%jEd1�|�F�D]$\}}tDd2|d3|ft%jEd1��qntDd0t%jEd1�t%jG�H�dS)4NrZlsb_releasezlsb_release -d -sZOSz	Darwin %szWindows � �
win32_editionz, z%s %sZarchr}Zkernelr|�__version__z
not installed�pipz (wheel=%s)rEz	--versionr�rZglibczfs-encodingz%s, %s�langz%Y-%m-%d %H:%M:%Sz	boot-timer��user�~�homer�ZpyexeZhostnameZPIDZcpusz%.1f%%, %.1f%%, %.1f%%cSsg|]}|t��d�qS)�d)r��	cpu_countr�rxrxryr�psz!print_sysinfo.<locals>.<listcomp>Zloadavgz%s%%, used=%s, total=%sZmemory�swaprVrhr�zF======================================================================�r`z%-17s %s�:)I�collections�datetime�getpass�locale�platform�pprintry�ImportError�wheel�OrderedDictr�rrr�ZOSXZmac_verrr��mapr�Z	win32_verr!rw�system�version�listZarchitecture�machiner
rZpython_implementationZpython_versionZpython_compilerr�rxrZlibc_verr��getfilesystemencodingZ	getlocaleZ
fromtimestamp�	boot_time�strftimeZnowZgetuserr~r�
expanduserr�r#Znode�getpidr�tuplere�virtual_memoryr�Zpercentr
ZusedZtotal�swap_memoryrrVr��as_dictrZpformatrmrr�itemsrq�flush)r�r�r�r�r�r�ryr��info�outr�rzr[r�Zpinfo�k�vrxrxryrF(s�

�
��


����
�
cCs6t��}t|d�r|��St|d�r2t�|���SdS)Nrjrcr)r�r�r!rj�random�choicerc)r�rxrxry�_get_eligible_cpu�s

r�c@sBeZdZdZddifddifgZddifddddifd	difd
difddifddifd
difddifddifg	Zddifddddifddifddifddifddifddifddifddifddifddifddifddifd difd!difd"difd#difgZe�rFed$difg7Zed%difg7Zed&difg7Zed'difg7Ze�r\ed(difg7Ze	�rred)difg7Ze
�r�ed*ejfifg7Ze
�r�ed+difg7Ze�r�ed,difg7Ze�r�ed-difg7Ze�r�ed.difg7Ze�r�ed/dd0d1ifg7ZgZe�reddifg7Znedejfifg7Ze
�rJed*ejd2fifg7Ze	�r�e�rned)ejd3fifg7Zned)ejfifg7Ze
�r�ed+e�gfifg7Zd4ejfifd5difd6difd7difd8difgZe�r�ed4ejfifg7Zed4ejfifg7ZeeeeZd9d:�ZdDd;d<�Zd=d>�Z e!d?d@��Z"e!dAdB��Z#dCS)ErDaA container that lists all Process class method names + some
    reasonable parameters to be called with. Utility methods (parent(),
    children(), ...) are excluded.

    >>> ns = process_namespace(psutil.Process())
    >>> for fun, name in ns.iter(ns.getters):
    ...    fun()
    �cpu_percentrxZmemory_percentr�rrTrUZmemory_info_exZoneshotr��parentsr�r��rZcmdlineZconnections�kind�all�	cpu_timesZcreate_timer�rwrZZmemory_infor��niceZnum_ctx_switchesZnum_threadsZ
open_filesZppidr�rpZusernameZuidsZgidsZterminalr]rkrgrlrcrjrfr^rhZgroupedF)r�irr�ZsuspendZresumer:�killcCs
||_dSr�)�_proc)r�r�rxrxryr��szprocess_namespace.__init__ccsZt|�}t�|�|D]>\}}}|r,|��t|j|�}tj|f|�|�}||fVqdS�z_Given a list of tuples yields a set of (fun, fun_name) tuples
        in random order.
        N)r�r��shuffle�clear_cacher�r�r�r=)r��lsr��fun_namer�r�r�rxrxry�iter�s
zprocess_namespace.itercCs|jj|jjdd�dS)z&Clear the cache of a Process instance.T)Z_ignore_nspN)r�Z_initr�r�rxrxryr��szprocess_namespace.clear_cachecCs>|D]4\}}}d|}t||�sd|jj|f}t|��qdS)z}Given a TestCase instance and a list of tuples checks that
        the class defines the required test method names.
        Ztest_z$%r class should define a '%s' methodN)r!r�r��AttributeError)�clsZ
test_classr�r�r�Z	meth_namerbrxrxry�test_class_coverage�s
�z%process_namespace.test_class_coveragecCs`tdd�|jD��}tdd�|jD��}tdd�ttj�D��}||B|A}|r\td|��dS)NcSsg|]}|d�qSr�rxr�rxrxryr�
sz*process_namespace.test.<locals>.<listcomp>cSsg|]}|d�qSr�rxr�rxrxryr�scSsg|]}|ddkr|�qS)rr�rxr�rxrxryr�sz!uncovered Process class names: %r)r�r��ignoredr�r�r�r�)r��thisr��klassZleftoutrxrxry�testszprocess_namespace.testN)T)$r�r�r�r�Zutilsr��gettersr
r0r1r4r�Z
RLIMIT_NOFILEr-r3r/rr2ZsettersZNORMAL_PRIORITY_CLASSrZIOPRIO_CLASS_NONEZ
IOPRIO_NORMALr�r��SIGTERMZkillersZCTRL_C_EVENTZCTRL_BREAK_EVENTr�r�r�r��classmethodr�r�rxrxrxryrD�s�	��
��


c@s�eZdZdZddifddddifddddifddifd	dd
difd	dd
difddddifd
dddifde��fifddddifddifddifddddifde��fifddifddifddifddifgZer�eddd
difg7Ze	r�eddifg7Ze
�reddifg7Ze�r$eddifg7Ze�r:eddifg7Ze
�r`ed difg7Zed!d"ifg7Zd#difd$e��gfifd%difd&difgZeZed'd(��ZejZd)S)*rEz�A container that lists all the module-level, system-related APIs.
    Utilities such as cpu_percent() are excluded. Usage:

    >>> ns = system_namespace
    >>> for fun, name in ns.iter(ns.getters):
    ...    fun()
    r�rxrZlogicalFTZ	cpu_statsr�ZpercpuZdisk_io_countersZperdiskZdisk_partitionsr�Z
disk_usageZnet_connectionsr�Znet_if_addrsZnet_if_statsriZpernicrrVr�Zusersr�rdrerornrmZwin_service_iterZwin_service_get)ZalgZprocess_iterrr�Zcpu_times_percentccsLt|�}t�|�|D]0\}}}tt|�}tj|f|�|�}||fVqdSr�)r�r�r�r�r�r�r=)r�r�r�r�r�rxrxryr�Hs

zsystem_namespace.iterN)r�r�r�r�r~r�r�r�r.�HAS_GETLOADAVGr8r7r5rr�r�r�r��staticmethodr�rDr�rxrxrxryrEsT��
cCst�|�st|��d|_|S)zA decorator to mark a TestCase class. When running parallel tests,
    class' unit tests will be run serially (1 process).
    T)�inspectZisclassr�Z
_serialrun)r�rxrxry�	serialrunWsr�cCsdd�}ttd||d�S)zZDecorator which runs a test function and retries N times before
    actually failing.
    cSstd|tjd�dS)Nz%r, retryingr�)rmr�rr)r-rxrxryr*esz retry_on_failure.<locals>.logfunN)r'r�r(r*)r&r�)r(r*rxrxryrAas�cs�fdd�}|S)z,Decorator to Ignore AccessDenied exceptions.cst�����fdd��}|S)Ncs@z�||�WStjk
r:�dk	r,�s,�t�d��YnXdS)Nzraises AccessDenied)r�ZAccessDeniedrR�SkipTestr��r��only_ifrxryr�osz9skip_on_access_denied.<locals>.decorator.<locals>.wrapperr�r��r�r�ryr/nsz(skip_on_access_denied.<locals>.decoratorrx�r�r/rxr�ryr?lscs�fdd�}|S)z3Decorator to Ignore NotImplementedError exceptions.cst�����fdd��}|S)NcsHz�||�WStk
rB�dk	r*�s*�d�j}t�|��YnXdS)Nz4%r was skipped because it raised NotImplementedError)rr�rRr�)r�r�rbr�rxryr�s�z;skip_on_not_implemented.<locals>.decorator.<locals>.wrapperr�r�r�r�ryr/~s
z*skip_on_not_implemented.<locals>.decoratorrxr�rxr�ryr@|s
�	127.0.0.1c
Cs@t�t����(}|�|df�|��dW5QR�SQRXdS)z6Return an unused TCP port. Subject to race conditions.rrN)�
contextlib�closing�socket�bind�getsockname)Zhostr�rxrxryrQ�scCs�|dkr|ttfkrd}t�||�}z@tjdkrB|�tjtjd�|�|�|tj	kr`|�
d�|WStk
r�|���YnXdS)zBinds a generic socket.N�rr)�nt�cygwinrr^)
rrr�r~r�Z
setsockoptZ
SOL_SOCKETZSO_REUSEADDRr�r�listenrvr�)�family�type�addrr�rxrxryrR�s



cCsrtjs
t�tj�|�rt|��t�tj|�}z"|�|�|tj	krL|�
d�Wntk
rl|���YnX|S)zBind a UNIX socket.r^)
r�r
r�r~rr�r�r�r�rr�rvr�)r�r�r�rxrxryrS�s


r�c
Cs�t�t�|t����}|�|�|�d�|��}t�|t�}zJ|�|�|��}|��\}}||krz||fWW5QR�S|�	�qPWnt
k
r�|�	��YnXW5QRXdS)z^Build a pair of TCP sockets connected to each other.
    Return a (server, client) tuple.
    r^N)r�r�r�rr�r�r��connectr�r�r)r�r�ZllrZcaddr�arxrxryrT�s


cCs�tjs
t�d}}z@t|tjd�}|�d�t�tjtj�}|�d�|�|�Wn6t	k
r�|dk	rr|�
�|dk	r�|�
��YnX||fS)z�Build a pair of UNIX sockets connected to each other through
    the same UNIX file name.
    Return a (server, client) tuple.
    N�r�r)r�r
r�rSr�rZsetblockingr�r�rvr�)r�ZserverZclientrxrxryrU�s


c	cs�g}d}}z�|�ttjtj��|�ttjtj��t�rd|�ttj	tj��|�ttj	tj��t
r�tr�t�}t�}t
|�\}}t|tjd�}|||fD]}|�|�q�|VW5|D]}|��q�||fD]}|dk	r�t|�q�XdS)z1Open as many socket families / types as possible.Nr�)r�rHrlrRr�rr�
SOCK_DGRAMrrr
�HAS_CONNECTIONS_UNIXrJrUrS)ZsocksZfname1Zfname2r�r4�s1�s2Zs3rxrxryrV�s*

cCsddl}tr(tr(ts(t|tj�s(t|��|tjkr�dd�|�	d�D�}t
|�dksZt|��|D]"}d|krvdks^nt|��q^ts�t|�}|�|�nb|tj
kr�t|t�s�t|��ts�t|�}|�|�n.|tjkr�t�d|�dk	s�t|��n
td	|��dS)
z[Check a net address validity. Supported families are IPv4,
    IPv6 and MAC addresses.
    rNcSsg|]}t|��qSrx)r�r�rxrxryr�sz%check_net_address.<locals>.<listcomp>rr�z([a-fA-F0-9]{2}[:|\-]?){6}zunknown family %r)�	ipaddress�enumrr"r��IntEnumr�r�rrrrZIPv4Addressrr�ZIPv6Addressr�ZAF_LINKr"�matchr�)r�r�r�ZoctsZnumrxrxryrPs&
 

cCsTdd�}dd�}dd�}dd�}d	d
�}||�||�||�||�||�dS)z*Check validity of a connection namedtuple.cSs�t|�dk}t|�dks$tt|���|d|jks<t|j��|d|jksTt|j��|d|jkslt|j��|d|jks�t|j��|d|jks�t|j��|d|jks�t|j��|r�|d	|jks�t|j��dS)
N�)rr�rrr}rrr^r)	rr�rdr�r��laddr�raddrr�r�)r�Zhas_pidrxrxry�check_ntuple sz-check_connection_ntuple.<locals>.check_ntuplecSs�|jtttfkst|j��tdk	r:t|jtj�sNt|��nt|jt�sNt|��|jtkr�t	�	|j|j
�}t�|��Rz|�
|jddf�Wn2t	jk
r�}z|jtjkr��W5d}~XYnXW5QRXn |jtkr�|jtjks�t|j��dS)Nr)r�rrr�r�r�r�r�r�r�r�r�r�r�r��errorrZ
EADDRNOTAVAILr�r��	CONN_NONE)r�r�rrxrxry�check_family,s
 
z-check_connection_ntuple.<locals>.check_familycSs�ttdt��}|jtjtj|fks,t|j��tdk	rLt|jtj	�s`t|��nt|jt
�s`t|��|jtjkr�|jtj
ks�t|j��dS)N�SOCK_SEQPACKET)r�r��objectr�rr�r�r�r�r�r�r�r�r�)r�r�rxrxry�
check_typeAs��z+check_connection_ntuple.<locals>.check_typecSs�|j|jfD]�}|jttfkr�t|t�s4tt|���|s:qt|j	t
�sTtt|j	���d|j	krjdksvnt|j	��t|j|j�q|jt
krt|t�stt|���qdS)Nri��)r�r�r�rrr�r�r�r�Zportr�rPZipr�r�)r�r�rxrxry�check_addrsMs"
z,check_connection_ntuple.<locals>.check_addrscSs�t|jt�st|j��dd�tt�D�}|j|ks<t|j��|jttfkrl|j	t
krl|jtjks�t|j��n|jtjks�t|j��dS)NcSs g|]}|�d�rtt|��qS)ZCONN_r�r�rxrxryr�\s
�zAcheck_connection_ntuple.<locals>.check_status.<locals>.<listcomp>)r�r�r�r�r�r�r�rrr�rr�)r�Zvalidsrxrxry�check_statusZsz-check_connection_ntuple.<locals>.check_statusNrx)r�r�r�r�r�r�rxrxry�check_connection_ntuples

r�cCsPzddl}t|d�st�Wn&tk
r@ddl}|�|�YSX|�|�SdS)z,Backport of importlib.reload of Python 3.3+.rN�reload)�	importlibr!r��impr�)�moduler�r�rxrxryrWps
cCs�tj�tj�|��d}tjddkr:ddl}|�||�Stjdd�dkrfddlm	}|||��
�Sddl}|j�
||�}|j�|�}|j�|�|SdS)Nrr}r)�SourceFileLoader)r~r�splitextr�r�r�r�Zload_sourceZimportlib.machineryr��load_module�importlib.util�util�spec_from_file_location�module_from_spec�loader�exec_module)rr�r�r�r��spec�modrxrxryrX}scCst�|t�dS)zRaise a warning msg.N)�warningsrY�UserWarning)rbrxrxryrY�scCsVt|�}|j}t|�dks&|dtkr*dSt|dd�}t|t�sDdStdd�|D��S)z-Check if object is an instance of namedtuple.rrF�_fieldsNcss|]}t|�tkVqdSr�)r�r�)r��nrxrxry�	<genexpr>�sz is_namedtuple.<locals>.<genexpr>)r��	__bases__rr�r�r�r�)r��t�br�rxrxryr[�s
c#sttrdnd�d�t|�d�}��fdd�t����D�}t�|�}t�||�zt
�|�|VW5t	|�XdS)z�Ctx manager which picks up a random shared CO lib used
        by this process, copies it in another location and loads it
        in memory via ctypes. Return the new absolutized path.
        r{r|z.sorFcs6g|].}tj�|j�d�kr�|j��kr|j�qS)r)r~rr��lowerr��rw�extrxryr��s��'copyload_shared_lib.<locals>.<listcomp>N)r"rJr�r�rhr�r�r>rIrH�ctypesZCDLL)rG�dst�libsr�rxrryrZ�s


c	#s�ddlm}ddlm}d�t|�d�}�fdd�t����D�}trb|sbdd�t����D�}t�	|�}t
�||�d	}zt�|�}|VW5|d	k	r�tjj
j}|jg|_||j�}|dkr�|�t|�Xd	S)
z�Ctx manager which picks up a random shared DLL lib used
        by this process, copies it in another location and loads it
        in memory via ctypes.
        Return the new absolutized, normcased path.
        r)�wintypes)�WinErrorz.dllrFcsFg|]>}|j�����rdtj�|j���krd|j��kr|j�qS)r|Zwow64)rrr�r~r�r��rrxryr��s
�rcSs(g|] }dtj�|j���kr|j�qS)r{)r~rr�rr�rxrxryr��s�N)rr	r
rJr�r�rhr"r�r�r>rIZwindllZkernel32�FreeLibraryZHMODULEZargtypesZ_handlerHZWinDLL)	rGr	r
rrr��cfilerr8rxrryrZ�s(





cCstdd�dS)NTr)r;rxrxrxry�cleanup_test_procs�srcCs
t�|�Sr�)r��exit)r�framerxrxryr��r�r�)N)F)TF)N)rN)N)N)r�)r�)r)r)�r�Z
__future__r�atexitr�rrr�rir�r~r�r"r�r>r�r�r:rsr�rMr�r�r�r�rrrr�rrrr	r
rrZpsutil._commonr
rrZpsutil._compatrrrrrrrrrRZ	unittest2rr��catch_warnings�simplefilterr�r��__all__�builtin_module_namesr"rfrr\r)�maxsizer,r!r r+rr�r�r&r'�decoder(r�rZASCII_FSrr�r�rC�__file__r$r%ZHEREr�r!r�r-r.r�r/r1r2ZHAS_NET_IO_COUNTERSr3r0r4r5rHrmr6rvr7r8ZHAS_THREADS�getuidZSKIP_SYSCONSr�r#r��devnullr�registerr�r�r*r�r�r�r�r�r�r�r�r�r<r>r=r9r�r�r:r;rLrKr&r�rNr�rOrMrHrB�contextmanagerrGrIrJrNrCZskipIfrBrFr�rDrEr�rAr?r@rQrRrSrTrUrVrPr�rWrXrYr[rZrrxrxrxry�<module>s�



�-



�






 0'
&-

X
%:
�


��
!



1
[	
B





R
,


Filemanager

Name Type Size Permission Actions
__init__.cpython-38.opt-1.pyc File 44.89 KB 0644
__init__.cpython-38.pyc File 46.44 KB 0644
__main__.cpython-38.opt-1.pyc File 285 B 0644
__main__.cpython-38.pyc File 285 B 0644
runner.cpython-38.opt-1.pyc File 10.84 KB 0644
runner.cpython-38.pyc File 10.84 KB 0644
test_aix.cpython-38.opt-1.pyc File 3.3 KB 0644
test_aix.cpython-38.pyc File 3.3 KB 0644
test_bsd.cpython-38.opt-1.pyc File 19.53 KB 0644
test_bsd.cpython-38.pyc File 19.53 KB 0644
test_connections.cpython-38.opt-1.pyc File 15.13 KB 0644
test_connections.cpython-38.pyc File 15.43 KB 0644
test_contracts.cpython-38.opt-1.pyc File 24.81 KB 0644
test_contracts.cpython-38.pyc File 25.64 KB 0644
test_linux.cpython-38.opt-1.pyc File 67.56 KB 0644
test_linux.cpython-38.pyc File 68.67 KB 0644
test_memleaks.cpython-38.opt-1.pyc File 22.59 KB 0644
test_memleaks.cpython-38.pyc File 22.59 KB 0644
test_misc.cpython-38.opt-1.pyc File 22.69 KB 0644
test_misc.cpython-38.pyc File 22.92 KB 0644
test_osx.cpython-38.opt-1.pyc File 7.1 KB 0644
test_osx.cpython-38.pyc File 7.1 KB 0644
test_posix.cpython-38.opt-1.pyc File 12.36 KB 0644
test_posix.cpython-38.pyc File 12.46 KB 0644
test_process.cpython-38.opt-1.pyc File 45.69 KB 0644
test_process.cpython-38.pyc File 46.52 KB 0644
test_sunos.cpython-38.opt-1.pyc File 1.5 KB 0644
test_sunos.cpython-38.pyc File 1.5 KB 0644
test_system.cpython-38.opt-1.pyc File 25.65 KB 0644
test_system.cpython-38.pyc File 26.92 KB 0644
test_testutils.cpython-38.opt-1.pyc File 15.6 KB 0644
test_testutils.cpython-38.pyc File 16.27 KB 0644
test_unicode.cpython-38.opt-1.pyc File 10.87 KB 0644
test_unicode.cpython-38.pyc File 10.87 KB 0644
test_windows.cpython-38.opt-1.pyc File 27.81 KB 0644
test_windows.cpython-38.pyc File 28 KB 0644