
P`cc           @   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 Wn e k
 rl e j Z n Xe 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 d S(	   iNi    i   c         C   s   t  j j |   } t  j j |  s( t St  j |  j } t j j	 d  r} t  j
   d k r} t | t j t j Bt j B@ St  j | t  j  S(   s   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)``.
    t   sunosi    (   t   ost   patht   realpatht   isfilet   Falset   statt   st_modet   syst   platformt
   startswitht   getuidt   boolt   S_IXUSRt   S_IXGRPt   S_IXOTHt   accesst   X_OK(   R   t   fpatht   mode(    (    s,   lib/python2.7/site-packages/pexpect/utils.pyt   is_executable_file   s    c         C   s   t  j j |   d k r( t |   r( |  S| d k r@ t  j } n  | j d  } | sa t  j } n  | j t  j	  } x3 | D]+ } t  j j
 | |   } t |  rz | Sqz Wd S(   s   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.t    t   PATHN(   R   R   t   dirnameR   t   Nonet   environt   gett   defpatht   splitt   pathsept   join(   t   filenamet   envt   pt   pathlistR   t   ff(    (    s,   lib/python2.7/site-packages/pexpect/utils.pyt   which0   s    $c   
      C   s  g  } d } d } d } d } d } d } | } x.|  D]&}	 | | k sU | | k r |	 d k rj | } q]|	 d k r | } q]|	 d	 k r | } q]|	 j    r | | k r d
 q | j |  d } | } q]| |	 } | } q7 | | k r| |	 } | } q7 | | k r/|	 d k r"| } q]| |	 } q7 | | k r7 |	 d	 k rP| } q]| |	 } q7 q7 W| d k r}| j |  n  | S(   s  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   i    i   i   i   i   s   \t   't   "N(   t   isspaceR   t   append(
   t   command_linet   arg_listt   argt   state_basict	   state_esct   state_singlequotet   state_doublequotet   state_whitespacet   statet   c(    (    s,   lib/python2.7/site-packages/pexpect/utils.pyt   split_command_lineE   sL    				
	
			c         C   s   | d k	 r t j   | } n  x t r y t j |  | | |  SWq" t k
 r t j   d } | j d t j	 k r | d k	 r | t j   } | d k  r g  g  g  f Sq q   q" Xq" Wd S(   s   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). i   i    N(
   R   t   timet   Truet   selectt   InterruptedErrorR   t   exc_infot   argst   errnot   EINTR(   t   iwtdt   owtdt   ewtdt   timeoutt   end_timet   err(    (    s,   lib/python2.7/site-packages/pexpect/utils.pyt   select_ignore_interrupts   s    		c   
      C   s0  | d k	 r t j   | } n  t j   } x6 |  D]. } | j | t j t j Bt j Bt j B q2 Wx t	 r+yL | d k r d n | d } | j |  } g  | D] \ } } | ^ q SWqg t
 k
 r't j   d }	 |	 j d t j k r!| d k	 r$| t j   } | d k  rg  Sq$q(  qg Xqg Wd S(   sO   Simple wrapper around poll to register file descriptors and
    ignore signals.i  i   i    N(   R   R4   R6   t   pollt   registert   POLLINt   POLLPRIt   POLLHUPt   POLLERRR5   R7   R   R8   R9   R:   R;   (
   t   fdsR?   R@   t   pollert   fdt
   timeout_mst   resultst   afdt   _RA   (    (    s,   lib/python2.7/site-packages/pexpect/utils.pyt   poll_ignore_interrupts   s$    ,	!
(   R   R   R   R6   R4   R:   R7   t	   NameErrort   errort   version_infot   strt   string_typest   unicodeR   R   R$   R3   RB   RP   (    (    (    s,   lib/python2.7/site-packages/pexpect/utils.pyt   <module>   s"   		=