o
    UÌh9  ã                   @   s€   d dl Z d dlZddlmZmZ ddlmZmZ e dej	¡Z
ddd	„Zd
d„ Ze d¡dhfgZdd„ Zdd„ Zddd„ZdS )é    Né   )ÚSHELL_NAMESÚShellDetectionFailureé   )ÚprocÚpsad  qemu-
        (alpha
        |armeb
        |arm
        |m68k
        |cris
        |i386
        |x86_64
        |microblaze
        |mips
        |mipsel
        |mips64
        |mips64el
        |mipsn32
        |mipsn32el
        |nios2
        |ppc64
        |ppc
        |sh4eb
        |sh4
        |sparc
        |sparc32plus
        |sparc64
    )é
   c              	   C   s>   t tfD ]}z| | |¡}W |  S  ty   Y qw tdƒ‚)z¡Select a way to obtain process information from the system.

    * `/proc` is used if supported.
    * The system `ps` utility is used as a fallback option.
    z,compatible proc fs or ps utility is required)r   r   Úiter_process_parentsÚEnvironmentErrorr   )ÚpidÚ	max_depthÚimplÚiterator© r   ún/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/shellingham/posix/__init__.pyÚ_iter_process_parents%   s   þÿr   c                 C   s8   t j dd¡}|r|} n| dd… } t j | ¡ ¡ | fS )z6Form shell information from SHELL environ if possible.ÚSHELLÚ r   N)ÚosÚenvironÚgetÚpathÚbasenameÚlower)Úproc_cmdÚlogin_shellr   r   r   Ú_get_login_shell4   s
   r   z^python(\d+(\.\d+)?)?$Úxonshc                 C   s\   t D ])\}}| | ¡sq|D ]}tj |¡ ¡ }tj |¡r*||v r*||f    S qqdS )aV  Get shell invoked via an interpreter.

    Some shells are implemented on, and invoked with an interpreter, e.g. xonsh
    is commonly executed with an executable Python script. This detects what
    script the interpreter is actually running, and check whether that looks
    like a shell.

    See sarugaku/shellingham#26 for rational.
    N)Ú_INTERPRETER_SHELL_NAMESÚmatchr   r   r   r   Úisfile)Ú	proc_nameÚ	proc_argsÚpatternÚshell_namesÚargÚnamer   r   r   Ú_get_interpreter_shellC   s   

€ýr'   c                 G   s~   |   d¡r	t| ƒS tj | ¡ ¡ }|dkst |¡r,|d } |dd … }tj | ¡ ¡ }|tv r4|| fS t	||ƒ}|r=|S d S )Nú-Úrosettar   r   )
Ú
startswithr   r   r   r   r   ÚQEMU_BIN_REGEXÚ	fullmatchr   r'   )ÚcmdÚargsr&   Úshellr   r   r   Ú
_get_shellW   s   

r0   c                 C   s>   t | pt ¡ ƒ} t| |ƒD ]\}}}t|Ž }|r|  S qdS )zAGet the shell that the supplied pid or os.getpid() is running in.N)Ústrr   Úgetpidr   r0   )r   r   r"   Ú_r/   r   r   r   Ú	get_shelli   s   ÿr4   )r   )Nr   )r   ÚreÚ_corer   r   r   r   r   ÚcompileÚVERBOSEr+   r   r   r   r'   r0   r4   r   r   r   r   Ú<module>   s    ç
ÿ