o
    adfr                  
   @   sb  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 dkZerddlZndZeedZe 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Z0dZ1dZ2dZ3dZ4d Z5d!Z6d"Z7d#Z8d$Z9d%Z:d&Z;d'Z<d(Z=d)Z>d*Z?d+Z@d,ZAd-ZBd.ZCd/ZDd0ZEedu rd1ZFd2ZGdZHnG d3d4 d4ejIZJeK LeJjM edu r*d5ZNd6ZOnG d7d8 d8ejIZPeK LePjM eQ ZResDd9ZSnzeT ZSW n eUy[   erWd:nd9ZSY nw ed;g d<ZVed=g d>ZWed?g d@ZXedAg dBZYedCg dDZZedEg dFZ[edGg dHZ\edIg dJZ]edKg dLZ^edMg dNZ_edOg dPZ`edQg dRZaedSg dTZbedUdVdWgZcedXg dYZdedZd[d\gZeed]g d^Zfed_g d`Zgedag d`Zhedbg dcZiedddedfgZjedgdhdigZkedjg dkZledldmdngZme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doZnedurMenLegegfegegfdp edur^enLdqegeegfi G drds dseoZpG dtdu duepZqG dvdw dweqZrG dxdy dyepZsG dzd{ d{epZtereuevewrevd| Zxneyevd|Zxexd} nd~d ZzdddZ{dd Z|dd Z}dd Z~dd Ze|dd Zdd Zdd Zdd ZdddZdd ZG dd dZdd Ze Zeje_eje_dZdd Zdd ZeefddZefddZdddZdd Zerdd Zndd Ze|e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   PSUTIL_DEBUG)R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	open_textopen_binarycatbcat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waking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 )	NicDuplexrn   ro   r   N)__name__
__module____qualname__r"   r#   r$    rt   rt   W/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/psutil/_common.pyrp      s    rp   c                   @   s   e Zd ZdZdZdS )BatteryTimerv   rw   N)rq   rr   rs   POWER_TIME_UNKNOWNPOWER_TIME_UNLIMITEDrt   rt   rt   ru   rx      s    rx   replacesurrogateescaperF   )totalusedfreepercentsinZsoutrB   )r}   r~   r   r   r@   )
read_countwrite_count
read_byteswrite_bytesZ	read_timeZ
write_timerA   )ZdeviceZ
mountpointZfstypeoptsZmaxfileZmaxpathrC   )Z
bytes_sentZ
bytes_recvZpackets_sentZpackets_recvZerrinZerroutZdropinZdropoutrG   )nameZterminalhoststartedpidr>   )fdfamilytypeladdrraddrstatusr   rD   )r   addressnetmask	broadcastZptprE   )ZisupZduplexspeedZmtuflagsr?   )Zctx_switchesZ
interruptsZsoft_interruptsZsyscallsscpufreq)currentminmaxshwtemp)labelr   highcriticalsbattery)r   ZsecsleftZpower_pluggedsfanr   r   r6   )usersystemchildren_userchildren_systemr;   pathr   r<   )idZ	user_timeZsystem_timer=   )realZ	effectivesavedr8   r9   )r   r   r   r   r:   Zioclassvaluer7   Z	voluntaryZinvoluntaryr5   )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   sH   t  }|D ]}t| |d }|r|||< q|dkr!|dkr!|||< q|S )Nr   r   )collectionsOrderedDictgetattr)selfattrsinfor   r   rt   rt   ru   	_infodict%  s   
zError._infodictc                 C   sP   |  d}|rdddd | D  }nd }ddd t| dd	|fD S )
N)r   ppidr   z(%s), c                 S      g | ]
\}}d ||f qS z%s=%rrt   .0kvrt   rt   ru   
<listcomp>4      z!Error.__str__.<locals>.<listcomp> c                 S   s   g | ]}|r|qS rt   rt   )r   xrt   rt   ru   r   8  s    msg )r   joinitemsr   r   r   detailsrt   rt   ru   __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   rt   r   rt   rt   ru   r   =  r   z"Error.__repr__.<locals>.<listcomp>zpsutil.%s(%s))r   r   r   	__class__rq   r   rt   rt   ru   __repr__:  s   
zError.__repr__N)rq   rr   rs   __doc__r   r   r   rt   rt   rt   ru   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   rt   rt   ru   r   H     
zNoSuchProcess.__init__NNrq   rr   rs   r   r   rt   rt   rt   ru   r   A      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   rt   rt   ru   r   Y  s   zZombieProcess.__init__NNNr   rt   rt   rt   ru   r   O  s    r   c                   @   r   )AccessDeniedz@Exception raised when permission to perform an action is denied.r   Nc                 C   r   )Nr   r   r   rt   rt   ru   r   d  r   zAccessDenied.__init__r   r   rt   rt   rt   ru   r   _  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   rt   rt   ru   r   r  s
   
zTimeoutExpired.__init__r   r   rt   rt   rt   ru   r   k  r   r   execzvdef raise_from(value, from_value):
    try:
        raise value from from_value
    finally:
        value = None
    c                 C   s   | Nrt   )r   
from_valuert   rt   ru   
raise_from     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)r~   r}   Zround_retrt   rt   ru   rN     s   
rN   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()
    >>>

    It supports:
     - functions
     - classes (acts as a @singleton)
     - staticmethods
     - classmethods

    It does NOT support:
     - methods
    c                     sr   | t t| f}z | W S  ty8   z| i | } |< W | Y S  ty7 } zt|d d }~ww w r   )	frozensetsortedr   KeyError	Exceptionr   )argskwargskeyr   errcachefunrt   ru   wrapper  s   

zmemoize.<locals>.wrapperc                      s       dS )zClear cache.N)clearrt   )r   rt   ru   cache_clear     zmemoize.<locals>.cache_clear)	functoolswrapsr   )r   r   r   rt   r   ru   rK     s   rK   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                    s   z| j   }W |S  ty(   z | W  Y S  ty' } zt|d d }~ww  ty[   z | }W n tyE } zt|d d }~ww z	|| j  < W Y |S  tyZ   Y Y |S w w r   )_cacheAttributeErrorr   r   r   )r   r   r   r   rt   ru   r     s2   

z'memoize_when_activated.<locals>.wrapperc                 S   s
   i | _ dS )zsActivate cache. Expects a Process instance. Cache will be
        stored as a "_cache" instance attribute.
        N)r   procrt   rt   ru   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   rt   rt   ru   cache_deactivate  s
   
z0memoize_when_activated.<locals>.cache_deactivate)r   r   r   r   )r   r   r   r   rt   r   ru   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   str   rt   rt   ru   rJ     s   rJ   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   rt   rt   ru   rM   "  s   rM   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)sockrt   rt   ru   rO   1  s   
rO   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 =ro   )r   findupper)datar   posZWINDOWS_Znext_posZ	equal_posr   r   rt   rt   ru   rL   ?  s"   rL   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numrt   rt   ru   rP   [     rP   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  rt   rt   ru   rQ   h  r  rQ   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   rP   rQ   r5   r>   )r   famtype_r   r   r   Z
status_mapr   rt   rt   ru   rX   u  s   rX   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 )Nrn   )category
stacklevel)warningswarnDeprecationWarningr   )r   r   r   )r   replacementrt   ru   inner  s   z/deprecated_method.<locals>.outer.<locals>.inner)rq   r   r   r   )r   r&  r%  )r   ru   outer  s   
z deprecated_method.<locals>.outerrt   )r%  r(  rt   r'  ru   rI     s   rI   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   rt   rt   ru   r     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   rt   rt   ru   	_add_dict  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   r2  keysr.  r-  )r   r3  r   old_dictZ	gone_keysZgone_keyremkeyrt   rt   ru   _remove_dead_reminders  s   
z#_WrapNumbers._remove_dead_remindersc              	   C   s   || j vr| || |S | || | j | }i }|D ]\}|| }z|| }W n ty5   |||< Y qw g }tt|D ]3}	||	 }
||	 }||	f}|
|k re| j| |  |7  < | j| | | |	|
| j| |   q>t
|||< q|| j |< |S )zlCache dict and sum numbers which overflow and wrap.
        Return an updated copy of `input_dict`.
        )r   r4  r8  r   rangelenr-  r.  addappendtuple)r   r3  r   r6  Znew_dictr   Zinput_tupleZ	old_tuplebitsiZinput_value	old_valuer7  rt   rt   ru   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   rt   rt   ru   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/  rt   rt   ru   
cache_info  s   $z_WrapNumbers.cache_infor   )
rq   rr   rs   r   r   r4  r8  rA  r   rC  rt   rt   rt   ru   r)    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,  rA  )r3  r   rt   rt   ru   rR     s   
$rR   i   c                 C   s   t | dtdS )Nrb	buffering)openFILE_READ_BUFFER_SIZE)fnamert   rt   ru   rT        rT   c                 C   sX   t st| tdS t| tttd}zt|_W |S  ty    Y |S  ty+   |   w )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').
    rF  )rG  encodingerrors)	PY3rH  rI  r3   r4   _CHUNK_SIZEr   r   close)rJ  fobjrt   rt   ru   rS     s$   rS   c              	   C   s   |t u r|| }| W  d   S 1 sw   Y  dS z|| }| W  d   W S 1 s3w   Y  W dS  ttfyG   | Y S w )zRead entire file content and return it as a string. File is
    opened in text mode. If specified, `fallback` is the value
    returned in case of error, either if the file does not exist or
    it can't be read().
    N)_DEFAULTreadIOErrorr  )rJ  fallback_openfrt   rt   ru   rU   5  s   
$
(rU   c                 C   s   t | |tdS )z,Same as above but opens file in binary mode.)rU  rV  )rU   rT   )rJ  rU  rt   rt   ru   rV   F  s   rV   %(value).1f%(symbol)sc                 C   s   d}i }t |dd D ]\}}d|d d > ||< qt|dd D ]}t| || 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Yro   N
   r   )symbolr   )	enumeratereversedabsr   localsdict)nformatsymbolsprefixr?  src  r   rt   rt   ru   rW   K  s   rW   c                   C   s   t jd jS )z+Return updated psutil.PROCFS_PATH constant.r   )sysmodulesZPROCFS_PATHrt   rt   rt   ru   get_procfs_path^  r   rp  c                 C   s   | j ttdS )N)rL  rM  )decoder3   r4   rm  rt   rt   ru   rq  e  rK  rq  c                 C   s   | S r   rt   rr  rt   rt   ru   rq  j  r   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tigetnumr   )filert  rt   rt   ru   r[   s  s   
r[   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34Z33Z30Z32Z37Z36Z91Z35Z93)	bluebrownZdarkgreygreenZgreyZ	lightblueredvioletyellowZ29Nz#invalid color %r; choose between %s1z[%sm%s[0m;)r[   rh  r   r  listr5  r<  r   )rm  colorboldattrrs  rt   rt   ru   rZ     s4   

rZ   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.rv  r   N   rn         )ry  rz  rx  r|  z#invalid color %r; choose between %r   ii)r[   printr   rZ   ctypesZwindllZKernel32GetStdHandleSetConsoleTextAttributerh  r   r  r  r5  rn  stderrZc_ulongrestype)rm  r  r  rv  r  ZDEFAULT_COLORr  r  rs  Z	handle_idhandlert   rt   ru   r\     s:   

r\   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]> %sr  )r   inspectgetframeinfocurrentframef_back
isinstancer   r  rT  EnvironmentErrorr  rn  r  )r   r  rJ  lineno_linesindexrt   rt   ru   rY     s   


rY   r   )rX  )NF)r   
__future__r   r   r   r
  r  r   r   r  r   rn  r*  r"  r   r   r   r   r   ImportErrorr	   version_inforN  r  boolgetenvr   objectrR  __all__r   r   r   platform
startswithr   r   r   r   r   r   r   r   ZAIXr)   r*   r&   r+   r-   r1   r%   r/   r0   r'   r(   r.   r,   r2   r   r    r   r   r   r!   r   r   r   r   r   r   r"   r#   r$   IntEnumrp   globalsupdate__members__ry   rz   rx   getfilesystemencodingr3   r4   getfilesystemencodeerrorsr   rF   rB   r@   rA   rC   rG   r>   rD   rE   r?   r   r   r   r   r6   r;   r<   r=   r8   r9   r:   r7   r5   r   rH   r   r   r   r   r   r   r  __builtins__rh  exec_r   r   rN   rK   r   rJ   rM   rO   rL   rP   rQ   rX   rI   r)  rR   rD  r   rC  rI  rT   rS   rU   rV   rW   rp  rq  stdoutr[   rZ   r\   rY   rt   rt   rt   ru   <module>   sx  

&
	

	





#



-G

W	

	

'