U
    ;g>                     @   s  d 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
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ g Ze ZejZe
jeje
jeje
jeje
j ej!e
j"ej#e
j$ej%e
j&ej'e
j(ej)e
j*ej+e
j,ej-e
j.ej/e
j0ej1iZ2e
j3ej4e
j5ej6e
j7ej8e
j9ej:e
j;ej<iZ=e>ddddddddddddZ?e>dddddddddZ@edddd d!gZAed"d#d$d%d&d'd(d)d*gZBed+d,d-d.d/gZCed0eCjDd1 ZEd2d3 ZFd4d5 ZGd6d7 ZHd8d9 ZId:d; ZJd<d= ZKd>d? ZLd@dA ZMejNZNe
jOZOdXdCdDZPdEdF ZQe
jRZRejSZSdYdHdIZTdJdK ZUdLdM ZVdNdO ZWdPdQ ZXejYZYdRdS ZZdTdU Z[G dVdW dWZ\dS )ZzmacOS platform implementation.    N)
namedtuple   )_common)_psposix)_psutil_osx)_psutil_posix)AccessDenied)NoSuchProcess)ZombieProcess)	conn_tmap)conn_to_ntuple)isfile_strict)memoize_when_activated)parse_environ_block)usage_percent                     	   
   )ppidruideuidsuidrgidegidsgidttynrctimestatusname)cpuutimecpustimerssvmspfaultspageins
numthreadsvolctxsw	scputimesusernicesystemidlesvmemtotal	availablepercentusedfreeactiveinactivewiredpmemr'   r(   r)   r*   pfullmem)ussc            	   	   C   sT   t  \} }}}}}|| }|| }||8 }t| | | dd}t| |||||||S )z&System virtual memory as a namedtuple.r   Zround_)cextZvirtual_memr   r2   )	r3   r8   r9   r:   r7   ZspeculativeZavailr6   r5    r@   M/opt/bot/vods_filmes/script/venv/lib/python3.8/site-packages/psutil/_psosx.pyvirtual_memoryo   s    rB   c                  C   s4   t  \} }}}}t|| dd}t| |||||S )z=Swap system memory as a (total, used, free, sin, sout) tuple.r   r>   )r?   Zswap_memr   r   Zsswap)r3   r6   r7   sinZsoutr5   r@   r@   rA   swap_memory~   s    rD   c                  C   s   t  \} }}}t| |||S )z(Return system CPU times as a namedtuple.)r?   	cpu_timesr-   )r.   r/   r0   r1   r@   r@   rA   rE      s    rE   c                  C   s:   g } t  D ](}|\}}}}t||||}| | q| S )z)Return system CPU times as a named tuple.)r?   per_cpu_timesr-   append)retZcpu_tr.   r/   r0   r1   itemr@   r@   rA   rF      s    rF   c                   C   s   t  S )z0Return the number of logical CPUs in the system.)r?   cpu_count_logicalr@   r@   r@   rA   rJ      s    rJ   c                   C   s   t  S )z-Return the number of CPU cores in the system.)r?   cpu_count_coresr@   r@   r@   rA   rK      s    rK   c                  C   s"   t  \} }}}}t| |||S N)r?   	cpu_statsr   Z	scpustats)Zctx_switchesZ
interruptsZsoft_interruptsZsyscallsZ_trapsr@   r@   rA   rM      s       rM   c                  C   s   t  \} }}t| ||gS )zReturn CPU frequency.
    On macOS per-cpu frequency is not supported.
    Also, the returned frequency never changes, see:
    https://arstechnica.com/civis/viewtopic.php?f=19&t=465002.
    )r?   cpu_freqr   Zscpufreq)currZmin_Zmax_r@   r@   rA   rN      s    rN   Fc           	      C   sj   g }t  }|D ]T}|\}}}}|dkr,d}| sJtj|rtj|sJqt||||}|| q|S )z8Return mounted disk partitions as a list of namedtuples.none )	r?   disk_partitionsospathisabsexistsr   Z	sdiskpartrG   )	allretlistZ
partitions	partitionZdeviceZ
mountpointZfstypeoptsntupler@   r@   rA   rR      s    rR   c                  C   sd   zt  \} }}W n tk
r(   Y dS X |dk}|r>tj}n|dkrNtj}n|d }t| ||S )zReturn battery information.Nr   <   )r?   sensors_batteryNotImplementedErrorr   ZPOWER_TIME_UNLIMITEDZPOWER_TIME_UNKNOWNZsbattery)r5   ZminsleftZpower_pluggedZsecsleftr@   r@   rA   r^      s    r^   inetc              	   C   sl   g }t  D ]\}zt|| }W n tk
r8   Y q
Y q
X |r
|D ]"}t||g }|tj|  qBq
|S )z System-wide network connections.)pidsProcessnet_connectionsr	   listrG   r   Zsconn)kindrH   pidZconscr@   r@   rA   rc      s    

rc   c            
      C   s   t   } i }| D ]}z&t|}t|}t|\}}W n0 tk
rl } z|jtjkr\ W 5 d}~X Y qX t	t
drt
|}d|}d|k}	t
|	||||||< q|S )z)Get NIC stats (isup, duplex, speed, mtu).N	NicDuplex,running)net_io_counterskeys
cext_posixZ
net_if_mtuZnet_if_flagsZnet_if_duplex_speedOSErrorerrnoZENODEVhasattrr   rh   joinZ	snicstats)
namesrH   r$   ZmtuflagsZduplexspeederrZoutput_flagsZisupr@   r@   rA   net_if_stats  s,    





    
rv   c                   C   s   t  S )z:The system boot time expressed in seconds since the epoch.)r?   	boot_timer@   r@   r@   rA   rw     s    rw   c            	      C   s\   g } t  }|D ]F}|\}}}}}|dkr,q|s2qt||p>d|pDd||}| | q| S )z:Return currently connected users as a list of namedtuples.~N)r?   usersr   ZsuserrG   )	rX   rawlistrI   r.   ttyhostnameZtstamprf   ntr@   r@   rA   ry   #  s    ry   c                  C   sd   t  } d| kr`ztd  | dd W n2 tk
r@   Y n  tk
r^   | dd Y nX | S Nr   )r?   ra   rb   create_timeinsertr	   r   )Zlsr@   r@   rA   ra   7  s    ra   c                 C   s:   zt | td  }|t jkW S  tk
r4   Y dS X d S )Nr#   F)r?   proc_kinfo_oneshotkinfo_proc_mapSZOMBrn   )rf   str@   r@   rA   	is_zombieJ  s
    r   c                    s   t   fdd}|S )z`Decorator which translates bare OSError exceptions into
    NoSuchProcess and AccessDenied.
    c              
      s   | j | j| j  }}}z | f||W S  tk
rl } z&t|rPt||||t|||W 5 d }~X Y n. tk
r } zt|||W 5 d }~X Y nX d S rL   )	rf   _ppid_nameProcessLookupErrorr   r
   r	   PermissionErrorr   )selfargskwargsrf   r   r$   ru   funr@   rA   wrapperW  s    z wrap_exceptions.<locals>.wrapper)	functoolswraps)r   r   r@   r   rA   wrap_exceptionsR  s    r   c                   @   sl  e Zd ZdZddddgZdd Zeedd	 Zeed
d Z	dd Z
dd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zed d! Zed"d# Zed$d% Zed&d' Zed(d) Zed*d+ Zed,d- Zed.d/ Zed@d1d2Zed3d4 ZedAd6d7Zed8d9 Zed:d; Z ed<d= Z!ed>d? Z"d5S )Brb   z1Wrapper class around underlying C implementation._cacher   r   rf   c                 C   s   || _ d | _d | _d S rL   )rf   r   r   )r   rf   r@   r@   rA   __init__k  s    zProcess.__init__c                 C   s$   t | j}t|ttks t|S rL   )r?   r   rf   lenr   AssertionErrorr   rH   r@   r@   rA   _get_kinfo_procp  s    zProcess._get_kinfo_procc                 C   s$   t | j}t|ttks t|S rL   )r?   Zproc_pidtaskinfo_oneshotrf   r   pidtaskinfo_mapr   r   r@   r@   rA   _get_pidtaskinfox  s    zProcess._get_pidtaskinfoc                 C   s   | j |  | j|  d S rL   )r   Zcache_activater   r   r@   r@   rA   oneshot_enter  s    zProcess.oneshot_enterc                 C   s   | j |  | j|  d S rL   )r   Zcache_deactivater   r   r@   r@   rA   oneshot_exit  s    zProcess.oneshot_exitc                 C   s(   |   td  }|d k	r|S t| jS )Nr$   )r   r   r?   Z	proc_namerf   )r   r$   r@   r@   rA   r$     s    zProcess.namec                 C   s   t | jS rL   )r?   Zproc_exerf   r   r@   r@   rA   exe  s    zProcess.exec                 C   s   t | jS rL   )r?   Zproc_cmdlinerf   r   r@   r@   rA   cmdline  s    zProcess.cmdlinec                 C   s   t t| jS rL   )r   r?   Zproc_environrf   r   r@   r@   rA   environ  s    zProcess.environc                 C   s   |   td  | _| jS )Nr   )r   r   r   r   r@   r@   rA   r     s    zProcess.ppidc                 C   s   t | jS rL   )r?   Zproc_cwdrf   r   r@   r@   rA   cwd  s    zProcess.cwdc                 C   s.   |   }t|td  |td  |td  S )Nr   r   r   r   r   Zpuidsr   r   Zrawtupler@   r@   rA   uids  s    


zProcess.uidsc                 C   s.   |   }t|td  |td  |td  S )Nr   r   r    r   r   r@   r@   rA   gids  s    


zProcess.gidsc                 C   s>   |   td  }t }z
|| W S  tk
r8   Y d S X d S )Nr!   )r   r   r   Zget_terminal_mapKeyError)r   Ztty_nrZtmapr@   r@   rA   terminal  s    
zProcess.terminalc                 C   s6   |   }t|td  |td  |td  |td  S )Nr'   r(   r)   r*   )r   r;   r   r   r@   r@   rA   memory_info  s    



zProcess.memory_infoc                 C   s"   |   }t| j}t||f  S rL   )r   r?   Zproc_memory_ussrf   r<   )r   Z	basic_memr=   r@   r@   rA   memory_full_info  s    zProcess.memory_full_infoc                 C   s(   |   }t|td  |td  ddS )Nr%   r&   g        )r   r   Z	pcputimesr   r   r@   r@   rA   rE     s    

zProcess.cpu_timesc                 C   s   |   td  S )Nr"   )r   r   r   r@   r@   rA   r     s    zProcess.create_timec                 C   s   |   td  }t|dS )Nr,   r   )r   r   r   Zpctxsw)r   Zvolr@   r@   rA   num_ctx_switches  s    zProcess.num_ctx_switchesc                 C   s   |   td  S )Nr+   )r   r   r   r@   r@   rA   num_threads  s    zProcess.num_threadsc                 C   sN   | j dkrg S g }t| j }|D ]&\}}t|r"t||}|| q"|S r~   )rf   r?   Zproc_open_filesr   r   Z	popenfilerG   )r   filesrz   rT   fdr[   r@   r@   rA   
open_files  s    
zProcess.open_filesr`   c              	   C   s\   t | \}}t| j||}g }|D ]2}|\}}}	}
}}t|||	|
||t}|| q$|S rL   )r   r?   Zproc_net_connectionsrf   r   TCP_STATUSESrG   )r   re   Zfamiliestypesrz   rH   rI   r   Zfamtypeladdrraddrr#   r}   r@   r@   rA   rc     s           zProcess.net_connectionsc                 C   s   | j dkrdS t| j S r~   )rf   r?   Zproc_num_fdsr   r@   r@   rA   num_fds  s    
zProcess.num_fdsNc                 C   s   t | j|| jS rL   )r   Zwait_pidrf   r   )r   timeoutr@   r@   rA   wait  s    zProcess.waitc                 C   s   t | jS rL   )rm   getpriorityrf   r   r@   r@   rA   nice_get  s    zProcess.nice_getc                 C   s   t | j|S rL   )rm   setpriorityrf   )r   valuer@   r@   rA   nice_set  s    zProcess.nice_setc                 C   s   |   td  }t|dS )Nr#   ?)r   r   PROC_STATUSESget)r   coder@   r@   rA   r#     s    zProcess.statusc                 C   s<   t | j}g }|D ]"\}}}t|||}|| q|S rL   )r?   Zproc_threadsrf   r   ZpthreadrG   )r   rz   rX   Z	thread_idutimeZstimer[   r@   r@   rA   threads  s    zProcess.threads)r`   )N)#__name__
__module____qualname____doc__	__slots__r   r   r   r   r   r   r   r$   r   r   r   r   r   r   r   r   r   r   rE   r   r   r   r   rc   r   r   r   r   r#   r   r@   r@   r@   rA   rb   f  sr   









	










rb   )F)r`   )]r   ro   r   rS   collectionsr   rQ   r   r   r   r?   r   rm   r   r	   r
   r   r   r   r   r   r   Z__extra__all__ZgetpagesizePAGESIZEZAF_LINKZTCPS_ESTABLISHEDZCONN_ESTABLISHEDZTCPS_SYN_SENTZCONN_SYN_SENTZTCPS_SYN_RECEIVEDZCONN_SYN_RECVZTCPS_FIN_WAIT_1ZCONN_FIN_WAIT1ZTCPS_FIN_WAIT_2ZCONN_FIN_WAIT2ZTCPS_TIME_WAITZCONN_TIME_WAITZTCPS_CLOSEDZ
CONN_CLOSEZTCPS_CLOSE_WAITZCONN_CLOSE_WAITZTCPS_LAST_ACKZCONN_LAST_ACKZTCPS_LISTENZCONN_LISTENZTCPS_CLOSINGZCONN_CLOSINGZPSUTIL_CONN_NONEZ	CONN_NONEr   ZSIDLZSTATUS_IDLEZSRUNZSTATUS_RUNNINGZSSLEEPZSTATUS_SLEEPINGZSSTOPZSTATUS_STOPPEDr   ZSTATUS_ZOMBIEr   dictr   r   r-   r2   r;   _fieldsr<   rB   rD   rE   rF   rJ   rK   rM   rN   
disk_usageZdisk_io_countersrR   r^   rk   Znet_if_addrsrc   rv   rw   ry   ra   Z
pid_existsr   r   rb   r@   r@   r@   rA   <module>   s                     
  	
	

