o
    Uhc
                     @   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)zDetect /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   j/var/www/html/construction_image-detection-poc/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    

