o
    ZhMg                  
   @   s  d Z ddlmZ ddlm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lZddlZddlZddlmZ ddl	mZ ddl	mZ ddl	mZ zdd	l	mZ W n eya   dZY nw zdd
l	mZ W n eyu   dZY nw ejdkrddlZndZejd dkZeeddZg dZejdkZejdkZej dZ!ej dZ"e"Z#ej dZ$ej dZ%ej dZ&e$pe%pe&Z'ej dZ(ej dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1d Z2d!Z3d"Z4d#Z5d$Z6d%Z7d&Z8d'Z9d(Z:d)Z;d*Z<d+Z=d,Z>d-Z?d.Z@d/ZAd0ZBd1ZCedu rd2ZDd3ZEdZFnG d4d5 d5ejGZHeI JeHjK edu r+d6ZLd7ZMnG d8d9 d9ejGZNeI JeNjK eO ZPesEd:ZQnzeR ZQW n eSy\   erXd;nd:ZQY nw ed<g d=ZTed>g d?ZUed@g dAZVedBg dCZWedDg dEZXedFg dGZYedHg dIZZedJg dKZ[edLg dMZ\edNg dOZ]edPg dQZ^edRg dSZ_edTg dUZ`edVdWdXgZaedYg dZZbed[d\d]gZced^g d_Zded`g daZeedbg daZfedcg ddZgededfdggZhedhdidjgZiedkg dlZjedmdndogZkeeegeegfeegegfegegfeegegfegegfeegeegfegeegfegeegfdpZledurNelJegegfegegfdq edur_elJdregeegfi G dsdt dtemZnG dudv dvenZoG dwdx dxeoZpG dydz dzenZqG d{d| d|enZrdd}d~Zsdd Ztdd Zudd Zvdd Zwetdd Zxdd Zydd Zzdd Z{dddZ|dd Z}G dd dZ~dd Ze~ Zeje_eje_dd Zdd ZdddZdd Zerdd Zndd ZetejfddZdddZddejfddZdd ZdS )z9Common objects shared by __init__.py and _ps*.py modules.    )division)print_functionN)
namedtuple)AF_INET)
SOCK_DGRAM)SOCK_STREAM)AF_INET6)AF_UNIX)      r
   PSUTIL_DEBUG)NFREEBSDBSDLINUXNETBSDOPENBSDMACOSOSXPOSIXSUNOSWINDOWS
CONN_CLOSECONN_CLOSE_WAITCONN_CLOSINGCONN_ESTABLISHEDCONN_FIN_WAIT1CONN_FIN_WAIT2CONN_LAST_ACKCONN_LISTEN	CONN_NONECONN_SYN_RECVCONN_SYN_SENTCONN_TIME_WAITNIC_DUPLEX_FULLNIC_DUPLEX_HALFNIC_DUPLEX_UNKNOWNSTATUS_DEADSTATUS_DISK_SLEEPSTATUS_IDLESTATUS_LOCKEDSTATUS_RUNNINGSTATUS_SLEEPINGSTATUS_STOPPEDSTATUS_SUSPENDEDSTATUS_TRACING_STOPSTATUS_WAITINGSTATUS_WAKE_KILLSTATUS_WAKINGSTATUS_ZOMBIESTATUS_PARKEDENCODINGENCODING_ERRSr   pconn	pcputimespctxswpgidspiopionice	popenfilepthreadpuidssconn	scpustatssdiskio	sdiskpart
sdiskusagesnetiosnicaddr	snicstatssswapsuser	conn_tmapdeprecated_methodisfile_strictmemoizeparse_environ_blockpath_exists_strictusage_percentsupports_ipv6sockfam_to_enumsocktype_to_enumwrap_numbersbytes2humanconn_to_ntupledebughiliteterm_supports_colorsprint_colorposixntlinuxdarwin)freebsdZmidnightbsdopenbsdnetbsd)sunossolarisaixrunningsleepingz
disk-sleepstoppedztracing-stopzombieZdeadz	wake-killZwakingZidlelockedZwaitingZ	suspendedZparkedZESTABLISHEDZSYN_SENTZSYN_RECVZ	FIN_WAIT1Z	FIN_WAIT2Z	TIME_WAITZCLOSEZ
CLOSE_WAITZLAST_ACKZLISTENZCLOSINGNONE      c                   @   s   e Zd ZdZdZdZdS )	NicDuplexrj   rk   r   N)__name__
__module____qualname__r#   r$   r%    rp   rp   E/var/www/html/lang_env/lib/python3.10/site-packages/psutil/_common.pyrl      s    rl   c                   @   s   e Zd ZdZdZdS )BatteryTimerr   rs   N)rm   rn   ro   POWER_TIME_UNKNOWNPOWER_TIME_UNLIMITEDrp   rp   rp   rq   rt      s    rt   replacesurrogateescaperG   )totalusedfreepercentsinZsoutrC   )ry   rz   r{   r|   rA   )
read_countwrite_count
read_byteswrite_bytesZ	read_timeZ
write_timerB   )ZdeviceZ
mountpointZfstypeoptsZmaxfileZmaxpathrD   )Z
bytes_sentZ
bytes_recvZpackets_sentZpackets_recvZerrinZerroutZdropinZdropoutrH   )nameZterminalhoststartedpidr?   )fdfamilytypeladdrraddrstatusr   rE   )r   addressnetmask	broadcastZptprF   )ZisupZduplexspeedZmtur@   )Zctx_switchesZ
interruptsZsoft_interruptsZsyscallsscpufreq)currentminmaxshwtemp)labelr   highcriticalsbattery)r|   ZsecsleftZpower_pluggedsfanr   r   r7   )usersystemchildren_userchildren_systemr<   pathr   r=   )idZ	user_timeZsystem_timer>   )realZ	effectivesavedr9   r:   )r~   r   r   r   r;   Zioclassvaluer8   Z	voluntaryZinvoluntaryr6   )r   r   r   r   r   r   addripport)allZtcpZtcp4ZudpZudp4ZinetZinet4Zinet6)Ztcp6Zudp6unixc                   @   s,   e Zd ZdZdZdd Zdd Zdd Zd	S )
ErrorzQBase exception class. All other psutil exceptions inherit
    from this one.
    psutilc                 C   sJ   zt  }W n ty   i }Y nw |D ]}t| |d }|r"|||< q|S N)collectionsOrderedDictAttributeErrorgetattr)selfattrsinfor   r   rp   rp   rq   	_infodict  s   zError._infodictc                 C   sJ   |  d}|rdddd | D  }nd }ddd | j|fD S )N)r   ppidr   z(%s), c                 S      g | ]
\}}d ||f qS z%s=%rrp   .0kvrp   rp   rq   
<listcomp>)      z!Error.__str__.<locals>.<listcomp> c                 S   s   g | ]}|r|qS rp   rp   )r   xrp   rp   rq   r   ,  s    )r   joinitemsmsgr   r   detailsrp   rp   rq   __str__$  s   
zError.__str__c                 C   s2   |  d}ddd | D }d| jj|f S )N)r   r   r   secondsr   r   c                 S   r   r   rp   r   rp   rp   rq   r   1  r   z"Error.__repr__.<locals>.<listcomp>zpsutil.%s(%s))r   r   r   	__class__rm   r   rp   rp   rq   __repr__.  s   
zError.__repr__N)rm   rn   ro   __doc__r   r   r   rp   rp   rp   rq   r     s    
r   c                   @      e Zd ZdZdZdddZdS )NoSuchProcesszXException raised when a process with a certain PID doesn't
    or no longer exists.
    r   Nc                 C   $   t |  || _|| _|pd| _d S )Nzprocess no longer existsr   __init__r   r   r   r   r   r   r   rp   rp   rq   r   ;     
zNoSuchProcess.__init__NNrm   rn   ro   r   r   rp   rp   rp   rq   r   5      r   c                   @   r   )ZombieProcessa1  Exception raised when querying a zombie process. This is
    raised on macOS, BSD and Solaris only, and not always: depending
    on the query the OS may be able to succeed anyway.
    On Linux all zombie processes are querable (hence this is never
    raised). Windows doesn't have zombie processes.
    r   Nc                 C   s$   t | ||| || _|pd| _d S )Nz"PID still exists but it's a zombie)r   r   r   r   )r   r   r   r   r   rp   rp   rq   r   K  s   zZombieProcess.__init__NNNr   rp   rp   rp   rq   r   B  s    r   c                   @   r   )AccessDeniedz@Exception raised when permission to perform an action is denied.r   Nc                 C   r   )N r   r   rp   rp   rq   r   U  r   zAccessDenied.__init__r   r   rp   rp   rp   rq   r   Q  s    r   c                   @   r   )TimeoutExpiredzWRaised on Process.wait(timeout) if timeout expires and process
    is still alive.
    r   Nc                 C   s*   t |  || _|| _|| _d| | _d S )Nztimeout after %s seconds)r   r   r   r   r   r   )r   r   r   r   rp   rp   rq   r   b  s
   
zTimeoutExpired.__init__r   r   rp   rp   rp   rq   r   \  r   r   c                 C   s@   z
t | | d }W n
 ty   Y dS w |durt||}|S )z5Calculate percentage usage of 'used' against 'total'.d   g        N)floatZeroDivisionErrorround)rz   ry   Zround_retrp   rp   rq   rO   o  s   
rO   c                    s2   t  fdd} fdd}i  ||_|S )a  A simple memoize decorator for functions supporting (hashable)
    positional arguments.
    It also provides a cache_clear() function for clearing the cache:

    >>> @memoize
    ... def foo()
    ...     return 1
        ...
    >>> foo()
    1
    >>> foo.cache_clear()
    >>>
    c                     sL   | t t| f}z | W S  ty%   | i | } |< | Y S w r   )	frozensetsortedr   KeyError)argskwargskeyr   cachefunrp   rq   wrapper  s   
zmemoize.<locals>.wrapperc                      s       dS )zClear cache.N)clearrp   )r   rp   rq   cache_clear     zmemoize.<locals>.cache_clear)	functoolswrapsr   )r   r   r   rp   r   rq   rL   {  s   rL   c                    s6   t   fdd}dd }dd }||_||_|S )a  A memoize decorator which is disabled by default. It can be
    activated and deactivated on request.
    For efficiency reasons it can be used only against class methods
    accepting no arguments.

    >>> class Foo:
    ...     @memoize
    ...     def foo()
    ...         print(1)
    ...
    >>> f = Foo()
    >>> # deactivated (default)
    >>> foo()
    1
    >>> foo()
    1
    >>>
    >>> # activated
    >>> foo.cache_activate(self)
    >>> foo()
    1
    >>> foo()
    >>> foo()
    >>>
    c                    sj   z| j   }W |S  ty    |  Y S  ty4    | }z	|| j  < W Y |S  ty3   Y Y |S w w r   )_cacher   r   )r   r   r   rp   rq   r     s   z'memoize_when_activated.<locals>.wrapperc                 S   s
   i | _ dS )zjActivate cache. Expects a Process instance. Cache will be
        stored as a "_cache" instance attribute.N)r   procrp   rp   rq   cache_activate  s   
z.memoize_when_activated.<locals>.cache_activatec                 S   s    z| ` W dS  ty   Y dS w )zDeactivate and clear cache.N)r   r   r   rp   rp   rq   cache_deactivate  s
   
z0memoize_when_activated.<locals>.cache_deactivate)r   r   r   r   )r   r   r   r   rp   r   rq   memoize_when_activated  s   r   c              
   C   sV   zt | }W n ty$ } z|jtjtjfv r W Y d}~dS d}~ww t|jS )zSame as os.path.isfile() but does not swallow EACCES / EPERM
    exceptions, see:
    http://mail.python.org/pipermail/python-dev/2012-June/120787.html
    NF)osstatOSErrorerrnoEPERMEACCESS_ISREGst_mode)r   sterrrp   rp   rq   rK     s   rK   c              
   C   sL   zt |  W dS  ty% } z|jtjtjfv r W Y d}~dS d}~ww )zSame as os.path.exists() but does not swallow EACCES / EPERM
    exceptions, see:
    http://mail.python.org/pipermail/python-dev/2012-June/120787.html
    NFT)r   r   r   r   r   r   )r   r   rp   rp   rq   rN     s   rN   c                  C   sv   t jrtdu r	dS z&t  tt j} t|  | d W d   W dS 1 s(w   Y  W dS  t jy:   Y dS w )z2Return True if IPv6 is supported on this platform.NF)z::1r   T)sockethas_ipv6r   r   
contextlibclosingbinderror)sockrp   rp   rq   rP     s   
rP   c                 C   sx   i }d}t }	 | d|}||kr	 |S | d||}||kr7| || }| |d | }|r3| }|||< |d }q)zCParse a C environ block of environment variables into a dictionary.r   T =rk   )r   findupper)datar   posZWINDOWS_Znext_posZ	equal_posr   r   rp   rp   rq   rM     s"   rM   c                 C   0   t du r| S zt| W S  ty   |  Y S w )zConvert a numeric socket family value to an IntEnum member.
    If it's not a known member, return the numeric value itself.
    N)enumr   AddressFamily
ValueErrornumrp   rp   rq   rQ   "     rQ   c                 C   r  )zConvert a numeric socket type value to an IntEnum member.
    If it's not a known member, return the numeric value itself.
    N)r  r   
SocketKindr  r  rp   rp   rq   rR   /  r  rR   c                 C   s   |t jtfv r|rt| }|rt| }|t jkr%|ttfv r%||t}nt}t|}t|}|du r<t	| |||||S t
| ||||||S )z2Convert a raw connection tuple to a proper ntuple.N)r   r   r   r   r   getr   rQ   rR   r6   r?   )r   Zfamtype_r   r   r   Z
status_mapr   rp   rp   rq   rU   <  s   rU   c                    s    fdd}|S )zA decorator which can be used to mark a method as deprecated
    'replcement' is the method name which will be called instead.
    c                    s:   d| j f  | jd u r | _t|  fdd}|S )Nz8%s() is deprecated and will be removed; use %s() insteadc                    s$   t j tdd t| |i |S )Nrj   )category
stacklevel)warningswarnDeprecationWarningr   )r   r   r   )r   replacementrp   rq   innerY  s   z/deprecated_method.<locals>.outer.<locals>.inner)rm   r   r   r   )r   r  r  )r   rq   outerS  s   
z deprecated_method.<locals>.outerrp   )r  r  rp   r  rq   rJ   O  s   rJ   c                   @   sB   e Zd ZdZdd Zdd Zdd Zdd	 ZdddZdd Z	d
S )_WrapNumberszNWatches numbers so that they don't overflow and wrap
    (reset to zero).
    c                 C   s    t  | _i | _i | _i | _d S r   )	threadingLocklockr   	remindersreminder_keysr   rp   rp   rq   r   f  s   

z_WrapNumbers.__init__c                 C   sX   || j vsJ || jvsJ || jvsJ || j |< tt| j|< tt| j|< d S r   )r   r"  r#  r   defaultdictintset)r   
input_dictr   rp   rp   rq   	_add_dictl  s   
z_WrapNumbers._add_dictc                 C   s\   | j | }t| t|  }|D ]}| j| | D ]}| j| |= q| j| |= qdS )zIn case the number of keys changed between calls (e.g. a
        disk disappears) this removes the entry from self.reminders.
        N)r   r'  keysr#  r"  )r   r(  r   old_dictZ	gone_keysZgone_keyremkeyrp   rp   rq   _remove_dead_reminderst  s   
z#_WrapNumbers._remove_dead_remindersc              	   C   s  || j vr| || |S | || | j | }i }| D ]\}|| }z|| }W n ty7   |||< Y qw g }tt|D ]3}	||	 }
||	 }||	f}|
|k rg| j| |  |7  < | j| | 	| |
|
| j| |   q@t|||< q|| j |< |S )zkCache dict and sum numbers which overflow and wrap.
        Return an updated copy of `input_dict`
        )r   r)  r-  r*  r   rangelenr"  r#  addappendtuple)r   r(  r   r+  Znew_dictr   Zinput_tupleZ	old_tuplebitsiZinput_value	old_valuer,  rp   rp   rq   run  s4   


z_WrapNumbers.runNc                 C   s   | j : |du r| j  | j  | j  n| j|d | j|d | j|d W d   dS W d   dS 1 s@w   Y  dS )z>Clear the internal cache, optionally only for function 'name'.N)r!  r   r   r"  r#  pop)r   r   rp   rp   rq   r     s   

"z_WrapNumbers.cache_clearc                 C   s:   | j  | j| j| jfW  d   S 1 sw   Y  dS )z5Return internal cache dicts as a tuple of 3 elements.N)r!  r   r"  r#  r$  rp   rp   rq   
cache_info  s   $z_WrapNumbers.cache_infor   )
rm   rn   ro   r   r   r)  r-  r6  r   r8  rp   rp   rp   rq   r  a  s    
'r  c                 C   s6   t j t | |W  d   S 1 sw   Y  dS )zGiven an `input_dict` and a function `name`, adjust the numbers
    which "wrap" (restart from zero) across different calls by adding
    "old value" to "new value" and return an updated dict.
    N)_wnr!  r6  )r(  r   rp   rp   rq   rS     s   
$rS   c                 K   s   t | dfi |S )Nrb)openfnamer   rp   rp   rq   open_binary  s   r>  c                 K   s.   t r|dt |dt t| dfi |S )zOn Python 3 opens a file in text mode by using fs encoding and
    a proper en/decoding errors handler.
    On Python 2 this is just an alias for open(name, 'rt').
    encodingerrorsrt)PY3
setdefaultr4   r5   r;  r<  rp   rp   rq   	open_text  s   rD  %(value).1f%(symbol)sc                 C   s   d}i }t |dd D ]\}}d|d d > ||< qt|dd D ]}| || kr:t| ||  }|t    S q#|t|d | d S )zUsed by various scripts. See:
    http://goo.gl/zeJZl

    >>> bytes2human(10000)
    '9.8K'
    >>> bytes2human(100001221)
    '95.4M'
    )	BKMGTPEZYrk   N
   r   )symbolr   )	enumeratereversedr   localsdict)nformatsymbolsprefixr4  srP  r   rp   rp   rq   rT     s   	rT   c                   C   s   t jd jS )z+Return updated psutil.PROCFS_PATH constant.r   )sysmodulesZPROCFS_PATHrp   rp   rp   rq   get_procfs_path  r   r\  c                 C   s   | j ttdS )N)r?  r@  )decoder4   r5   rY  rp   rp   rq   r]    s   r]  c                 C   s   | S r   rp   r^  rp   rp   rq   r]    s   c                 C   sX   t jdkrdS zdd l}|  sJ |  |ddksJ W dS  ty+   Y dS w )Nr[   Tr   colorsF)r   r   cursesisattyZ	setuptermZtigetnum	Exception)filer`  rp   rp   rq   rX     s   
rX   Fc                 C   s   t  s| S g }tddddddddd	d
	}d|d< z|| }W n ty/   tdt|  w || |r<|d dd|| f S )z*Return an highlighted version of 'string'.Z32Z91Z33Z93Z34Z35Z36Z37Z30)	greenredbrownyellowbluevioletZ	lightblueZgreyZdarkgreyZ29Nz#invalid color %r; choose between %s1z[%sm%s[0m;)rX   rT  r   r  listr*  r1  r   )rY  colorboldattrr_  rp   rp   rq   rW     s$   


rW   c              	   C   s  t  st| |d dS trtt| |||d dS ddl}d}|jjj}|jjj}t	ddddd}||d< z|| }W n t
yN   td	|t| f w |rY|dkrY|d
7 }|tju r`dnd}	|j|_||	}
||
| zt| |d W ||
| dS ||
| w )z$Print a colorized version of string.rc  r   N   rj   r      )rd  re  rf  rg  z#invalid color %r; choose between %r   ii)rX   printr   rW   ctypesZwindllZKernel32GetStdHandleSetConsoleTextAttributerT  r   r  rl  r*  rZ  stderrZc_ulongrestype)rY  rm  rn  rc  ru  ZDEFAULT_COLORrv  rw  r_  Z	handle_idhandlerp   rp   rq   rY      s6   

rY   c                 C   sr   t r7ddl}|| j\}}}}}t| tr)t| ttt	fr%d|  } nd|  } t
d||| f tjd dS dS )z@If PSUTIL_DEBUG env var is set, print a debug message to stderr.r   Nzignoring %szignoring %rzpsutil-debug [%s:%s]> %srp  )r   inspectgetframeinfocurrentframef_back
isinstancerb  r   IOErrorEnvironmentErrorrt  rZ  rx  )r   r{  r=  lineno	func_namelinesindexrp   rp   rq   rV   C  s   


rV   r   )rE  )NF)r   
__future__r   r   r   r   r   r   r   r   r   rZ  r  r  r   r   r   r   r   ImportErrorr	   version_infor  rB  boolgetenvr   __all__r   r   r   platform
startswithr   r   r   r   r   r   r   r   ZAIXr*   r+   r'   r,   r.   r2   r&   r0   r1   r(   r)   r/   r-   r3   r   r!   r    r   r   r"   r   r   r   r   r   r   r#   r$   r%   IntEnumrl   globalsupdate__members__ru   rv   rt   getfilesystemencodingr4   r5   getfilesystemencodeerrorsr   rG   rC   rA   rB   rD   rH   r?   rE   rF   r@   r   r   r   r   r7   r<   r=   r>   r9   r:   r;   r8   r6   r   rI   rb  r   r   r   r   r   rO   rL   r   rK   rN   rP   rM   rQ   rR   rU   rJ   r  rS   r9  r   r8  r>  rD  rT   r\  r]  stdoutrX   rW   rY   rV   rp   rp   rp   rq   <module>   s\  


$
	

	






"
 ?

W	

	

#