a
    Š©lcƒ  ã                   @   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yP   ejZY n0 ej	d  dkrhe
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¡rZt  	¡ dkrZt
|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   úI/var/www/html/django/DPS/env/lib/python3.9/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|ƒrN|  S qNd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 ]Æ}	||ks8||kr–|	dkrF|}qê|	dkrT|}qê|	d	krb|}qê|	  ¡ rˆ||krtq”| |¡ d}|}qê||	 }|}q$||kr¬||	 }|}q$||krÌ|	dkrÂ|}qê||	 }q$||kr$|	d	krâ|}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   sL    



r2   c                 C   sŠ   |durt   ¡ | }zt | |||¡W S  ty‚   t ¡ d }|jd tjkr||dur~|t   ¡  }|dk r~g g g f Y S n‚ Y q0 qdS )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). Nr&   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 rTdn|d }| |¡}dd„ |D ƒW S  tyÊ   t	 
¡ d }|jd tjkrÄ|durÆ|t   ¡  }|dk rÆg  Y S n‚ Y qF0 qFdS )zOSimple wrapper around poll to register file descriptors and
    ignore signals.Niè  c                 S   s   g | ]\}}|‘qS r   r   )Ú.0ZafdÚ_r   r   r   Ú
<listcomp>®   ó    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"    "

rK   )N)N)N)r   r
   r   r4   r3   r8   r5   Ú	NameErrorÚerrorÚversion_infoÚstrÚstring_typesÚunicoder   r%   r2   r=   rK   r   r   r   r   Ú<module>   s"   
=
