o
    hq                  
   @   sh  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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/ZCd0ZDd1ZEedu rd2ZFd3ZGdZHnG d4d5 d5ejIZJeK LeJjM edu r-d6ZNd7ZOnG d8d9 d9ejIZPeK LePjM eQ ZResGd:ZSnzeT ZSW n eUy^   erZd;nd:ZSY nw ed<g d=ZVed>g d?ZWed@g dAZXedBg dCZYedDg dEZZedFg dGZ[edHg dIZ\edJg dKZ]edLg dMZ^edNg dOZ_edPg dQZ`edRg dSZaedTg dUZbedVdWdXgZcedYg dZZded[d\d]gZeed^g d_Zfed`g daZgedbg daZhedcg ddZiededfdggZjedhdidjgZkedkg dlZledmdndog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dpZnedurPenLegegfegegfdq eduraenLdregeegfi G dsdt dteoZpG dudv dvepZqG dwdx dxeqZrG dydz dzepZsG d{d| 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)      r
   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)ZfreebsdZmidnightbsdZopenbsdZ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 )	NicDuplexrl   rm   r   N)__name__
__module____qualname__r#   r$   r%    rr   rr   e/Users/merlin/projects/employee-monitoring-system/venv/lib/python3.10/site-packages/psutil/_common.pyrn      s    rn   c                   @   s   e Zd ZdZdZdS )BatteryTimert   ru   N)ro   rp   rq   POWER_TIME_UNKNOWNPOWER_TIME_UNLIMITEDrr   rr   rr   rs   rv      s    rv   replacesurrogateescaperG   )totalusedfreepercentsinZsoutrC   )r{   r|   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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   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   sH   t  }|D ]}t| |d }|r|||< q|dkr!|dkr!|||< q|S )Nr   r   )collectionsOrderedDictgetattr)selfattrsinfor   r   rr   rr   rs   	_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=%rrr   .0kvrr   rr   rs   
<listcomp>+      z!Error.__str__.<locals>.<listcomp> c                 S   s   g | ]}|r|qS rr   rr   )r   xrr   rr   rs   r   .  s    msg )r   joinitemsr   r   r   detailsrr   rr   rs   __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   rr   r   rr   rr   rs   r   3  r   z"Error.__repr__.<locals>.<listcomp>zpsutil.%s(%s))r   r   r   	__class__ro   r   rr   rr   rs   __repr__0  s   
zError.__repr__N)ro   rp   rq   __doc__r   r   r   rr   rr   rr   rs   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   rr   rr   rs   r   =     
zNoSuchProcess.__init__NNro   rp   rq   r   r   rr   rr   rr   rs   r   7      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   rr   rr   rs   r   M  s   zZombieProcess.__init__NNNr   rr   rr   rr   rs   r   D  s    r   c                   @   r   )AccessDeniedz@Exception raised when permission to perform an action is denied.r   Nc                 C   r   )Nr   r   r   rr   rr   rs   r   W  r   zAccessDenied.__init__r   r   rr   rr   rr   rs   r   S  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   rr   rr   rs   r   d  s
   
zTimeoutExpired.__init__r   r   rr   rr   rr   rs   r   ^  r   r   execzvdef raise_from(value, from_value):
    try:
        raise value from from_value
    finally:
        value = None
    c                 C   s   | Nrr   )r   
from_valuerr   rr   rs   
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_retrr   rr   rs   rO     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()
    >>>

    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funrr   rs   wrapper  s   

zmemoize.<locals>.wrapperc                      s       dS )zClear cache.N)clearrr   )r   rr   rs   cache_clear     zmemoize.<locals>.cache_clear)	functoolswrapsr   )r   r   r   rr   r   rs   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                    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   rr   rs   r     s2   

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   procrr   rr   rs   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   rr   rr   rs   cache_deactivate  s
   
z0memoize_when_activated.<locals>.cache_deactivate)r   r   r   r   )r   r   r   r   rr   r   rs   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   rr   rr   rs   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   rr   rr   rs   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)sockrr   rr   rs   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 =rm   )r   findupper)datar   posZWINDOWS_Znext_posZ	equal_posr   r   rr   rr   rs   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numrr   rr   rs   rQ   I     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  rr   rr   rs   rR   V  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   famtype_r   r   r   Z
status_mapr   rr   rr   rs   rY   c  s   rY   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 )Nrl   )category
stacklevel)warningswarnDeprecationWarningr   )r   r   r   )r   replacementrr   rs   inner  s   z/deprecated_method.<locals>.outer.<locals>.inner)ro   r   r   r   )r   r$  r#  )r   rs   outerz  s   
z deprecated_method.<locals>.outerrr   )r#  r&  rr   r%  rs   rJ   v  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   rr   rr   rs   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   rr   rr   rs   	_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   r0  keysr,  r+  )r   r1  r   old_dictZ	gone_keysZgone_keyremkeyrr   rr   rs   _remove_dead_reminders  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   r2  r6  r3  r   rangelenr+  r,  addappendtuple)r   r1  r   r4  Znew_dictr   Zinput_tupleZ	old_tuplebitsiZinput_value	old_valuer5  rr   rr   rs   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   rr   rr   rs   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-  rr   rr   rs   
cache_info  s   $z_WrapNumbers.cache_infor   )
ro   rp   rq   r   r   r2  r6  r?  r   rA  rr   rr   rr   rs   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*  r?  )r1  r   rr   rr   rs   rS     s   
$rS   i   c                 C   s   t | dtdS )Nrb	buffering)openFILE_READ_BUFFER_SIZE)fnamerr   rr   rs   rU        rU   c                 C   s\   t s	t| dtdS t| d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').
    rtrD  )rE  encodingerrors)	PY3rF  rG  r4   r5   _CHUNK_SIZEr   r   close)rH  Zfobjrr   rr   rs   rT      s   rT   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   )rH  fallback_openfrr   rr   rs   rV     s   
$
(rV   c                 C   s   t | |tdS )z,Same as above but opens file in binary mode.)rS  rT  )rV   rU   )rH  rS  rr   rr   rs   rW   +  s   rW   %(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Yrm   N
   r   )symbolr   )	enumeratereversedr   localsdict)nformatsymbolsprefixr=  sra  r   rr   rr   rs   rX   0  s   	rX   c                   C   s   t jd jS )z+Return updated psutil.PROCFS_PATH constant.r   )sysmodulesZPROCFS_PATHrr   rr   rr   rs   get_procfs_pathD  r   rm  c                 C   s   | j ttdS )N)rK  rL  )decoder4   r5   rj  rr   rr   rs   rn  J  rI  rn  c                 C   s   | S r   rr   ro  rr   rr   rs   rn  M  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   )filerq  rr   rr   rs   r\   V  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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;)r\   re  r   r  listr3  r:  r   )rj  colorboldattrrp  rr   rr   rs   r[   e  s$   


r[   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.rs  r   N   rl   r      )rt  ru  rv  rw  z#invalid color %r; choose between %r   ii)r\   printr   r[   ctypesZwindllZKernel32GetStdHandleSetConsoleTextAttributere  r   r  r|  r3  rk  stderrZc_ulongrestype)rj  r}  r~  rs  r  ZDEFAULT_COLORr  r  rp  Z	handle_idhandlerr   rr   rs   r]   x  s6   

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   rR  EnvironmentErrorr  rk  r  )r   r  rH  lineno_linesindexrr   rr   rs   rZ     s   


rZ   r   )rV  )NF)r   
__future__r   r   r   r  r   r   r   r  r   rk  r(  r   r   r   r   r   r   ImportErrorr	   version_infor  rM  boolgetenvr   objectrP  __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%   IntEnumrn   globalsupdate__members__rw   rx   rv   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   r   r   r   r   r   r   r  __builtins__re  exec_r   r   rO   rL   r   rK   rN   rP   rM   rQ   rR   rY   rJ   r'  rS   rB  r   rA  rG  rU   rT   rV   rW   rX   rm  rn  stdoutr\   r[   r]   rZ   rr   rr   rr   rs   <module>   st  


%
	

	






!



,E

W	

	

#