o
    Ñ­jc
  ã                   @   s|   d dl Z d dlZd dlZd dlZddlmZ dZdZe d¡Z	dd„ Z
d	d
„ Zdd„ Zdd„ ZG dd„ deƒZddd„ZdS )é    Né   )ÚProcessé   é   z
\(.+\)|\S+c                  C   s>   t  ¡ } dD ]}t j t j dt| ƒ|¡¡r|  S qtdƒ‚)züDetect /proc filesystem style.

    This checks the /proc/{pid} directory for possible formats. Returns one of
    the following as str:

    * `stat`: Linux-style, i.e. ``/proc/{pid}/stat``.
    * `status`: BSD-style, i.e. ``/proc/{pid}/status``.
    )ÚstatÚstatusú/proczunsupported proc format)ÚosÚgetpidÚpathÚexistsÚjoinÚstrÚProcFormatError)ÚpidÚname© r   úS/var/www/html/CropPilot/venv/lib/python3.10/site-packages/shellingham/posix/proc.pyÚdetect_proc   s   	ÿr   c                   C   s*   z
t  ¡ j ¡ dv W S  ty   Y dS w )N)ÚfreebsdÚnetbsdÚ	dragonflyF)r	   ÚunameÚsysnameÚlowerÚ	Exceptionr   r   r   r   Ú_use_bsd_stat_format#   s
   ÿr   c                 C   sh   t j dt| ƒ|¡}tj|ddd��}t | ¡ ¡}W d   ƒ n1 s$w   Y  t	ƒ r0|t
 S |t S )Nr   ÚasciiÚreplace©ÚencodingÚerrors)r	   r   r   r   ÚioÚopenÚSTAT_PATTERNÚfindallÚreadr   ÚBSD_STAT_PPIDÚLINUX_STAT_PPID)r   r   r   ÚfÚpartsr   r   r   Ú	_get_ppid*   s   ÿr+   c                 C   sn   t j dt| ƒd¡}t ¡ pd}tj||dd��}t| 	¡  
d¡d d… ƒW  d   ƒ S 1 s0w   Y  d S )Nr   Úcmdlinezutf-8r   r   ú éÿÿÿÿ)r	   r   r   r   ÚsysÚgetfilesystemencodingr"   r#   Útupler&   Úsplit)r   r   r    r)   r   r   r   Ú_get_cmdline4   s
   $ûr3   c                   @   s   e Zd ZdS )r   N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   ?   s    r   é
   c                    s   t ƒ ‰ ‡ fdd„}|| |ƒS )z8Try to look up the process tree via the /proc interface.c                 3   sH   � t |ƒD ]}t| ˆ ƒ}t| ƒ}t|| |d�V  |dkr d S |} qd S )N)Úargsr   ÚppidÚ0)Úranger+   r3   r   )r   Ú	max_depthÚ_r9   r8   ©Ú	stat_namer   r   Ú_iter_process_parentsJ   s   €
úz3iter_process_parents.<locals>._iter_process_parents)r   )r   r<   r@   r   r>   r   Úiter_process_parentsC   s   
	rA   )r7   )r"   r	   Úrer/   Ú_corer   r'   r(   Úcompiler$   r   r   r+   r3   ÚEnvironmentErrorr   rA   r   r   r   r   Ú<module>   s    

