Uname:Linux server2.hostofiraq.site 5.15.0-186-generic #196-Ubuntu SMP Sat Jun 20 16:09:34 UTC 2026 x86_64

Base Dir : /home/iscmbt-kufa-atu/public_html

User : iscmbt-kufa-atu


403WebShell
403Webshell
Server IP : 89.117.53.150  /  Your IP : 216.73.216.11
Web Server : Apache
System : Linux server2.hostofiraq.site 5.15.0-186-generic #196-Ubuntu SMP Sat Jun 20 16:09:34 UTC 2026 x86_64
User : iscmbt-kufa-atu ( 1014)
PHP Version : 8.2.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/psutil/tests/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/psutil/tests/__pycache__/__init__.cpython-310.pyc
o

���a���@s4dZddlmZddlZddlZddlZddlZddlZddlZddl	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(e4�ye�5��e�6d�ddl3Z3Wd�n	1�swYYnwej7dk�r)ddl8Z8ndZ8e!�r4ddl9m:Z:gd�Z;dej<vZ=de
j>vZ?d e
j>v�pLd!e
j>vZ@e?�pQe@ZAejBd"kZCd#ZDd$ZEd%ZFd&ZGeA�rreDd'9ZDeGd'9ZGeEd'9ZEeFd'9ZFe
jHd(k�rd)e
�I�ZJnd*e
�I�ZJe.d+�ZKe)�r�d,�Ld-d.�ZMnd/ZMe�N��O�d0vZPe
jQ�Re
jQ�Se
jQ�TeU�d1d1��ZVe
jQ�SeVd2�ZWe
jQ�Re
jQ�TeU��ZXe!�o�e"ZYeZej[d3�Z\eZed4�Z]eZed5�Z^eZej[d6�Z_eZej[d7�Z`eZej[d8�ZaeZed9�ZbeZej[d:�ZceZej[d;�ZdeZej[d<�ZeeZed=�Zfzef�oege�h��ZiWnej�yd>ZiYnweZed?�ZkeZed@�ZleZej[dA�Zme �s0e�o5e
�n�dkZodBdC�Zpep�Zqere
jsdD�Zte�uetjv�dEdF�ewe�D�ZxeyedGez��Z{e|�Z}e|�Z~GdHdI�dIej�Z�dJdK�Z�e�d�dLdM��Z�e�dNdO��Z�dPdQ�Z�e�dRdS��Z�e�dTdU��Z�ej�eGfdVdW�Z�d�dXdY�Z�dZd[�Z�d\d]�Z�Gd^d_�d_ez�Z�e�ej�deGd`da�dbdc��Z�e�e+e�fdeGd`da�d�dedf��Z�e�e�deGd`da�dgdh��Z�didj�Z�dkdl�Z�ej�dmdn��Z�d�dodp�Z�d�drds�Z�Gdtdu�due1j��Z�e�e1_�Gdvdw�dwe��Z�e1��e=dx�Gdydz�dze���Z�d{d|�Z�d}d~�Z�Gdd��d��Z�Gd�d��d��Z�d�d��Z�eDfd�d��Z�d�d�d��Z�d�d�d��Z�d�d�d��Z�eedfd�d��Z�ejfd�d��Z�d�d�d��Z�d�d��Z�ej�d�d���Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�e!�r{ej�d�d�d���Z�nej�d�d�d���Z�ejud�d���Z�e!�r�e�ej�d�d���dSdS)�z
Test utilities.
�)�print_functionN)�AF_INET)�AF_INET6)�SOCK_STREAM)�AIX)�FREEBSD)�LINUX)�MACOS)�POSIX)�SUNOS)�WINDOWS)�bytes2human)�print_color)�
supports_ipv6)�PY3)�FileExistsError)�FileNotFoundError)�range)�super)�u)�unicode)�which)�mock�ignore���)�wait_pid)E�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_TEMPERATURES�HAS_MEMORY_FULL_INFO�pyrun�	terminate�
reap_children�spawn_testproc�spawn_zombie�spawn_children_pair�ThreadTaskunittest�skip_on_access_denied�skip_on_not_implemented�retry_on_failure�TestMemoryLeak�PsutilTestCase�process_namespace�system_namespace�
print_sysinfo�install_pip�install_test_deps�chdir�safe_rmpath�
create_exe�decode_path�encode_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_namedtuple�__pypy__r�GITHUB_ACTIONS�CIBUILDWHEELl�
iPi��r�javaz$psutil-%s-z@psutil-%s-u-ƒőősf���utf8�surrogateescapeufÀ€)�asciizus-asciiz..�scripts�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�}trtrtrtd�Std�Strtj�tj	�Std�St
rL|tj	�pC|tj�tj	��pC|tdtjdd���pC|t�
����}|sJtd��|Stj�tj	�}tj�|�s]J|��|S)	NcSs4ztj|dgtjtjd�W|StyYdSw)Nz-V)�stdout�stderr)�
subprocess�
check_call�PIPE�	Exception)�exe�r��7/usr/lib/python3/dist-packages/psutil/tests/__init__.py�attempt�s���z_get_py_exe.<locals>.attempt�pypy3�pypy�pythonzpython%s.%s�z"can't find python exe real abspath)rdr#rrr�os�path�realpath�sys�
executabler	�version_info�psutil�Processr��
ValueError�exists)r�r�r�r�r��_get_py_exe�s*	
���r�zr+cC� g|]}|�d�rtt|��qS)�STATUS_��
startswith�getattrr���.0�xr�r�r��
<listcomp>���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�	threading�Event�_flag��self��	__class__r�r�r��s
zThreadTask.__init__cCs|jj}d||jt|�fS)Nz<%s running=%s at %#x>)r��__name__r��id)r��namer�r�r��__repr__szThreadTask.__repr__cCs|��|S�N)�startr�r�r�r��	__enter__szThreadTask.__enter__cOs|��dSr�)�stop)r��args�kwargsr�r�r��__exit__
szThreadTask.__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�r�r�r�r�
szThreadTask.startcCs0d|_|j��|jrt�|j�|jsdSdS)NT)r�r��set�time�sleepr�r�r�r�r��runs

�zThreadTask.runcCs |jstd��d|_|��dS)z8Stop thread execution and and waits until it is stopped.zalready stoppedFN)r�r��joinr�r�r�r�r�szThreadTask.stop)r��
__module__�__qualname__�__doc__r�r�r�r�r�r�r��
__classcell__r�r�r�r�r��s	r�cst����fdd��}|S)Ncs(z�|i|��WStyt��wr�)r�r=�r�r���funr�r��wrapper*s�z&_reap_children_on_err.<locals>.wrapper��	functools�wraps�r�r�r�r�r��_reap_children_on_err)sr�cKs�|�dt�|�dt�|�dt���|�dtj�tr%d}|�d|�|dur[t�}z)t|�d|}td	|g}t	j
|fi|��}t�|�t
|d
d
d�Wt|�|St|�wt	j
|fi|��}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().
    �stdinr{�cwd�env��
creationflagsNz:from time import sleep;open(r'%s', 'w').close();sleep(60);z-cT��delete�empty)�
setdefaultrr��getcwdrprrQrMr$r}�Popen�_subprocesses_started�addrVrU�pid)�cmd�kwds�CREATE_NO_WINDOW�testfn�pyline�sprocr�r�r�r>4s2
�


�

r>cCs�d}tt��d�}zIt�dtj�|�tf�}tr"t	|dd�\}}nt	|�\}}t
�|j�}t
t|ddd��}t�|�t
�|�}||fWt|�|durRt|�SSt|�|dur`t|�ww)	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�)rQr�r��textwrap�dedentr��basenamer$rr;r�r�r��intrV�
_pids_startedr�rM)�tfiler��s�subp�child�grandchild_pid�
grandchildr�r�r�r@\s,	�



��
�r@cs�tjsJ�t�}t�d|�}d}t|�}zW|�t�t|�\}}|�	�\}}z@t
�
|��gggt�t|�
d��}t�|�t�|��t�fdd�d�|�fW|��W|��t|�|durgt|�SS|��w|��t|�|dur~t|�ww)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�)�statusr���zombier�r��<lambda>�szspawn_zombie.<locals>.<lambda>zret == psutil.STATUS_ZOMBIE)r�r
rQr�r�rZ�
settimeoutr r;�accept�select�filenor��recvr�r�r�rT�closerM)�	unix_file�srcr��sock�parent�conn�_�zpidr�r�r�r?�s<
�




�
�
�r?cKs�|�dd�|�dd�t�}z/t|d��
}|�|�Wd�n1s%wYtt|jgfi|��}t|j�||fWSt	yJt
|��w)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.
    r{Nr|�wt)r�rQ�open�writer>r$r�rUr�r�rM)r�r��srcfile�fr�r�r�r�r;�s�

�r;cKs�t|ttf�r	dnd}tr|rdnd}|�d|�|�dtj�|�dtj�|�dd�|�d	|�tj|fi|��}t�	|�t
rL|jtd
�\}}n|��\}}|j
dkr[t|��|rat|�|�d�rl|dd
�}|S)zUrun cmd in a subprocess and return its output.
    raises RuntimeError on error.
    TFr�r�shellr{r|�universal_newlinesr���timeout�
N���)�
isinstance�strrrr�r}rr�r�r�r�communicater �
returncode�RuntimeErrorr`�endswith)r�r�r�flags�pr{r|r�r�r��sh�s&


rc
s�dd��dd�����fdd�}���fdd���fd	d
�}dd�}|}z�t|t�rP|||�Wt|tjtjf�r<||�t|t�rC|n|j}t�|�rOJ|��St|tjtjf�r�||�Wt|tjtjf�rk||�t|t�rr|n|j}t�|�r~J|��St|tj�r�|||�Wt|tjtjf�r�||�t|t�r�|n|j}t�|�r�J|��Std
|��t|tjtjf�r�||�t|t�r�|n|j}t�|�r�J|��w)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.
    cSsht|tj�r
ts
|��n|�|�tr0t|tj�r2z
t�|j��|�WStj	y/YdSwdSdSr�)
rr}r�rr�rr�r�r��
NoSuchProcess��procrr�r�r�r��s

��zterminate.<locals>.waitcSs6trtrtj}tr|tjkr|�tj�|�|�dSr�)r	rd�signal�SIGKILLr
�send_signal�SIGCONT)r�sigr�r�r��sendsig�s
zterminate.<locals>.sendsigc
s\z�|��Wn!ty(}ztr|jdkrn|jtjkr�WYd}~nd}~ww�||�S)N�)�OSErrorr�winerror�errno�ESRCH)rr�err�rrr�r�r��term_subprocs��
zterminate.<locals>.term_subproccs.z�|��Wn
tjyYnw�||�Sr�)r�rrr r�r��term_psproc
s�
zterminate.<locals>.term_psproccsBzt�|�}Wntjytrt||�YSYdSw�||�Sr�)r�r�rr
r)r�rr)r"r�r��term_pids��
zterminate.<locals>.term_pidcSs8|jr|j��|jr|j��|jr|j��dSdSr�)r{r�r|r�)rr�r�r��flush_popens

�zterminate.<locals>.flush_popenz
wrong type %r)	rr�r}r�r�r��
pid_existsr��	TypeError)�proc_or_pidr�wait_timeoutr!r#r$rr�r�)rrr"r�r�r<�s>



	

�
�
�r<cCs�t��j|d�}trt��}t|�ts
tr t��}t|�ts|rH|D]}t|dd�q$tj|td�\}}|D]}t	d|�t|t
jd�q8dSdS)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)r(rz0couldn't terminate process %r; attempting kill())r)r�r��childrenr��popr<r��
wait_procsr r`rr)r*r+r�r�r�gone�aliver�r�r�r=5s$
���r=cCs�tstd��d}t��d}|D]}|��s|dkr||7}q|s(td|��d}d}|�d�}t|d�}t|�dkrCt|d�}t|�dkrOt|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�r4�c�minor�micro�nums�majorr�r�r�rSZs&


rScCsdtstd��t��}t|d�r|jpd}nt�d|d�}|r't|�	d��}nd}|d|d|fS)Nznot WINDOWS�service_pack_majorrz\s\d$rr2)
rr3r��getwindowsversion�hasattrr=�re�searchr��group)�wv�sp�rr�r�r�rRrs
rRc@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�rGrrHrIrJr�r�r�r��s
zretry.__init__ccsf�|jrt��|j}t��|krdVt��|ksdSdS|jr.t|j�D]}dVq&dS	dVq/r�)rr�rHr)r��stop_atr�r�r�r��__iter__�s����zretry.__iter__cCs|jdur
t�|j�dSdSr�)rIr�r�r�r�r�r�r��s
�zretry.sleepcs"t�����fdd��}�|_|S)Ncsrd}�D]/}z
�|i|��WS�jy3}z|}�jdur%��|����WYd}~qd}~wwtr8|��r�)rGrJr�r)r�r��excr��r�r�r�r�r��s

��zretry.__call__.<locals>.wrapper)r�r��	decorator)r�r�r�r�rNr��__call__�szretry.__call__)	r�r�r�r�r�r�rLr�rPr�r�r�r�rF�s
�rFr�)rGrJrrIcCs t�|�trt�d�dSdS)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�r�r�r�rU�s
�rUTcCsNt|d��}|��}Wd�n1swY|s|sJ�|r%t|�|S)z8Wait for a file to be written on disk with some content.�rbN)r��readrM)�fnamer�r�r�datar�r�r�rV�s
�rVcCs|�}t|�s	J�|S)zVKeep calling function for timeout secs and exit if eval()
    expression is True.
    )�eval)r��expr�retr�r�r�rT�srTcCspdd�}z)t�|�}t�|j�rt�tj|�}nt�tj|�}t	r'|�WdS||�WdSt
y7YdSw)z>Convenience function for removing temporary test files or dirsc
Ss�t��t}t��|kr@z|�WStyYnty4}z|}tdt|��WYd}~nd}~wwt�d�t��|ks|�)Nzignoring %srQ)r�r r�WindowsErrorr`r	r�)r�rKr�rr�r�r��	retry_fun�s��
�	zsafe_rmpath.<locals>.retry_funN)r��stat�S_ISDIR�st_moder��partial�shutil�rmtree�remover
r)r�rZ�str�r�r�r�rM�s
�rMcCs&zt�|�WdStyYdSw)z-Convenience function for creating a directoryN)r��mkdirrr�r�r�r��
safe_mkdir
s
�rdc	cs8�t��}zt�|�dVWt�|�dSt�|�w)z@Context manager which temporarily changes the current directory.N)r�r�rL)�dirname�curdirr�r�r�rLs�
rLcCs�tj�|�r
J|��|r]td�std��t|t�rt�d�}t|t	�s'J|��t
tdd�d��
}|�|�Wd�n1s?wYzt
�d|jd|g�Wt|j�dSt|j�wt�t|�trvt�|�}t�||jtjB�dSdS)	z1Creates an executable file in the given location.�gcczgcc is not installedz�
                #include <unistd.h>
                int main() {
                    pause();
                    return 1;
                }
                z.c��suffixr�Nz-o)r�r�r�rr�r�boolr�r�r	r�rQr�r}r~r�rMr_�copyfiler$r
r[�chmodr]�S_IEXEC)�outpath�c_coderrbr�r�r�rNs(
��
�rNr0cCs,	tjt||d�}tj�|�stj�|�Sq)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.
    T)�prefixrir�)�tempfile�mktempr'r�r�r�r�)rir�r�r�r�r�rQ;s
�rQc@s8eZdZdd�Zeejd�sejjZe	sdd�Z
dSdS)�TestCasecCs.|jj}|�d�s
d|}d||jj|jfS)Nzpsutil.z
psutil.tests.z%s.%s.%s)r�r�r�r��_testMethodName)r��fqmodr�r�r��__str__Ps
�zTestCase.__str__�assertRaisesRegexcCsdSr�r�r�r�r�r��runTest^szTestCase.runTestN)r�r�r�rvr?�unittestrs�assertRaisesRegexprwrrxr�r�r�r�rsLs	�rsc@sBeZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)rFzUTest class providing auto-cleanup wrappers on top of process
    test utilities.
    r0NcCst||d�}|�t|�|S)N)rir�)rQ�
addCleanuprM)r�rir�rTr�r�r�rQkszPsutilTestCase.get_testfncOst|i|��}|�t|�|Sr�)r>r{r<)r�r�r�r�r�r�r�r>pszPsutilTestCase.spawn_testproccC�*t�\}}|�t|�|�t|�||fSr�)r@r{r<)r��child1�child2r�r�r�r@u�
z"PsutilTestCase.spawn_children_paircCr|r�)r?r{r<)r�r�r�r�r�r�r?{rzPsutilTestCase.spawn_zombiecOs.t|i|��\}}|�t|�|�t|�|Sr�)r;r{rMr<)r�r�r�r�rr�r�r�r;�szPsutilTestCase.pyruncCs�|�tjtj|j�t|tjtjf�r6|��rJ�z|��}Wn
tjy)Ynwt	d|��|j
dd�t�|j�rAJ|j��|�|jt�
��dS)Nz3Process.status() didn't raise exception (status=%s)rr)�assertRaisesr�rr�r�rr��
is_runningr��AssertionErrorr�r%�assertNotIn�pids)r�rr�r�r�r��assertProcessGone�s��z PsutilTestCase.assertProcessGone�r0N)
r�r�r�r�rQr>r@r?r;r�r�r�r�r�rFfs
rFzunreliable on PYPYc@s�eZdZdZdZdZdZerdndZdZ	e
��Ze
e�dd��Zedd	��Zed
d��Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z		ddd�Zdd�ZdS) rEa�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)
    ��rfrrgT�PSUTIL_DEBUGcCst�d�dS)NF)r��
_set_debug��clsr�r�r��
setUpClass��zTestMemoryLeak.setUpClasscCst�|j�dSr�)r�r��_psutil_debug_origr�r�r�r��
tearDownClass��zTestMemoryLeak.tearDownClasscCs|j��}t|d|j�S)N�uss)�	_thisproc�memory_full_infor��rss)r��memr�r�r��_get_mem�s
zTestMemoryLeak._get_memcCstr|j��S|j��Sr�)r
r��num_fds�num_handlesr�r�r�r��_get_num_fds�s

zTestMemoryLeak._get_num_fdscCs|jr
t|dtjd�dSdS)N�yellow)�color�file)�verboserr�r|)r��msgr�r�r��_log�s�zTestMemoryLeak._logcCsx|��}|�|�|��}||}|dkr|�d|��|dkr:tr$dnd}|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)�fd�handler2r�z%s unclosed %s after calling %rN)r��call�failr
)r�r��before�after�diff�type_r�r�r�r��
_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.
        r2)�
generation)�gc�collectr�rr��assertEqual�garbage)r�r��times�mem1r�rX�mem2r�r�r�r��_call_ntimes�s
zTestMemoryLeak._call_ntimesc
Cs�g}d}|}td|d�D]C}	|�||�}
d|	t|
�t|
|�|f}|�|�|
|kp/|
|k}|r>|	dkr;|�|�dS|	dkrEt�|�|�||7}|
}q
|�d�|���)Nrr2z,Run #%s: extra-mem=%s, per-call=%s, calls=%sz. )rr�r
�appendr��printr�r�)
r�r�r��warmup_timesrH�	tolerance�messages�prev_mem�increase�idxr�r��successr�r�r��
_check_mem�s(�


zTestMemoryLeak._check_memcCs|�Sr�r�)r�r�r�r�r�r�szTestMemoryLeak.callNc
Cs�|dur|n|j}|dur|n|j}|dur|n|j}|dur!|n|j}z"|dks-Jd��|dks5Jd��|dks=Jd��|dksEJd��WntyX}ztt|���d}~ww|�||�|�|�|j	|||||d�dS)	zTest a callable.Nr2ztimes must be >= 1rzwarmup_times must be >= 0zretries must be >= 0ztolerance must be >= 0)r�r�rHr�)
r�r�rHr�r�r�r	r�r�r�)r�r�r�r�rHr�rr�r�r��executes(���


�zTestMemoryLeak.executecs&���fdd�}�j|fi|��dS)znConvenience method to test a callable while making sure it
        raises an exception on every call.
        cs�����dSr�)r�r��rMr�r�r�r�r�-sz*TestMemoryLeak.execute_w_exc.<locals>.callN)r�)r�rMr�r�r�r�r�r��
execute_w_exc)szTestMemoryLeak.execute_w_exc)NNNN)r�r�r�r�r�r�r�r*rHr�r�r�r�rjr��getenvr��classmethodr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rE�s0


�rEcCs�ddl}ddl}ddl}ddl}ddl}ddl}zddl}Wnty)d}Ynwzddl}Wnty;d}Ynw|�	�}t
jrNtd�rNt
d�|d<n=t
jr\d|��d|d<n/t
jrdd�tt|����|d<t|d�r~|dd	|��7<nd
|��|��f|d<d	�t|���|��g�|d<t
jr�|��d|d
<d	�|��|��|� �g�|d<t!|dd�|d<|dur�|dd|j"7<t
jr�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��q�tDd0t%jEd1�t%jG�H�dS)4Nr�lsb_releasezlsb_release -d -s�OSz	Darwin %szWindows � �
win32_editionz, z%s %s�archr��kernelr��__version__z
not installed�pipz (wheel=%s)rgz	--versionrr2�glibczfs-encodingz%s, %s�langz%Y-%m-%d %H:%M:%Sz	boot-timer��user�~�homer��pyexe�hostname�PID�cpusz%.1f%%, %.1f%%, %.1f%%cSsg|]
}|t��d�qS)�d)r��	cpu_countr�r�r�r�r�{�z!print_sysinfo.<locals>.<listcomp>�loadavgz%s%%, used=%s, total=%s�memory�swapr�rrrzF======================================================================�r�z%-17s %s�:)I�collections�datetime�getpass�locale�platform�pprintr��ImportError�wheel�OrderedDictr�rrr�OSX�mac_verrr��mapr	�	win32_verr?r��system�version�list�architecture�machiner
r4�python_implementation�python_version�python_compilerr�r�r6�libc_verr��getfilesystemencoding�	getlocale�
fromtimestamp�	boot_time�strftime�now�getuserr�r��
expanduserr�r$�node�getpidr��tuplero�virtual_memoryr��percentr
�used�total�swap_memoryr7r�r��as_dictr,�pformatr�r|�itemsr{�flush)r�r�r�r�r�r�r�r��info�outr�r�r�r��pinfo�k�vr�r�r�rI3s���
�
��
����
�
�rIcCs6t��}t|d�r
|��St|d�rt�|���SdS)Nrtrmr)r�r�r?rt�random�choicerm)rr�r�r��_get_eligible_cpu�s

rc@s0eZdZdZddifddifgZddifddddifd	difd
difddifddifd
difddifddifg	Zddifddddifddifddifddifddifddifddifddifddifddifddifddifd difd!difd"difd#difgZer�ed$difg7Zed%difg7Zed&difg7Zed'difg7Zer�ed(difg7Ze	r�ed)difg7Ze
r�ed*ejfifg7Ze
r�ed+difg7Zer�ed,difg7Zer�ed-difg7Zer�ed.difg7Zer�ed/dd0d1ifg7ZgZe�reddifg7Zn
edejfifg7Ze
�red*ejd2fifg7Ze	�r8e�r.ed)ejd3fifg7Zn
ed)ejfifg7Ze
�rFed+e�gfifg7Zd4ejfifd5difd6difd7difd8difgZe�rued4ejfifg7Zed4ejfifg7ZeeeeZd9d:�ZdDd;d<�Zd=d>�Z e!d?d@��Z"e!dAdB��Z#dCS)ErGaA 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_percentr��memory_percentrr+r*Tr��memory_info_ex�oneshotr��parentsr�r��r�cmdline�connections�kind�all�	cpu_times�create_timer�r�r��memory_infor��nice�num_ctx_switches�num_threads�
open_files�ppidr�rz�username�uids�gids�terminalr�rurqrvrmrtrpr�rr�groupedF)r�irr�suspend�resumer<�killcCs
||_dSr�)�_proc)r�rr�r�r�r��s
zprocess_namespace.__init__ccsb�t|�}t�|�|D]"\}}}|r|��t|j|�}tj|g|�Ri|��}||fVqdS�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�r�r�r��iter�s�
�zprocess_namespace.itercCs|jj|jjdd�dS)z&Clear the cache of a Process instance.T)�_ignore_nspN)r&�_initr�r�r�r�r�r)szprocess_namespace.clear_cachecCs>|D]\}}}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.
        �test_z$%r class should define a '%s' methodN)r?r�r��AttributeError)r��
test_classr*r+r��	meth_namer�r�r�r��test_class_coverage
s
���z%process_namespace.test_class_coveragecCs`tdd�|jD��}tdd�|jD��}tdd�ttj�D��}||B|A}|r.td|��dS)NcS�g|]}|d�qSrr�r�r�r�r�r��z*process_namespace.test.<locals>.<listcomp>cSr4rr�r�r�r�r�r�r5cSsg|]
}|ddkr|�qS)rr�r�r�r�r�r�r�r�z!uncovered Process class names: %r)r�r�ignoredr�r�r�r�)r��thisr6�klass�leftoutr�r�r��tests�zprocess_namespace.testN)T)$r�r�r�r��utilsr6�gettersr
r1r2r5r��
RLIMIT_NOFILEr.r4r0rr3�setters�NORMAL_PRIORITY_CLASSr�IOPRIO_CLASS_NONE�
IOPRIO_NORMALrr�SIGTERM�killers�CTRL_C_EVENT�CTRL_BREAK_EVENTrr�r,r)r�r3r:r�r�r�r�rG�s�	��
��


rGc@s�eZdZdZddifddddifddddifddifd	dd
difd	dd
difddddifd
dddifde��fifddddifddifddifddddifde��fifddifddifddifddifgZerreddd
difg7Ze	r|eddifg7Ze
r�eddifg7Zer�eddifg7Zer�eddifg7Ze
r�ed difg7Zed!d"ifg7Zd#difd$e��gfifd%difd&difgZeZed'd(��ZejZd)S)*rHz�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�r�r��logicalFT�	cpu_statsr�percpu�disk_io_counters�perdisk�disk_partitionsr�
disk_usage�net_connectionsr�net_if_addrs�net_if_statsrs�pernicr%r�r��usersr�rnroryrxrw�win_service_iter�win_service_get)�alg�process_iterr-r�cpu_times_percentccsT�t|�}t�|�|D]\}}}tt|�}tj|g|�Ri|��}||fVqdSr')r�r	r(r�r�r�r^)r*r+r�r�r�r�r�r�r,Ss�

�zsystem_namespace.iterN)r�r�r�r�r�r�r�r<r/�HAS_GETLOADAVGr9r8r6rr�r�r6r�staticmethodr,rGr3r�r�r�r�rH sV��

rHcCst�|�s	J|��d|_|S)zA decorator to mark a TestCase class. When running parallel tests,
    class' unit tests will be run serially (1 process).
    T)�inspect�isclass�
_serialrun)r8r�r�r��	serialrunbsr\cCsdd�}ttd||d�S)zZDecorator which runs a test function and retries N times before
    actually failing.
    cSstd|tjd�dS)Nz%r, retryingr�)r�r�r|)rMr�r�r�rJpsz retry_on_failure.<locals>.logfunN)rGrrHrJ)rFr�)rHrJr�r�r�rDls�rDc��fdd�}|S)z,Decorator to Ignore AccessDenied exceptions.c�t�����fdd��}|S)Ncs:z�|i|��WStjy�dur�s�t�d��w)Nzraises AccessDenied)r��AccessDeniedry�SkipTestr��r��only_ifr�r�r�zs
�z9skip_on_access_denied.<locals>.decorator.<locals>.wrapperr�r��rbr�r�rOysz(skip_on_access_denied.<locals>.decoratorr��rbrOr�rcr�rBwsrBcr])z3Decorator to Ignore NotImplementedError exceptions.cr^)NcsBz�|i|��WSty �dur�s�d�j}t�|��w)Nz4%r was skipped because it raised NotImplementedError)r3r�ryr`)r�r�r�rar�r�r��s�
�z;skip_on_not_implemented.<locals>.decorator.<locals>.wrapperr�r�rcr�r�rO�s
z*skip_on_not_implemented.<locals>.decoratorr�rdr�rcr�rC�s
rC�	127.0.0.1cCsLt�t����}|�|df�|��dWd�S1swYdS)z6Return an unused TCP port. Subject to race conditions.rr2N)�
contextlib�closing�socket�bind�getsockname)�hostr�r�r�r�rX�s
$�rXcCs~|dur|ttfvrd}t�||�}z tjdvr!|�tjtjd�|�|�|tj	kr0|�
d�|WSty>|���w)zBinds a generic socket.N�r0r)�nt�cygwinr2rg)
rrrhr�r��
setsockopt�
SOL_SOCKET�SO_REUSEADDRrir�listenr�r�)�family�type�addrr�r�r�r�rY�s



�rYcCsptjsJ�tj�|�rJ|��t�tj|�}z|�|�|tjkr)|�	d�W|SW|St
y7|���w)zBind a UNIX socket.rg)r�r
r�r�r�rhr�rirrrr�r�)r�rtr�r�r�r�rZ�s


���rZrlc	Cs�t�t�|t���G}|�|�|�d�|��}t�|t�}z%|�|�|��}	|��\}}||kr?||fWWd�S|�	�q)t
yO|�	��w1sSwYdS)z^Build a pair of TCP sockets connected to each other.
    Return a (server, client) tuple.
    rgTN)rfrgrhrrirrrj�connectr�r�r)rsru�llr8�caddr�ar�r�r�r[�s(


�
���r[cCs�tjsJ�d}}z#t|tjd�}|�d�t�tjtj�}|�d�|�|�W||fStyD|dur;|�	�|durC|�	��w)z�Build a pair of UNIX sockets connected to each other through
    the same UNIX file name.
    Return a (server, client) tuple.
    N�rtr)
r�r
rZrhr�setblockingr�rvr�r�)r��server�clientr�r�r�r\�s 


��r\c	cs�g}d}}zm|�ttjtj��|�ttjtj��t�r3|�ttjtj��|�ttjtj��trWt	rWt
�}t
�}t|�\}}t|tjd�}|||fD]}|�|�qO|VW|D]}|�
�q]||fD]
}|durrt|�qhdS|D]}|�
�qw||fD]
}|dur�t|�q�w)z1Open as many socket families / types as possible.Nrz)r�rYrhrr�
SOCK_DGRAMrrr
�HAS_CONNECTIONS_UNIXrQr\rZr�rM)�socks�fname1�fname2�s1�s2�s3r�rTr�r�r�r]�s>�
���
��r]cCsddl}trtrtst|tj�sJ|��|tjkrQdd�|�d�D�}t	|�dks-J|��|D]}d|kr>dksCJ|��J|��q/tsJt
|�}|�|�dS|tjkrlt|t
�s_J|��tset
|�}|�|�dS|tjkrt�d|�dus}J|��dStd	|��)
z[Check a net address validity. Supported families are IPv4,
    IPv6 and MAC addresses.
    rNcSsg|]}t|��qSr�)r�r�r�r�r�r�r5z%check_net_address.<locals>.<listcomp>r1r�z([a-fA-F0-9]{2}[:|\-]?){6}zunknown family %r)�	ipaddress�enumrr#r�IntEnumrhrr6r7r�IPv4Addressrr	�IPv6Addressr��AF_LINKr@�matchr�)rursr��octs�numr�r�r�rWs&
&


rWcCsTdd�}dd�}dd�}dd�}d	d
�}||�||�||�||�||�dS)z*Check validity of a connection namedtuple.cSs�t|�dk}t|�dvsJt|���|d|jksJ|j��|d|jks*J|j��|d|jks6J|j��|d|jksBJ|j��|d|jksNJ|j��|d|jksZJ|j��|rh|d	|jksjJ|j��dSdS)
N�)rr�rr2r�rrrgr)r7r�rsrt�laddr�raddrr�r�)r��has_pidr�r�r��check_ntuple+s�z-check_connection_ntuple.<locals>.check_ntuplecSs|jtttfvs
J|j��tdurt|jtj�sJ|��n
t|jt�s'J|��|jtkr{t�|j|j	�}t
�|��8z|�|j
ddf�Wntjy`}z
|jtjkrV�WYd}~n
d}~wwWd�dSWd�dS1stwYdS|jtkr�|jtjks�J|j��dSdS)Nr)rsrrr�r�rr�r�rhrtrfrgrir��errorr�
EADDRNOTAVAILr�r��	CONN_NONE)r�r�rr�r�r��check_family7s.
�����"�
�z-check_connection_ntuple.<locals>.check_familycSs�ttdt��}|jtjtj|fvsJ|j��tdur&t|jtj�s%J|��n
t|jt	�s0J|��|jtjkrA|j
tjksCJ|j
��dSdS)N�SOCK_SEQPACKET)
r�rh�objectrtrr~r�rr�r�r�r�r�)r�r�r�r�r��
check_typeLs���z+check_connection_ntuple.<locals>.check_typecSs�|j|jfD]M}|jttfvrCt|t�sJt|���|sqt|jt	�s*Jt|j���d|jkr5dks;nJ|j��t
|j|j�q|jtkrSt|t
�sSJt|���qdS)Nri��)r�r�rsrrrr�rt�portr�rW�ipr�r	)r�rur�r�r��check_addrsXs"
��z,check_connection_ntuple.<locals>.check_addrscSs�t|jt�sJ|j��dd�tt�D�}|j|vsJ|j��|jttfvr7|jt	kr7|jtj
ks5J|j��dS|jtj
ksBJ|j��dS)NcSr�)�CONN_r�r�r�r�r�r�gr�zAcheck_connection_ntuple.<locals>.check_status.<locals>.<listcomp>)rr�r	r�r�rsrrrtrr�)r��validsr�r�r��check_statusesz-check_connection_ntuple.<locals>.check_statusNr�)r�r�r�r�r�r�r�r�r��check_connection_ntuple)s

r�cCsJz
ddl}t|d�st�Wntyddl}|�|�YSw|�|�S)z,Backport of importlib.reload of Python 3.3+.rN�reload)�	importlibr?r��impr�)�moduler�r�r�r�r�r^{s
��
r^cCs�tj�tj�|��d}tjddkrddl}|�||�Stjdd�dkr3ddlm	}|||��
�Sddl}|j�
||�}|j�|�}|j�|�|S)Nrr�r)�SourceFileLoader)r�r��splitextr�r�r�r��load_source�importlib.machineryr��load_module�importlib.util�util�spec_from_file_location�module_from_spec�loader�exec_module)r�r�r�r�r��spec�modr�r�r�r_�sr_cCst�|t�dS)zRaise a warning msg.N)�warningsr`�UserWarning)r�r�r�r�r`�r�r`cCsVt|�}|j}t|�dks|dtkrdSt|dd�}t|t�s"dStdd�|D��S)z-Check if object is an instance of namedtuple.r2rF�_fieldsNcss�|]	}t|�tkVqdSr�)rtr	)r��nr�r�r��	<genexpr>�s�z is_namedtuple.<locals>.<genexpr>)rt�	__bases__r7r�r�rr)r��t�brr�r�r�rb�s
rbc#s|�trdnd�d�t|�d�}��fdd�t����D�}t�|�}t�||�zt	�
|�|VWt|�dSt|�w)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.sorhcs6g|]}tj�|j�d�kr�|j��vr|j�qS)r2)r�r�r��lowerr��r��extr�r�r��s
��'copyload_shared_lib.<locals>.<listcomp>N)r#rQr�r�rrr	r
r_rk�ctypes�CDLLrM)ri�dst�libsr�r�r�r�ra�s�

rac	#s�ddlm}ddlm}d�t|�d�}�fdd�t����D�}tr2|s2dd�t����D�}t�	|�}t
�||�d	}z)t�|�}|VW|d	urctj
jj}|jg|_||j�}|dkrc|�t|�d	S|d	ur�tj
jj}|jg|_||j�}|dkr�|�t|�w)
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)�WinError)�wintypesz.dllrhcsFg|]}|j�����r!dtj�|j���vr!d|j��vr|j�qS)r��wow64)r�r�r
r�r�r��r�r�r�r��s��r�cSs(g|]}dtj�|j���vr|j�qS)r�)r�r�r�r�r�r�r�r�r��s�N)r�r�r�rQr�r�rrr#r	r
r_rk�WinDLL�windll�kernel32�FreeLibrary�HMODULE�argtypes�_handlerM)	rir�r�r�r�r��cfiler�rXr�r�r�ra�s8�




�



cCstdd�dS)NTr))r=r�r�r�r��cleanup_test_procs�r�r�cCs
t�|�Sr�)r��exit)r�framer�r�r�r��s
r�r�)F)TFr�)re)rl)r0)�r��
__future__r�atexitrfr�rr�r�rYr�r	r@r�r_rrhr[r}r�rqr�r�r�r�rrrr�rrrr	r
rr�psutil._commonr
rr�psutil._compatrrrrrrrrry�	unittest2rr��catch_warnings�simplefilterr�r��psutil._psposixr�__all__�builtin_module_namesr#rprrdr*�maxsizer-r"r!r,r r�r�r'r(�decoder)r�r��ASCII_FSr�r�r�re�__file__r%r&�HERErr?r�r.r/rWr0r2r3�HAS_NET_IO_COUNTERSr4r1r5r6rjrwr7r�r8r9�HAS_THREADS�getuid�SKIP_SYSCONSr�r$r��devnullr�registerr�r�r+r�r�r�r�r�r�r�r�r�r>r@r?r;rrBr<r=rSrRrFrrUr�rVrTrMrd�contextmanagerrLrNrQrsrF�skipIfrErIrrGrHr\rDrBrCrXrYrZr[r\r]rWr�r^r_r`rbrar�r�r�r�r��<module>s�



���

-


�



�

 0'
&-


U%
:�


��
!




1[	
B





R
,
�

Youez - 2016 - github.com/yon3zu
LinuXploit