o
    !j)>                     @   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
j/ej0iZ1e
j2ej3e
j4ej5e
j6ej7e
j8ej9e
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?dd Z@dd  ZAe
jBZBe
jCZCd!d" ZDd#d$ ZEd%d& ZFd'd( ZGd)d* ZHe
I rd+d, ZJejKZKe
jLZLdDd.d/ZMd0d1 ZNe
jOZOe
jPZPdEd3d4ZQd5d6 ZRd7d8 ZSzeS ZTW n eUy; ZV zed9eV dZTW Y dZV[VndZV[Vww d:d; ZWd<d= ZXd>d? ZYejZZZd@dA Z[G dBdC dCZ\dS )FzmacOS platform implementation.    N   )_common)_ntuples)_psposix)_psutil_osx)AccessDenied)NoSuchProcess)ZombieProcess)	conn_tmap)conn_to_ntuple)debug)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volctxswc            	   
   C   sV   t  \} }}}}}|| }|| }||8 }t| | | dd}t| |||||||S )z&System virtual memory as a namedtuple.r   Zround_)cextZvirtual_memr   ntpZsvmem)	totalZactiveZinactiveZwiredfreeZspeculativeZavailusedpercent r4   N/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/psutil/_psosx.pyvirtual_memory[   s   r6   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)r0   r2   r1   sinZsoutr3   r4   r4   r5   swap_memoryl   s   r8   c                  C   s    t  \} }}}t| |||S )z(Return system CPU times as a namedtuple.)r.   	cpu_timesr/   	scputimes)usernicesystemidler4   r4   r5   r9   }   s   r9   c                  C   s<   g } t  D ]}|\}}}}t||||}| | q| S )z)Return system CPU times as a named tuple.)r.   per_cpu_timesr/   r:   append)retZcpu_tr;   r<   r=   r>   itemr4   r4   r5   r?      s   r?   c                   C      t  S )z0Return the number of logical CPUs in the system.)r.   cpu_count_logicalr4   r4   r4   r5   rD         rD   c                   C   rC   )z-Return the number of CPU cores in the system.)r.   cpu_count_coresr4   r4   r4   r5   rF      rE   rF   c                  C   s"   t  \} }}}}t| |||S N)r.   	cpu_statsr/   Z	scpustats)Zctx_switchesZ
interruptsZsoft_interruptsZsyscallsZ_trapsr4   r4   r5   rH      s   rH   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_r4   r4   r5   rI      s   rI   Fc           	      C   sj   g }t  }|D ]*}|\}}}}|dkrd}| s%tj|r$tj|s%qt||||}|| q|S )z8Return mounted disk partitions as a list of namedtuples.none )	r.   disk_partitionsospathisabsexistsr/   Z	sdiskpartr@   )	allretlistZ
partitions	partitionZdeviceZ
mountpointZfstypeoptsntupler4   r4   r5   rM      s   rM   c                  C   sb   z	t  \} }}W n
 ty   Y dS w |dk}|rtj}n|dkr&tj}n|d }t| ||S )zReturn battery information.Nr   <   )r.   sensors_batteryNotImplementedErrorr   ZPOWER_TIME_UNLIMITEDZPOWER_TIME_UNKNOWNr/   Zsbattery)r3   ZminsleftZpower_pluggedZsecsleftr4   r4   r5   rY      s   rY   inetc              	   C   sf   g }t  D ]+}z	t|| }W n	 ty   Y qw |r0|D ]}t||g }|tj|  qq|S )z System-wide network connections.)pidsProcessnet_connectionsr   listr@   r/   Zsconn)kindrA   pidZconscr4   r4   r5   r^      s   
r^   c            
      C   s   t   } i }| D ]M}zt|}t|}t|\}}W n ty7 } z|jtjkr- W Y d}~q	d}~ww t	t
drBt
|}d|}d|v }	t|	||||||< q	|S )z)Get NIC stats (isup, duplex, speed, mtu).N	NicDuplex,running)net_io_counterskeysr.   Z
net_if_mtuZnet_if_flagsZnet_if_duplex_speedOSErrorerrnoZENODEVhasattrr   rc   joinr/   Z	snicstats)
namesrA   r$   ZmtuflagsZduplexspeederrZoutput_flagsZisupr4   r4   r5   net_if_stats   s&   





rp   c                   C   rC   )z:The system boot time expressed in seconds since the epoch.)r.   	boot_timer4   r4   r4   r5   rq     rE   rq   zignoring exception on import: c                 C   sN   t dkr| S t t  }|dkst|dk r| S td |dk r#| | S | | S )z!Account for system clock updates.r   r   z9system clock was updated; adjusting process create_time())INIT_BOOT_TIMErq   absr   )r"   diffr4   r4   r5   adjust_proc_create_time  s   
ru   c            	      C   s\   g } t  }|D ]#}|\}}}}}|dkrq|sqt||pd|p"d||}| | q| S )z:Return currently connected users as a list of namedtuples.~N)r.   usersr/   Zsuserr@   )	rS   rawlistrB   r;   ttyhostnameZtstampra   ntr4   r4   r5   rw   +  s   rw   c                  C   sf   t  } d| vr1ztd  | dd W | S  ty!   Y | S  ty0   | dd Y | S w | S Nr   )r.   r\   r]   create_timeinsertr   r   )Zlsr4   r4   r5   r\   ?  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 | g|R i |W S  ty5 } zt|r+t||||t|||d }~w tyF } zt	|||d }~w tj
yY } zt||||d }~ww rG   )ra   _ppid_nameProcessLookupErrorr.   Zproc_is_zombier	   r   PermissionErrorr   ZZombieProcessError)selfargskwargsra   r   r$   ro   funr4   r5   wrapperW  s   
z wrap_exceptions.<locals>.wrapper)	functoolswraps)r   r   r4   r   r5   wrap_exceptionsR  s   r   c                   @   sj  e Zd ZdZg d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&d'Zed(d) Zed*d+ Zed,d- Zed?d/d0Zed1d2 Zed@d4d5Zed6d7 Zed8d9 Z ed:d; Z!ed<d= Z"d3S )Ar]   z1Wrapper class around underlying C implementation.)_cacher   r   ra   c                 C   s   || _ d | _d | _d S rG   )ra   r   r   )r   ra   r4   r4   r5   __init__m  s   
zProcess.__init__c                 C   $   t | j}t|ttksJ |S rG   )r.   Zproc_kinfo_oneshotra   lenkinfo_proc_mapr   rA   r4   r4   r5   _get_kinfo_procr     zProcess._get_kinfo_procc                 C   r   rG   )r.   Zproc_pidtaskinfo_oneshotra   r   pidtaskinfo_mapr   r4   r4   r5   _get_pidtaskinfoz  r   zProcess._get_pidtaskinfoc                 C      | j |  | j|  d S rG   )r   Zcache_activater   r   r4   r4   r5   oneshot_enter     zProcess.oneshot_enterc                 C   r   rG   )r   Zcache_deactivater   r   r4   r4   r5   oneshot_exit  r   zProcess.oneshot_exitc                 C   s(   |   td  }|d ur|S t| jS )Nr$   )r   r   r.   Z	proc_namera   )r   r$   r4   r4   r5   r$     s   zProcess.namec                 C      t | jS rG   )r.   Zproc_exera   r   r4   r4   r5   exe     zProcess.exec                 C   r   rG   )r.   Zproc_cmdlinera   r   r4   r4   r5   cmdline  r   zProcess.cmdlinec                 C   s   t t| jS rG   )r   r.   Zproc_environra   r   r4   r4   r5   environ     zProcess.environc                 C   s   |   td  | _| jS )Nr   )r   r   r   r   r4   r4   r5   r     s   zProcess.ppidc                 C   r   rG   )r.   Zproc_cwdra   r   r4   r4   r5   cwd  r   zProcess.cwdc                 C   .   |   }t|td  |td  |td  S )Nr   r   r   r   r/   Zpuidsr   r   Zrawtupler4   r4   r5   uids     


zProcess.uidsc                 C   r   )Nr   r   r    r   r   r4   r4   r5   gids  r   zProcess.gidsc                 C   s8   |   td  }t }z|| W S  ty   Y d S w )Nr!   )r   r   r   Zget_terminal_mapKeyError)r   Ztty_nrZtmapr4   r4   r5   terminal  s   
zProcess.terminalc                 C   s8   |   }t|td  |td  |td  |td  S )Nr'   r(   r)   r*   )r   r/   Zpmemr   r   r4   r4   r5   memory_info  s   



zProcess.memory_infoc                 C   s$   |   }t| j}tj||f  S rG   )r   r.   Zproc_memory_ussra   r/   Zpfullmem)r   Z	basic_memZussr4   r4   r5   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   r4   r4   r5   r9     s   

zProcess.cpu_timesFc                 C   s    |   td  }|st|}|S )Nr"   )r   r   ru   )r   	monotonicr"   r4   r4   r5   r}     s   zProcess.create_timec                 C      |   td  }t|dS )Nr,   r   )r   r   r/   Zpctxsw)r   Zvolr4   r4   r5   num_ctx_switches  s   zProcess.num_ctx_switchesc                 C   s   |   td  S )Nr+   )r   r   r   r4   r4   r5   num_threads  r   zProcess.num_threadsc                 C   sN   | j dkrg S g }t| j }|D ]\}}t|r$t||}|| q|S r|   )ra   r.   Zproc_open_filesr   r/   Z	popenfiler@   )r   filesrx   rO   fdrV   r4   r4   r5   
open_files  s   

zProcess.open_filesr[   c              	   C   s\   t | \}}t| j||}g }|D ]}|\}}}	}
}}t|||	|
||t}|| q|S rG   )r
   r.   Zproc_net_connectionsra   r   TCP_STATUSESr@   )r   r`   Zfamiliestypesrx   rA   rB   r   Zfamtypeladdrraddrr#   r{   r4   r4   r5   r^     s   zProcess.net_connectionsc                 C   s   | j dkrdS t| j S r|   )ra   r.   Zproc_num_fdsr   r4   r4   r5   num_fds  s   
zProcess.num_fdsNc                 C      t | j|S rG   )r   Zwait_pidra   )r   timeoutr4   r4   r5   wait     zProcess.waitc                 C   r   rG   )r.   Zproc_priority_getra   r   r4   r4   r5   nice_get  r   zProcess.nice_getc                 C   r   rG   )r.   Zproc_priority_setra   )r   valuer4   r4   r5   nice_set  r   zProcess.nice_setc                 C   r   )Nr#   ?)r   r   PROC_STATUSESget)r   coder4   r4   r5   r#     s   zProcess.statusc                 C   s<   t | j}g }|D ]\}}}t|||}|| q
|S rG   )r.   Zproc_threadsra   r/   Zpthreadr@   )r   rx   rS   	thread_idutimeZstimerV   r4   r4   r5   threads  s   zProcess.threadsFr[   rG   )#__name__
__module____qualname____doc__	__slots__r   r   r   r   r   r   r   r$   r   r   r   r   r   r   r   r   r   r   r9   r}   r   r   r   r^   r   r   r   r   r#   r   r4   r4   r4   r5   r]   h  st    









	









r]   r   r   )]r   ri   r   rN   rL   r   r   r/   r   r   r.   r   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_STOPPEDZSZOMBZSTATUS_ZOMBIEr   dictr   r   r6   r8   Z	heap_infoZ	heap_trimr9   r?   rD   rF   rH   Zhas_cpu_freqrI   
disk_usageZdisk_io_countersrM   rY   rf   Znet_if_addrsr^   rp   rq   rr   	Exceptionro   ru   rw   r\   Z
pid_existsr   r]   r4   r4   r4   r5   <module>   s   



