3
mW                 @   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ye W n ek
rR   ejZY nX dd Z	d
ddZ
dd Zddd	ZdS )    Nc             C   sh   t jj| }t jj|sdS t j|j}tjjdrZt j	 dkrZt
|tjtjB tjB @ S t j|t jS )zChecks 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   //usr/lib/python3/dist-packages/pexpect/utils.pyis_executable_file   s    
r   c             C   sv   t jj| dkrt| r| S |dkr*t j}|jd}|s>t j}|jt j}x&|D ]}t jj	|| }t|rP|S qPW dS )zThis 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   Zffr   r   r   which+   s    

r#   c       
      C   s  g }d}d}d}d}d}d}|}x| D ]}	||ks:||kr|	dkrH|}q|	dkrV|}q|	d	krd|}q|	j  r||krvq|j| d}|}q||	 }|}q&||kr||	 }|}q&||kr|	dkr|}q||	 }q&||kr&|	d	kr|}q&||	 }q&W |dkr|j| |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               \'")isspaceappend)
Zcommand_linearg_listargZstate_basicZ	state_escZstate_singlequoteZstate_doublequoteZstate_whitespacestatecr   r   r   split_command_line@   sL    




r1   c             C   s   |dk	rt j  | }xpytj| |||S  tk
r   tj d }|jd tjkrz|dk	r||t j   }|dk r|g g g fS n Y qX qW dS )zThis 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errnoZEINTR)ZiwtdZowtdZewtdZtimeoutZend_timeerrr   r   r   select_ignore_interrupts}   s    	r9   )N)N)r   r	   r   r3   r2   r7   r4   	NameErrorerrorr   r#   r1   r9   r   r   r   r   <module>   s   
=