HEX
Server: Apache
System: Linux insrv.serversdaddy.com 5.14.0-362.24.2.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Mar 30 14:11:54 EDT 2024 x86_64
User: jsaha (1066)
PHP: 8.3.6
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/lib/python3.9/site-packages/tracer/resources/__pycache__/processes.cpython-39.pyc
a

�|
`o#�@s�ddlmZddlmZddlZddlZddlZddlZddlZddlm	Z	m
Z
ddlmZddl
mZGdd	�d	e�ZGd
d�de�ZGdd
�d
e�ZGdd�deee��ZGdd�de�ZdS)�)�ProcessesCollection)�FilenameCleaner�N)�PIPE�Popen)�Timer)�with_metaclassc@s$eZdZedd��Zedd��ZdS)�	ProcessescCs*z
t��WSty$t��YS0dS�N)�psutil�pids�AttributeErrorZget_pid_list�rr�>/usr/lib/python3.9/site-packages/tracer/resources/processes.pyr"s
zProcesses.pidsc	CsRt�}t��D]>}z|�t|��Wqtjy8YqtjyJYq0q|Sr
)rr	r�append�ProcessrZ
NoSuchProcess�AccessDenied)Z	processes�pidrrr�all)sz
Processes.allN)�__name__�
__module__�__qualname__�staticmethodrrrrrrr	s
r	c@s�eZdZdZd!dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
d"dd�Zdd�Zdd�Zd#dd �ZdS)$�ProcessWrappera�
	Wrapper for ``psutil.Process class``
	Library ``psutil`` is not backward compatible from version 2.x.x to 1.x.x.

	Purpose of this class is cover incompatibility in ``psutil.Process`` class and
	provide interface of new version. It allows using new interface even with
	old version of ``psutil``.

	Note that, for performance reasons, process information is cached at
	object creation. To force a refresh, invoke the ``rebuild_cache()``
	method.
	NcCst�|�|_|��dSr
)rr�_process�
rebuild_cache��selfrrrr�__init__BszProcessWrapper.__init__cCs
t|j�Sr
)�boolr�rrrr�__nonzero__FszProcessWrapper.__nonzero__cCs|jjgd�d�|_dS)N)�name�exe�cmdline�ppid�username�create_time)�attrs)rZas_dict�	_procdictr rrrrIszProcessWrapper.rebuild_cachec
Cs|z\|�d�dkrZ|�d�|�d�vrZt|�d��dkrZd�t�dd�|�d���d�WSWntjypYn0|�d�S)	Nr"Zsshdr#r$rzssh-{0}-sessionz |@� )�_attr�len�format�re�split�joinrrr rrrr"Ls&(zProcessWrapper.namecCs
|�d�S)Nr#�r+r rrrr#WszProcessWrapper.execCs
|�d�S)Nr$r1r rrrr$ZszProcessWrapper.cmdlinecCs
|�d�S)Nr%r1r rrrr%]szProcessWrapper.ppidcCs
|�d�S)N�parentr1r rrrr2`szProcessWrapper.parentcCs
|�d�S)Nr&r1r rrrr&cszProcessWrapper.usernamecCs
|�d�S)Nr'r1r rrrr'fszProcessWrapper.create_timeFcCsZd�|�}||jvrPz|j�|�|j|<Wn$tyN|j�|�|j|<Yn0|j|S)Nzchildren-{0})r-r)r�childrenr
Zget_children)r�	recursive�keyrrrr3is

zProcessWrapper.childrencCsN||jvrDt|j|�}z|�|j|<WntyB||j|<Yn0|j|Sr
)r)�getattrr�	TypeError)rr"�attrrrrr+rs
zProcessWrapper._attrcCst|j|�Sr
)r6r)r�itemrrr�__getattr__{szProcessWrapper.__getattr__TcCs^d�|�}||jvrTz|jj|d�|j|<Wn&tyR|jj|d�|j|<Yn0|j|S)Nzmemory_maps-{0})�grouped)r-r)r�memory_mapsr
Zget_memory_maps)rr;r5rrrr<s

zProcessWrapper.memory_maps)N)F)T)rrr�__doc__rr!rr"r#r$r%r2r&r'r3r+r:r<rrrrr4s

		rcs(eZdZdZ�fdd�Zdd�Z�ZS)�ProcessMetaz�
	Caching metaclass that ensures that only one ``Process`` object is ever
	instantiated for any given PID. The cache can be cleared by calling
	``Process.reset_cache()``.

	Based on https://stackoverflow.com/a/33458129
	cs6tt���|||��fdd�}|�t�d|�dS)Ncs
i�_dSr
)�_cacher��clsrr�reset_cache�sz)ProcessMeta.__init__.<locals>.reset_cacherB)�superr>r�setattr)rAr"�basesZ
attributesrB��	__class__r@rr�szProcessMeta.__init__cOsV|d}||jvrL|j|g|�Ri|��}|j|g|�Ri|��||j|<|j|S)Nr)r?�__new__r)rA�args�kwargsrrrrr�__call__�s

zProcessMeta.__call__)rrrr=rrK�
__classcell__rrrFrr>�sr>cs�eZdZdZdd�Zdd�Zdd�Zedd	d
��Ze	dd��Z
d
d�Z�fdd�Zd�fdd�	Z
e	�fdd��Ze	dd��Ze	dd��Ze	dd��Ze	dd��Z�ZS) raS
	Represent the process instance uniquely identifiable through PID

	For all class properties and methods, please see
	http://pythonhosted.org/psutil/#process-class

	Below listed are only reimplemented ones.

	For performance reasons, instances are cached based on PID, and
	multiple instantiations of a ``Process`` object with the same PID will
	return the same object. To clear the cache, invoke
	``Process.reset_cache()``. Additionally, as with ``ProcessWrapper``,
	process information is cached at object creation. To force a refresh,
	invoke the ``rebuild_cache()`` method on the object.
	cCs|j|jkS)zBFor our purposes, two processes are equal when they have same name)r�r�processrrr�__eq__�szProcess.__eq__cCs|�|�Sr
)rOrMrrr�__ne__�szProcess.__ne__cCs
t|j�Sr
)�hashrr rrr�__hash__�szProcess.__hash__��?cCsTtdd|gttd�}t||j�}z$|��|��|jdkW|��S|��0dS)z�
		Process arguments could be referring to files on remote filesystems and
		os.path.isfile will hang forever if the shared FS is offline.
		Instead, use a subprocess that we can time out if we can't reach some file.
		�testz-f)�stdout�stderrrN)rrr�kill�startZcommunicate�
returncode�cancel)Z	file_path�timeoutrNZtimerrrr�safe_isfile�s
�zProcess.safe_isfilecCsdg}|��D]}|�t�|j��q|��dd�D]&}tj�|�sFq4t�	|�r4|�|�q4t
|�S�Nr)r<rr�strip�pathr$�os�isabsrr\�sorted)r�filesZmmap�argrrrrc�s
z
Process.filescCs|��rt|���SdS)zGThe parent process casted from ``psutil.Process`` to tracer ``Process``N)r%rr rrrr2�szProcess.parentcs*ztt|���WSty$YdS0dS)zcThe user who owns the process. If user was deleted in the meantime,
		``None`` is returned instead.N)rCrr&�KeyErrorr rFrrr&�szProcess.usernameFcs"tt|��|�}tdd�|D��S)zjThe collection of process's children. Each of them casted from ``psutil.Process``
		to tracer ``Process``.cSsg|]}t|j��qSr)rr)�.0�childrrr�
<listcomp>��z$Process.children.<locals>.<listcomp>)rCrr3r)rr4r3rFrrr3�szProcess.childrencsBtt|���}|�d�r$|dd�}d|vr>|d|�d��}|S)zcThe absolute path to process executable. Cleaned from arbitrary strings
		which appears on the end.z#newr����;)rCrr#�endswith�index)rr#rFrrr#�s
zProcess.execCs|��dvS)N)Zpython)r"r rrr�is_interpretedszProcess.is_interpretedcCs8|��}|durdS|��}|dus0||��kr4dSdS)NT)�terminalr2)rror2rrr�
is_sessionszProcess.is_sessioncCs@|jr8|��dd�D] }tj�|�rtj�|�Sq|��Sr])rnr$r`r_�isfile�basenamer")rrdrrr�	real_names
zProcess.real_namecCs�tj�t���}tj�|���}||}d}|jdkrFt|j�d}n`|jdkrhtt|jd��d}n>|jdkr�tt|jd��d}n|jdkr�tt|j��d}|S)	z�
		The time of how long process is running. Returned as string
		in format ``XX unit`` where unit is one of
		``days`` | ``hours`` | ``minutes`` | ``seconds``
		�rz daysiz hours�<z minutesz seconds)�datetimeZ
fromtimestamp�timer'Zdays�strZseconds�int)rZnow�startedZstarted_strrrr�str_started_agos



zProcess.str_started_ago)rS)F)rrrr=rOrPrRrr\�propertyrcr2r&r3r#rnrprsr{rLrrrFrr�s*




rc@s&eZdZdZdZddd�Zdd�ZdS)�AffectedProcessNcCs t�||�t�|_t�|_dSr
)rr�set�packagesrcrrrrr9szAffectedProcess.__init__cCs$|j�|j�|_|j�|j�|_dSr
)rc�unionrrMrrr�update>szAffectedProcess.update)N)rrrrrcrr�rrrrr}5s
r})�collectionsrrrrvrwr`r.�
subprocessrr�	threadingrZsixr�objectr	r�typer>rr}rrrr�<module>sU