
    e                         d dl Z d dlZd dlZd dlZd dlZd dlZ	 e ej                  d    dk\  re
fZnee
fZd ZddZd ZddZddZy# e$ r ej                  ZY @w xY w)	    N   c                    t         j                  j                  |       }t         j                  j                  |      syt        j                  |      j
                  }t        j                  j                  d      rUt        j                         dk(  r>t        |t        j                  t        j                  z  t        j                  z  z        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   fpathmodes      //usr/lib/python3/dist-packages/pexpect/utils.pyis_executable_filer      s     GGT"E77>>% 775>!!D(		q  DDLL LL) LL) * + 	+ 99UBGG$$    c                 v   t         j                  j                  |       dk7  rt        |       r| S |t         j                  }|j                  d      }|st         j                  }|j                  t         j                        }|D ]1  }t         j                  j                  ||       }t        |      s/|c S  y)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ppathlistr   ffs         r   whichr*   0   s     
wwx B&+=h+G
{jjAJJwwrzz"H WW\\$)b!I r   c                 r   g }d}d}d}d}d}d}|}| D ]  }	||k(  s||k(  rL|	dk(  r|}|	dk(  r|}|	d	k(  r|}%|	j                         r||k(  r;|j                  |       d}|}Q||	z   }|}Y||k(  r||	z   }|}f||k(  r|	dk(  r|}s||	z   }y||k(  s|	d	k(  r|}||	z   } |dk7  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         r      \'")isspaceappend)
command_linearg_listargstate_basic	state_escstate_singlequotestate_doublequotestate_whitespacestatecs
             r   split_command_liner>   E   s    H
C KIE #K5,<#<Dy!d)d),,OOC(C,EAg#i'CE''Dy#Ag''Dy#AgG#J byOr   c                 B   |t        j                          |z   }	 	 t        j                  | |||      S # t        $ r` t        j                         d   }|j
                  d   t        j                  k(  r%|$t        j                          z
  }|dk  rg g g fcY S  Y nw xY w)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). r,   r   )timeselectInterruptedErrorr   exc_infoargserrnoEINTR)iwtdowtdewtdtimeoutend_timeerrs         r   select_ignore_interruptsrM      s     99;(
	==tT7;; 	,,.#Cxx{ekk) &&4G{!2rl* 	 s   4 A#BBBc                 R   |t        j                          |z   }t        j                         }| D ]U  }|j                  |t        j                  t        j
                  z  t        j                  z  t        j                  z         W 	 	 |dn|dz  }|j                  |      }|D cg c]  \  }}|	 c}}S c c}}w # t        $ r] t        j                         d   }	|	j                  d   t        j                  k(  r"|!t        j                          z
  }|dk  rg cY S  Y nw xY w)zOSimple wrapper around poll to register file descriptors and
    ignore signals.Ni  r,   r   )r@   rA   pollregisterPOLLINPOLLPRIPOLLHUPPOLLERRrB   r   rC   rD   rE   rF   )
fdsrJ   rK   pollerfd
timeout_msresultsafd_rL   s
             r   poll_ignore_interruptsr\      s    99;([[]F ^FMMFNN:V^^Kfnn\]^ 	!(gnJkk*-G&-.FCC... 	,,.#Cxx{ekk) &&4G{!	 	 s+   
B? )B95B? 9B? ?A D%!D%$D%)N)r   r   r
   rA   r@   rE   rB   	NameErrorerrorversion_infostrstring_typesunicoder   r*   r>   rM   r\    r   r   <module>rd      sz    	 
    $
 A!6LS>L%8*:z:k  $||$s   A	 	AA