U
    ;go                  R   @   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k
r   dZY nX zddlmZ W n ek
r   dZY nX eed	Ze Zd
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[gRZ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daZ ejdbZ!epe pe!Z"ejdcZ#ejddZ$deZ%dfZ&dgZ'dhZ(diZ)djZ*dkZ+dlZ,dmZ-dnZ.doZ/dpZ0dqZ1drZ2dsZ3dtZ4duZ5dvZ6dwZ7dxZ8dyZ9dzZ:d{Z;d|Z<d}Z=d~Z>G dd dej?Z@eA Be@jC G dd dej?ZDeA BeDjC eE ZFeG ZHe
dEddddddgZIe
dAddddgZJe
d?ddddddgZKe
d@ddddgZLe
dBddddddddgZMe
dFdddddgZNe
d=dddddddgZOe
dCdddddgZPe
dDdddddgZQe
d>ddddgZRe
ddddgZSe
dddddgZTe
ddddgZUe
dddgZVe
d5ddddgZWe
d:ddgZXe
d;dddgZYe
d<dddgZZe
d7dddgZ[e
d8ddddgZ\e
d9ddgZ]e
d6ddgZ^e
d4ddddddgZ_e
dddg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dќZaedk	reaBegegfegegfdҜ edk	r,e#s,eaBdegeegfi G ddՄ debZcG ddׄ decZdG ddل dedZeG ddۄ decZfG dd݄ decZgdddMZhddJ Zidd ZjddI ZkddL ZleiddN ZmddK ZnddO ZoddP Zpd ddWZqdd ZrddH ZsG dd dZtddQ Zuet Zvevjweu_wevjxeu_xdZyddS ZzddR Z{ee{fddTZ|efddUZ}dddVZ~dd Zdd ZeiejfddZZdddYZddejfdd[ZddX 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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wakingZ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!    rp   rp   N/opt/bot/vods_filmes/script/venv/lib/python3.8/site-packages/psutil/_common.pyrj      s   rj   c                   @   s   e Zd ZdZdZdS )BatteryTimeN)rm   rn   ro   ZPOWER_TIME_UNKNOWNZPOWER_TIME_UNLIMITEDrp   rp   rp   rq   rr      s   rr   totalusedfreepercentsinZsoutZ
read_countZwrite_count
read_byteswrite_bytesZ	read_timeZ
write_timeZdeviceZ
mountpointZfstypeoptsZ
bytes_sentZ
bytes_recvZpackets_sentZpackets_recvZerrinZerroutZdropinZdropoutnameZterminalhoststartedpidfdfamilytypeladdrraddrstatusaddressnetmask	broadcastZptpZisupZduplexspeedZmtuflagsZctx_switchesZ
interruptsZsoft_interruptsZsyscallsscpufreqcurrentminmaxshwtemplabelhighcriticalsbatteryZsecsleftZpower_pluggedsfanusersystemchildren_userchildren_systempathidZ	user_timeZsystem_timerealZ	effectiveZsavedZioclassvalueZ	voluntaryZinvoluntary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 }|s0|dkr|dkr|||< q|S )Nr   r   )collectionsOrderedDictgetattr)selfattrsinfor}   r   rp   rp   rq   	_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   s   g | ]\}}| d |qS =rp   .0kvrp   rp   rq   
<listcomp>  s     z!Error.__str__.<locals>.<listcomp> c                 S   s   g | ]}|r|qS rp   rp   )r   xrp   rp   rq   r     s      msg )r   formatjoinitemsr   r   r   detailsrp   rp   rq   __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   s   g | ]\}}| d |qS r   rp   r   rp   rp   rq   r   "  s     z"Error.__repr__.<locals>.<listcomp>zpsutil.())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                   @   s&   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   s$   t |  || _|| _|pd| _d S )Nzprocess no longer existsr   __init__r   r}   r   r   r   r}   r   rp   rp   rq   r   -  s    
zNoSuchProcess.__init__c                 C   s   | j | j| j| jffS Nr   r   r}   r   r   rp   rp   rq   
__reduce__3  s    zNoSuchProcess.__reduce__)NNrm   rn   ro   r   r   r   rp   rp   rp   rq   r   &  s   
r   c                   @   s&   e Zd ZdZdZdddZdd ZdS )	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   A  s    zZombieProcess.__init__c                 C   s   | j | j| j| j| jffS r   )r   r   r}   r   r   r   rp   rp   rq   r   F  s    zZombieProcess.__reduce__)NNNr   rp   rp   rp   rq   r   7  s   
r   c                   @   s&   e Zd ZdZdZdddZdd ZdS )	AccessDeniedz@Exception raised when permission to perform an action is denied.r   Nc                 C   s$   t |  || _|| _|pd| _d S )Nr   r   r   rp   rp   rq   r   O  s    
zAccessDenied.__init__c                 C   s   | j | j| j| jffS r   r   r   rp   rp   rq   r   U  s    zAccessDenied.__reduce__)NNNr   rp   rp   rp   rq   r   J  s   
r   c                   @   s&   e Zd ZdZdZdddZdd ZdS )	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}   rp   rp   rq   r   `  s
    
zTimeoutExpired.__init__c                 C   s   | j | j| j| jffS r   )r   r   r   r}   r   rp   rp   rq   r   g  s    zTimeoutExpired.__reduce__)NNr   rp   rp   rp   rq   r   Y  s   
r   c                 C   sF   zt | | d }W n tk
r*   Y dS X |dk	r>t||}|S dS )z5Calculate percentage usage of 'used' against 'total'.d   g        N)floatZeroDivisionErrorround)rv   ru   Zround_retrp   rp   rq   rK   p  s    
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                     s|   | t t| f}z
 | W S  tk
rv   z| | } |< W n( tk
rl } z
|d W 5 d }~X Y nX | Y S X d S r   )	frozensetsortedr   KeyError	Exception)argskwargskeyr   errcachefunrp   rq   wrapper  s    
zmemoize.<locals>.wrapperc                      s       dS )zClear cache.N)clearrp   )r   rp   rq   cache_clear  s    zmemoize.<locals>.cache_clear)	functoolswrapsr   )r   r   r   rp   r   rq   rH   |  s    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 n tk
rZ   z | W  Y S  tk
rT } z
|d W 5 d }~X Y nX Y nn tk
r   z | }W n( tk
r } z
|d W 5 d }~X Y nX z|| j  < W n tk
r   Y nX Y nX |S r   )_cacheAttributeErrorr   r   )r   r   r   r   rp   rq   r     s"    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   procrp   rp   rq   cache_activate  s    z.memoize_when_activated.<locals>.cache_activatec                 S   s"   z| ` W n tk
r   Y nX dS )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   sJ   zt | }W n* tk
r$    Y n" tk
r8   Y dS X t|jS d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.
    FN)osstatPermissionErrorOSErrorS_ISREGst_mode)r   strp   rp   rq   rG     s    c                 C   sB   zt |  W n* tk
r$    Y n tk
r8   Y dS X dS dS )zSame as os.path.exists() but does not swallow EACCES / EPERM
    exceptions. See:
    http://mail.python.org/pipermail/python-dev/2012-June/120787.html.
    FTN)r   r   r   r   )r   rp   rp   rq   rJ     s    c               	   C   sX   t jrtdkrdS z*t  tt j} | d W 5 Q R X W dS  tk
rR   Y dS X dS )z2Return True if IPv6 is supported on this platform.NF)z::1r   T)sockethas_ipv6r   r   bindr   )sockrp   rp   rq   rL     s    c                 C   sv   i }d}t }| d|}||kr"qr| d||}||krh| || }| |d | }|r`| }|||< |d }q|S )zCParse a C environ block of environment variables into a dictionary.r    r   rl   )r   findupper)datar   posZWINDOWS_Znext_posZ	equal_posr   r   rp   rp   rq   rI     s    
c                 C   s*   zt | W S  tk
r$   |  Y S X dS )zConvert a numeric socket family value to an IntEnum member.
    If it's not a known member, return the numeric value itself.
    N)r   AddressFamily
ValueErrornumrp   rp   rq   rM   7  s    c                 C   s*   zt | W S  tk
r$   |  Y S X dS )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   
SocketKindr   r   rp   rp   rq   rN   A  s    c                 C   s   |t jthkr&|rt| }|r&t| }|t jkrJ|tthkrJ||t}nt}t|}t|}|dkrxt	| |||||S t
| ||||||S dS )z2Convert a raw connection tuple to a proper ntuple.N)r   r   r   r   r   getr   rM   rN   r2   r;   )r   Zfamtype_r   r   r   Z
status_mapr   rp   rp   rq   rU   K  s    c                 C   sx   ddl }| jr| jsdS | jtjkrFt|j| j d| j ddjS | jtj	krtt|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  rp   rp   rq   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 kr" | _t|  fdd}|S )Nz*() is deprecated and will be removed; use z
() insteadc                    s    t j tdd t| ||S )Nrk   )category
stacklevel)warningswarnDeprecationWarningr   )r   r   r   )r   replacementrp   rq   inner  s    z/deprecated_method.<locals>.outer.<locals>.inner)rm   r   r   r   )r   r  r  )r   rq   outery  s    
z deprecated_method.<locals>.outerrp   )r  r  rp   r  rq   rF   t  s    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   rp   rp   rq   r     s    
z_WrapNumbers.__init__c                 C   sX   || j kst|| jkst|| jks*t|| j |< tt| j|< tt| j|< d S r   )r   AssertionErrorr  r  r   defaultdictintset)r   
input_dictr}   rp   rp   rq   	_add_dict  s    
z_WrapNumbers._add_dictc                 C   s\   | j | }t| t|  }|D ]0}| j| | D ]}| j| |= q8| 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_reminders  s    
z#_WrapNumbers._remove_dead_remindersc              	   C   s  || j kr| || |S | || | j | }i }|D ]}|| }z|| }W n  tk
rp   |||< Y q8Y nX g }tt|D ]f}	||	 }
||	 }||	f}|
|k r| j| |  |7  < | j| | | |	|
| j| |   qt
|||< q8|| j |< |S )zlCache dict and sum numbers which overflow and wrap.
        Return an updated copy of `input_dict`.
        )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  s2    



z_WrapNumbers.runNc              	   C   sh   | j X |dkr0| j  | j  | j  n*| j|d | j|d | j|d W 5 Q R X 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  5 Q R  S Q R X 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_info)N)
rm   rn   ro   r   r   r!  r%  r.  r   r0  rp   rp   rp   rq   r    s   '
r  c              
   C   s*   t j t | |W  5 Q R  S Q R X 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}   rp   rp   rq   rO     s    i   c                 C   s   t | dtdS )Nrb)	buffering)openFILE_READ_BUFFER_SIZE)fnamerp   rp   rq   rQ     s    c                 C   sP   t | tttd}z
t|_W n0 tk
r.   Y n tk
rJ   |   Y nX |S )zaOpen a file in text mode by using the proper FS encoding and
    en/decoding error handlers.
    )r3  encodingerrors)r4  r5  r0   r1   _CHUNK_SIZEr   r   close)r6  Zfobjrp   rp   rq   rP     s    
c              
   C   sv   |t kr.|| }| W  5 Q R  S Q R X nDz*|| }| W  5 Q R  W S Q R X W n tk
rp   | Y S X dS )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   )r6  fallback_openfrp   rp   rq   rR     s    

 c                 C   s   t | |tdS )z,Same as above but opens file in binary mode.)r=  r>  )rR   rQ   )r6  r=  rp   rp   rq   rS   ,  s    %(value).1f%(symbol)sc                 C   s   d}i }t |dd D ]\}}d|d d > ||< qt|dd D ]2}t| || krFt| ||  }|t    S qF|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Yrl   N
   r   )symbolr   )	enumeratereversedabsr   localsdict)nr   symbolsprefixr,  srK  r   rp   rp   rq   rT   1  s    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_pathD  s    rW  c                 C   s   | j ttdS )N)r7  r8  )decoder0   r1   )rT  rp   rp   rq   rX  I  s    rX  c                 C   s`   t jdkrdS z2dd l}|  s$t|  |ddks>tW n tk
rV   Y dS X dS d S )Nr[   Tr   colorsF)r   r}   cursesisattyr  Z	setuptermZtigetnumr   )filerZ  rp   rp   rq   rX   R  s    
Fc                 C   s   t  s
| S g }tddddddddd	d
	}d|d< z|| }W n6 tk
rr   d|dt|  }t|dY nX || |r|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   rP  r   listr"  r   r)  r   )rT  colorboldattrrY  r   rp   rp   rq   rW   b  s0    

c              	   C   s  t  st| |d ntr.tt| |||d nddl}d}|jjj}|jjj}t	ddddd}||d< z|| }W n6 t
k
r   d	|d
t| }	t|	dY nX |r|dkr|d7 }|tjkrdnd}
|j|_||
}||| zt| |d W 5 ||| X dS )z$Print a colorized version of string.r\  r   N   rk         )r_  r`  r^  rb  rc  z; choose between    ii)rX   printr   rW   ctypeswindllZKernel32GetStdHandleSetConsoleTextAttributerP  r   rg  r"  r   rU  stderrZc_ulongrestype)rT  rh  ri  r\  rq  ZDEFAULT_COLORrs  rt  rY  r   Z	handle_idhandlerp   rp   rq   rY   ~  s4    

c                 C   st   t rpddl}|| j\}}}}}t| trPt| trFd|  } n
d| } td| d| d|  t	j
d dS )z@If PSUTIL_DEBUG env var is set, print a debug message to stderr.r   Nz	ignoring zpsutil-debug [:z]> rk  )r   inspectgetframeinfocurrentframef_back
isinstancer   r   rp  rU  ru  )r   ry  r6  lineno__lines_indexrp   rp   rq   rV     s    


 )N)N)r@  )NF)r   r   enumr   r   r   r   rU  r  r  r   r   r   r   r   ImportErrorr   boolgetenvr   objectr;  __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   IntEnumrj   globalsupdate__members__rr   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   r1  r   r0  r5  rQ   rP   rR   rS   rT   rW  rX  stdoutrX   rW   rY   rV   rp   rp   rp   rq   <module>   s  

                                                              &

	       
 
 
 
 	




!
-G


W		  
(