o
    F+ io                  
   @   s  d 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yQ   dZY nw zddlmZ W n eye   dZY nw 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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>G d.d/ d/ej?Z@eA Be@jC G d0d1 d1ej?ZDeA BeDjC eE ZFeG ZHe
d2g d3ZIe
d4g d5ZJe
d6g d7ZKe
d8g d9ZLe
d:g d;ZMe
d<g d=ZNe
d>g d?ZOe
d@g dAZPe
dBg dCZQe
dDg dEZRe
dFg dGZSe
dHg dIZTe
dJg dKZUe
dLdMdNgZVe
dOg dPZWe
dQdRdSgZXe
dTg dUZYe
dVg dWZZe
dXg dWZ[e
dYg dZZ\e
d[d\d]gZ]e
d^d_d`gZ^e
dag dbZ_e
dcdddegZ`e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dfZaedureaBegegfegegfdg edure#seaBdhegeegfi G didj djebZcG dkdl dlecZdG dmdn dnedZeG dodp dpecZfG dqdr drecZgddsdtZhdudv Zidwdx Zjdydz Zkd{d| Zld}d~ Zmdd Zndd Zodd ZpdddZqdd Zrdd ZsG dd dZtdd Zuet Zvevjweu_wevjxeu_xdZydd Zzdd Z{ee{fddZ|efddZ}dddZ~dd Zdd ZeiejfddZdddZddejfddZdd ZdS )zCommon objects shared by __init__.py and _ps*.py modules.

Note: this module is imported by setup.py, so it should not import
psutil or third-party modules.
    N)
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)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NONEc                   @   s   e Zd ZdZdZdZdS )	NicDuplex      r   N)__name__
__module____qualname__r   r    r!    rn   rn   Z/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/psutil/_common.pyrh      s    rh   c                   @   s   e Zd ZdZdZdS )BatteryTimeN)rk   rl   rm   ZPOWER_TIME_UNKNOWNZPOWER_TIME_UNLIMITEDrn   rn   rn   ro   rp      s    rp   rC   )totalusedfreepercentsinZsoutr?   )rs   rt   ru   rv   r=   )
read_countwrite_count
read_byteswrite_bytesZ	read_timeZ
write_timer>   )ZdeviceZ
mountpointZfstypeoptsr@   )Z
bytes_sentZ
bytes_recvZpackets_sentZpackets_recvZerrinZerroutZdropinZdropoutrD   )nameZterminalhoststartedpidr;   )fdfamilytypeladdrraddrstatusr   rA   )r   addressnetmask	broadcastZptprB   )ZisupZduplexspeedZmtuflagsr<   )Zctx_switchesZ
interruptsZsoft_interruptsZsyscallsscpufreq)currentminmaxshwtemp)labelr   highcriticalsbattery)rv   ZsecsleftZpower_pluggedsfanr   r   r3   )usersystemchildren_userchildren_systemr8   pathr   r9   )idZ	user_timeZsystem_timer:   )realZ	effectivesavedr5   r6   )rx   ry   rz   r{   r7   Zioclassvaluer4   Z	voluntaryZinvoluntaryr2   )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   s>   t  }|D ]}t| |d }|s|dkr|dkr|||< q|S )Nr   r   )collectionsOrderedDictgetattr)selfattrsinfor}   r   rn   rn   ro   	_infodict  s   zError._infodictc                 C   sR   |  d}|rdddd | D }nd }ddd t| dd	|fD S )
N)r   ppidr}   z({}), c                 S      g | ]\}}| d |qS =rn   .0kvrn   rn   ro   
<listcomp>      z!Error.__str__.<locals>.<listcomp> c                 S   s   g | ]}|r|qS rn   rn   )r   xrn   rn   ro   r     s    msg )r   formatjoinitemsr   r   r   detailsrn   rn   ro   __str__  s   
 zError.__str__c                 C   s8   |  d}ddd | D }d| jj d| dS )N)r   r   r}   secondsr   r   c                 S   r   r   rn   r   rn   rn   ro   r   !  r   z"Error.__repr__.<locals>.<listcomp>zpsutil.())r   r   r   	__class__rk   r   rn   rn   ro   __repr__  s   
zError.__repr__N)rk   rl   rm   __doc__r   r   r   rn   rn   rn   ro   r     s    r   c                   @   &   e Zd ZdZdZdddZ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   rn   rn   ro   r   ,     
zNoSuchProcess.__init__c                 C      | j | j| j| jffS Nr   r   r}   r   r   rn   rn   ro   
__reduce__2     zNoSuchProcess.__reduce__NNrk   rl   rm   r   r   r   rn   rn   rn   ro   r   %  s
    
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   rn   rn   ro   r   @  s   zZombieProcess.__init__c                 C   s   | j | j| j| j| jffS r   )r   r   r}   r   r   r   rn   rn   ro   r   E  s   zZombieProcess.__reduce__NNNr   rn   rn   rn   ro   r   6  s
    
r   c                   @   r   )	AccessDeniedz@Exception raised when permission to perform an action is denied.r   Nc                 C   r   )Nr   r   r   rn   rn   ro   r   N  r   zAccessDenied.__init__c                 C   r   r   r   r   rn   rn   ro   r   T  r   zAccessDenied.__reduce__r   r   rn   rn   rn   ro   r   I  s
    
r   c                   @   r   )	TimeoutExpiredzWRaised on Process.wait(timeout) if timeout expires and process
    is still alive.
    r   Nc                 C   s.   t |  || _|| _|| _d| d| _d S )Nztimeout after z seconds)r   r   r   r   r}   r   )r   r   r   r}   rn   rn   ro   r   _  s
   
zTimeoutExpired.__init__c                 C   r   r   )r   r   r   r}   r   rn   rn   ro   r   f  r   zTimeoutExpired.__reduce__r   r   rn   rn   rn   ro   r   X  s
    
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)rt   rs   Zround_retrn   rn   ro   rK   o  s   
rK   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                     sn   | t t| f}z | W S  ty6   z| i | } |< W | Y S  ty5 } z|d d }~ww w r   )	frozensetsortedr   KeyError	Exception)argskwargskeyr   errcachefunrn   ro   wrapper  s   
zmemoize.<locals>.wrapperc                      s       dS )zClear cache.N)clearrn   )r   rn   ro   cache_clear     zmemoize.<locals>.cache_clear)	functoolswrapsr   )r   r   r   rn   r   ro   rH   {  s   rH   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|d d }~ww  tyW   z | }W n tyA } z|d d }~ww z	|| j  < W Y |S  tyV   Y Y |S w w r   )_cacheAttributeErrorr   r   )r   r   r   r   rn   ro   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   procrn   rn   ro   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   rn   rn   ro   cache_deactivate  s
   
z0memoize_when_activated.<locals>.cache_deactivate)r   r   r   r   )r   r   r   r   rn   r   ro   memoize_when_activated  s   r   c                 C   s>   zt | }W n ty     ty   Y dS 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.
    F)osstatPermissionErrorOSErrorS_ISREGst_mode)r   strn   rn   ro   rG     s   rG   c                 C   s4   zt |  W dS  ty     ty   Y dS 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.
    FT)r   r   r   r   )r   rn   rn   ro   rJ     s   rJ   c                  C   sj   t jrtdu r	dS z!t  tt j} | d W d   W dS 1 s#w   Y  W dS  ty4   Y dS w )z2Return True if IPv6 is supported on this platform.NF)z::1r   T)sockethas_ipv6r   r   bindr   )sockrn   rn   ro   rL     s   
rL   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 r   rj   )r   findupper)datar   posZWINDOWS_Znext_posZ	equal_posr   r   rn   rn   ro   rI     s"   rI   c                 C   $   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.
    )r   AddressFamily
ValueErrornumrn   rn   ro   rM   5  
   rM   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.
    )r   
SocketKindr  r  rn   rn   ro   rN   ?  r  rN   c                 C   s   |t jthv r|rt| }|rt| }|t jkr%|tth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   rM   rN   r2   r;   )r   famtype_r   r   r   Z
status_mapr   rn   rn   ro   rU   I  s   rU   c                 C   sx   ddl }| jr
| jsdS | jtjkr#t|j| j d| j ddjS | jtj	kr:t|j
| j d| j ddjS dS )zbGiven the address ntuple returned by ``net_if_addrs()``
    calculates the broadcast address.
    r   N/F)strict)	ipaddressr   r   r   r   r   strIPv4Networkbroadcast_addressr   IPv6Network)r   r  rn   rn   ro   broadcast_addr\  s$   r  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>   | j  d d | jd u r | _t|  fdd}|S )Nz*() is deprecated and will be removed; use z
() insteadc                    s$   t j tdd t| |i |S )Nri   )category
stacklevel)warningswarnDeprecationWarningr   )r   r   r   )r   replacementrn   ro   inner  s   z/deprecated_method.<locals>.outer.<locals>.inner)rk   r   r   r   )r   r!  r   )r   ro   outerw  s   
z deprecated_method.<locals>.outerrn   )r   r#  rn   r"  ro   rF   r  s   rF   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_keysr   rn   rn   ro   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}   rn   rn   ro   	_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   r,  keysr)  r(  )r   r-  r}   old_dictZ	gone_keysZgone_keyremkeyrn   rn   ro   _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   r.  r2  r   rangelenr(  r)  addappendtuple)r   r-  r}   r0  Znew_dictr   Zinput_tupleZ	old_tuplebitsiZinput_value	old_valuer1  rn   rn   ro   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}   rn   rn   ro   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   rn   rn   ro   
cache_info  s   $z_WrapNumbers.cache_infor   )
rk   rl   rm   r   r   r.  r2  r;  r   r=  rn   rn   rn   ro   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;  )r-  r}   rn   rn   ro   rO     s   
$rO   i   c                 C   s   t | dtdS )Nrb)	buffering)openFILE_READ_BUFFER_SIZE)fnamern   rn   ro   rQ        rQ   c                 C   sH   t | tttd}zt|_W |S  ty   Y |S  ty#   |   w )zaOpen a file in text mode by using the proper FS encoding and
    en/decoding error handlers.
    )r@  encodingerrors)rA  rB  r0   r1   _CHUNK_SIZEr   r   close)rC  Zfobjrn   rn   ro   rP     s    rP   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yE   | 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readr   )rC  fallback_openfrn   rn   ro   rR     s   
$
(rR   c                 C   s   t | |tdS )z,Same as above but opens file in binary mode.)rK  rL  )rR   rQ   )rC  rK  rn   rn   ro   rS   *  s   rS   %(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: https://code.activestate.com/recipes/578019-bytes-to-human-human-to-bytes-converter/?in=user-4178764.

    >>> bytes2human(10000)
    '9.8K'
    >>> bytes2human(100001221)
    '95.4M'
    )	BKMGTPEZYrj   N
   r   )symbolr   )	enumeratereversedabsr   localsdict)nr   symbolsprefixr9  srY  r   rn   rn   ro   rT   /  s   rT   c                   C   s   t jd jS )z+Return updated psutil.PROCFS_PATH constant.r   )sysmodulesZPROCFS_PATHrn   rn   rn   ro   get_procfs_pathB  r   re  c                 C   s   | j ttdS )N)rE  rF  )decoder0   r1   )rb  rn   rn   ro   rf  G  rD  rf  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   )filerh  rn   rn   ro   rX   P  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y6   d|dt|  }t|dw || |rC|d dd| d|  d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29Ninvalid color z; choose amongst 1z[;mz[0m)rX   r^  r   listr/  r  r6  r   )rb  colorboldattrrg  r   rn   rn   ro   rW   `  s2   


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
yS   d	|d
t| }	t|	dw |r^|dkr^|d7 }|tju rednd}
|j|_||
}||| zt| |d W ||| dS ||| w )z$Print a colorized version of string.rj  r   N   ri         )rm  rn  rl  rp  rq  z; choose between    ii)rX   printr   rW   ctypesZwindllZKernel32GetStdHandleSetConsoleTextAttributer^  r   ru  r/  r  rc  stderrZc_ulongrestype)rb  rv  rw  rj  r  ZDEFAULT_COLORr  r  rg  r   Z	handle_idhandlern   rn   ro   rY   |  s:   



rY   c                 C   sx   t r:ddl}|| j\}}}}}t| tr(t| tr#d|  } nd| } td| d| d|  t	j
d dS dS )z@If PSUTIL_DEBUG env var is set, print a debug message to stderr.r   Nz	ignoring zpsutil-debug [:z]> ry  )r   inspectgetframeinfocurrentframef_back
isinstancer   r   r~  rc  r  )r   r  rC  lineno__lines_indexrn   rn   ro   rV     s   



rV   r   )rN  )NF)r   r   enumr   r   r   r   rc  r%  r  r   r   r   r   r   ImportErrorr   boolgetenvr   objectrI  __all__r}   r   r   platform
startswithr   r   r   r	   r   r   r
   r   ZAIXr&   r'   r#   r(   r*   r.   r"   r,   r-   r$   r%   r+   r)   r/   r   r   r   r   r   r   r   r   r   r   r   r   IntEnumrh   globalsupdate__members__rp   getfilesystemencodingr0   getfilesystemencodeerrorsr1   rC   r?   r=   r>   r@   rD   r;   rA   rB   r<   r   r   r   r   r3   r8   r9   r:   r5   r6   r7   r4   r2   r   rE   r   r   r   r   r   r   rK   rH   r   rG   rJ   rL   rI   rM   rN   rU   r  rF   r$  rO   r>  r   r=  rB  rQ   rP   rR   rS   rT   re  rf  stdoutrX   rW   rY   rV   rn   rn   rn   ro   <module>   s@  
&
		




!
-G


W	
	

(