o
    à©Zhƒ  ã                   @   s¢   d dl Z d dlZd dlZd dlZd dlZd dlZze W n ey(   ejZY nw ej	d  dkr4e
fZnee
fZdd„ Zddd„Zdd„ Zdd	d
„Zddd„ZdS )é    Né   c                 C   sh   t j | ¡}t j |¡sdS t  |¡j}tj d¡r-t  	¡ dkr-t
|tjtjB tjB @ ƒS t  |t j¡S )zšChecks that path is an executable regular file, or a symlink towards one.

    This is roughly ``os.path isfile(path) and os.access(path, os.X_OK)``.
    FÚsunosr   )ÚosÚpathÚrealpathÚisfileÚstatÚst_modeÚsysÚplatformÚ
startswithÚgetuidÚboolÚS_IXUSRÚS_IXGRPÚS_IXOTHÚaccessÚX_OK)r   ZfpathÚmode© r   úD/var/www/html/lang_env/lib/python3.10/site-packages/pexpect/utils.pyÚis_executable_file   s   ÿþr   c                 C   sv   t j | ¡dkrt| ƒr| S |du rt j}| d¡}|st j}| t j¡}|D ]}t j 	|| ¡}t|ƒr8|  S q'dS )zÐThis takes a given filename; tries to find it in the environment path;
    then checks if it is executable. This returns the full path to the filename
    if found and executable. Otherwise this returns None.Ú NÚPATH)
r   r   Údirnamer   ÚenvironÚgetÚdefpathÚsplitÚpathsepÚjoin)ÚfilenameÚenvÚpZpathlistr   Úffr   r   r   Úwhich0   s   
ÿr%   c           
      C   s  g }d}d}d}d}d}d}|}| D ]c}	||ks||krK|	dkr#|}q|	dkr*|}q|	d	kr1|}q|	  ¡ rD||kr:q| |¡ d}|}q||	 }|}q||krV||	 }|}q||krf|	dkra|}q||	 }q||kru|	d	krq|}q||	 }q|dkr| |¡ |S )
a  This splits a command line into a list of arguments. It splits arguments
    on spaces, but handles embedded quotes, doublequotes, and escaped
    characters. It's impossible to do this with a regular expression, so I
    wrote a little state machine to parse the command line. r   r   é   é   r   é   ú\ú'ú")ÚisspaceÚappend)
Zcommand_lineÚarg_listÚargZstate_basicZ	state_escZstate_singlequoteZstate_doublequoteZstate_whitespaceÚstateÚcr   r   r   Úsplit_command_lineE   sN   

€
r2   c                 C   sˆ   |dur
t   ¡ | }	 z	t | |||¡W S  tyB   t ¡ d }|jd tjkr?|dur>|t   ¡  }|dk r>g g g f Y S n‚ Y nw q)zæThis is a wrapper around select.select() that ignores signals. If
    select.select raises a select.error exception and errno is an EINTR
    error then it is ignored. Mainly this is used to ignore sigwinch
    (terminal resize). NTr&   r   )ÚtimeÚselectÚInterruptedErrorr
   Úexc_infoÚargsÚerrnoÚEINTR)ZiwtdZowtdZewtdÚtimeoutÚend_timeÚerrr   r   r   Úselect_ignore_interrupts‚   s"   	€€ôýr=   c                 C   sÐ   |dur
t   ¡ | }t ¡ }| D ]}| |tjtjB tjB tjB ¡ q	 z|du r+dn|d }| |¡}dd„ |D ƒW S  tyf   t	 
¡ d }|jd tjkrc|durb|t   ¡  }|dk rbg  Y S n‚ Y nw q$)zOSimple wrapper around poll to register file descriptors and
    ignore signals.NTiè  c                 S   s   g | ]\}}|‘qS r   r   )Ú.0ZafdÚ_r   r   r   Ú
<listcomp>®   s    z*poll_ignore_interrupts.<locals>.<listcomp>r&   r   )r3   r4   ÚpollÚregisterÚPOLLINÚPOLLPRIÚPOLLHUPÚPOLLERRr5   r
   r6   r7   r8   r9   )Úfdsr:   r;   ZpollerÚfdZ
timeout_msÚresultsr<   r   r   r   Úpoll_ignore_interruptsŸ   s,   "
€€ôûrJ   )N)r   r
   r   r4   r3   r8   r5   Ú	NameErrorÚerrorÚversion_infoÚstrÚstring_typesÚunicoder   r%   r2   r=   rJ   r   r   r   r   Ú<module>   s&    
þ

=