
bc        	   @   s  d  Z  d d l Z e j d k Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d e
 f d     YZ e r d d l Z d d l Z d d l Z d f  d     YZ d f  d	     YZ no d d l Z e e d
  Z y d d l Z Wn e k
 re Z n Xd d l Z d d l Z e e d d  Z d d d d d d d g Z e rd d l m Z m Z m Z m Z m Z m  Z  m! Z! m" Z" e j# d d d d d d d d g  n  y e j$ d  Z% Wn d Z% n Xg  Z& d   Z' d Z( d Z) d    Z* d!   Z+ d"   Z, d#   Z- d$   Z. d%   Z/ d e0 f d&     YZ1 d'   Z2 d(   Z3 e4 d) k re r|e3   n e2   n  d S(*   s  Subprocesses with accessible I/O streams

This module allows you to spawn processes, connect to their
input/output/error pipes, and obtain their return codes.

For a complete description of this module see the Python documentation.

Main API
========
call(...): Runs a command, waits for it to complete, then returns
    the return code.
check_call(...): Same as call() but raises CalledProcessError()
    if return code is not 0
check_output(...): Same as check_call() but returns the contents of
    stdout instead of a return code
Popen(...): A class for flexibly executing a command in a new process

Constants
---------
PIPE:    Special value that indicates a pipe should be created
STDOUT:  Special value that indicates that stderr should go to stdout
iNt   win32t   CalledProcessErrorc           B   s#   e  Z d  Z d d  Z d   Z RS(   s   This exception is raised when a process run by check_call() or
    check_output() returns a non-zero exit status.

    Attributes:
      cmd, returncode, output
    c         C   s   | |  _  | |  _ | |  _ d  S(   N(   t
   returncodet   cmdt   output(   t   selfR   R   R   (    (    s    /usr/lib/python2.7/subprocess.pyt   __init__3   s    		c         C   s   d |  j  |  j f S(   Ns-   Command '%s' returned non-zero exit status %d(   R   R   (   R   (    (    s    /usr/lib/python2.7/subprocess.pyt   __str__7   s    N(   t   __name__t
   __module__t   __doc__t   NoneR   R   (    (    (    s    /usr/lib/python2.7/subprocess.pyR   ,   s   t   STARTUPINFOc           B   s&   e  Z d  Z d Z d Z d Z d  Z RS(   i    N(   R   R	   t   dwFlagsR   t	   hStdInputt
   hStdOutputt	   hStdErrort   wShowWindow(    (    (    s    /usr/lib/python2.7/subprocess.pyR   ?   s
   t
   pywintypesc           B   s   e  Z e Z RS(    (   R   R	   t   IOErrort   error(    (    (    s    /usr/lib/python2.7/subprocess.pyR   E   s   t   pollt   PIPE_BUFi   t   Popent   PIPEt   STDOUTt   callt
   check_callt   check_output(   t   CREATE_NEW_CONSOLEt   CREATE_NEW_PROCESS_GROUPt   STD_INPUT_HANDLEt   STD_OUTPUT_HANDLEt   STD_ERROR_HANDLEt   SW_HIDEt   STARTF_USESTDHANDLESt   STARTF_USESHOWWINDOWR   R   R   R    R!   R"   R#   R$   t   SC_OPEN_MAXi   c          C   s_   xX t  D]O }  |  j d t j  } | d  k	 r y t  j |   WqW t k
 rS qW Xq q Wd  S(   Nt
   _deadstate(   t   _activet   _internal_pollt   syst   maxintR   t   removet
   ValueError(   t   instt   res(    (    s    /usr/lib/python2.7/subprocess.pyt   _cleanupk   s    ic         G   sV   xO t  rQ y |  |   SWq t t f k
 rM } | j t j k rG q n    q Xq Wd  S(   N(   t   Truet   OSErrorR   t   errnot   EINTR(   t   funct   argst   e(    (    s    /usr/lib/python2.7/subprocess.pyt   _eintr_retry_callz   s    	c          C   s   i	 d d 6d d 6d d 6d d 6d	 d
 6d d 6d d 6d d 6d d 6}  g  } xP |  j    D]B \ } } t t j |  } | d k rX | j d | |  qX qX Wt t j d  d k r | j d  n  x" t j D] } | j d |  q W| S(   sn   Return a list of command-line arguments reproducing the current
    settings in sys.flags and sys.warnoptions.t   dt   debugt   Ot   optimizet   Bt   dont_write_bytecodet   st   no_user_sitet   St   no_sitet   Et   ignore_environmentt   vt   verboset   bt   bytes_warningt   3t   py3k_warningi    t   -t   hash_randomizations   -Rs   -W(   t   itemst   getattrR)   t   flagst   appendt   warnoptions(   t   flag_opt_mapR5   t   flagt   optRD   (    (    s    /usr/lib/python2.7/subprocess.pyt   _args_from_interpreter_flags   s(    
c          O   s   t  |  |   j   S(   s   Run command with arguments.  Wait for command to complete, then
    return the returncode attribute.

    The arguments are the same as for the Popen constructor.  Example:

    retcode = call(["ls", "-l"])
    (   R   t   wait(   t	   popenargst   kwargs(    (    s    /usr/lib/python2.7/subprocess.pyR      s    c          O   sS   t  |  |   } | rO | j d  } | d k r= |  d } n  t | |   n  d S(   sS  Run command with arguments.  Wait for command to complete.  If
    the exit code was zero then return, otherwise raise
    CalledProcessError.  The CalledProcessError object will have the
    return code in the returncode attribute.

    The arguments are the same as for the Popen constructor.  Example:

    check_call(["ls", "-l"])
    R5   i    N(   R   t   getR   R   (   RV   RW   t   retcodeR   (    (    s    /usr/lib/python2.7/subprocess.pyR      s    
c          O   s   d | k r t  d   n  t d t |  |  } | j   \ } } | j   } | r | j d  } | d k r| |  d } n  t | | d |  n  | S(   s  Run command with arguments and return its output as a byte string.

    If the exit code was non-zero it raises a CalledProcessError.  The
    CalledProcessError object will have the return code in the returncode
    attribute and output in the output attribute.

    The arguments are the same as for the Popen constructor.  Example:

    >>> check_output(["ls", "-l", "/dev/null"])
    'crw-rw-rw- 1 root root 1, 3 Oct 18  2007 /dev/null\n'

    The stdout argument is not allowed as it is used internally.
    To capture standard error in the result, use stderr=STDOUT.

    >>> check_output(["/bin/sh", "-c",
    ...               "ls -l non_existent_file ; exit 0"],
    ...              stderr=STDOUT)
    'ls: non_existent_file: No such file or directory\n'
    t   stdouts3   stdout argument not allowed, it will be overridden.R5   i    R   N(   R,   R   R   t   communicateR   RX   R   R   (   RV   RW   t   processR   t
   unused_errRY   R   (    (    s    /usr/lib/python2.7/subprocess.pyR      s    c         C   sG  g  } t  } x+|  D]#} g  } | r5 | j d  n  d | k pQ d | k pQ | } | rj | j d  n  x | D] } | d k r | j |  qq | d k r | j d t |  d  g  } | j d  qq | r | j |  g  } n  | j |  qq W| r| j |  n  | r | j |  | j d  q q Wd j |  S(   s  
    Translate a sequence of arguments into a command line
    string, using the same rules as the MS C runtime:

    1) Arguments are delimited by white space, which is either a
       space or a tab.

    2) A string surrounded by double quotation marks is
       interpreted as a single argument, regardless of white space
       contained within.  A quoted string can be embedded in an
       argument.

    3) A double quotation mark preceded by a backslash is
       interpreted as a literal double quotation mark.

    4) Backslashes are interpreted literally, unless they
       immediately precede a double quotation mark.

    5) If backslashes immediately precede a double quotation mark,
       every pair of backslashes is interpreted as a literal
       backslash.  If the number of backslashes is odd, the last
       backslash escapes the next double quotation mark as
       described in rule 3.
    t    s   	t   "s   \i   s   \"t    (   t   FalseRO   t   lent   extendt   join(   t   seqt   resultt	   needquotet   argt   bs_buft   c(    (    s    /usr/lib/python2.7/subprocess.pyt   list2cmdline   s4    	c           B   s  e  Z d  Z e Z d d! d! d! d! d! e e d! d! e d! d d  Z d   Z e j	 d  Z
 d! d  Z d   Z e r d   Z d   Z d	   Z d
   Z d! e j e j e j d  Z d   Z d   Z d   Z d   Z d   Z e Z n d   Z e d  Z d   Z d   Z  e! r)e! j"   Z# n d e$ f d     YZ% e%   Z# d   Z e& j' e& j( e& j) e& j* e& j+ e& j, d  Z- d! e& j. e& j/ e& j0 e1 j2 d  Z d   Z d   Z d   Z3 d   Z4 d   Z d   Z d    Z RS("   s   Execute a child program in a new process.

    For a complete description of the arguments see the Python documentation.

    Arguments:
      args: A string, or a sequence of program arguments.

      bufsize: supplied as the buffering argument to the open() function when
          creating the stdin/stdout/stderr pipe file objects

      executable: A replacement program to execute.

      stdin, stdout and stderr: These specify the executed programs' standard
          input, standard output and standard error file handles, respectively.

      preexec_fn: (POSIX only) An object to be called in the child process
          just before the child is executed.

      close_fds: Controls closing or inheriting of file descriptors.

      shell: If true, the command will be executed through the shell.

      cwd: Sets the current directory before the child is executed.

      env: Defines the environment variables for the new process.

      universal_newlines: If true, use universal line endings for file
          objects stdin, stdout and stderr.

      startupinfo and creationflags (Windows only)

    Attributes:
        stdin, stdout, stderr, pid, returncode
    i    c         C   s  t    t | t t f  s+ t d   n  t r | d
 k	 rL t d   n  | r | d
 k	 sv | d
 k	 sv | d
 k	 r t d   q n6 | d
 k	 r t d   n  | d k r t d   n  d
 |  _ d
 |  _	 d
 |  _
 d
 |  _ d
 |  _ | |  _ |  j | | |  \ \ } } } } } } } yA |  j | | | | |
 | | | | |	 | | | | | | |  Wn{ t k
 rt j   \ } } } xF | D]> } y$ t r| j   n t j |  Wqt k
 rqXqW| | |  n Xt r^| d
 k	 rt j | j   d  } n  | d
 k	 r4t j | j   d  } n  | d
 k	 r^t j | j   d  } q^n  | d
 k	 rt j | d |  |  _ n  | d
 k	 r| rt j | d |  |  _	 qt j | d	 |  |  _	 n  | d
 k	 r| rt j | d |  |  _
 qt j | d	 |  |  _
 n  d
 S(   s   Create new Popen instance.s   bufsize must be an integers0   preexec_fn is not supported on Windows platformssS   close_fds is not supported on Windows platforms if you redirect stdin/stdout/stderrs2   startupinfo is only supported on Windows platformsi    s4   creationflags is only supported on Windows platformst   wbt   rUt   rbN(   R/   t
   isinstancet   intt   longt	   TypeErrort	   mswindowsR   R,   t   stdinRZ   t   stderrt   pidR   t   universal_newlinest   _get_handlest   _execute_childt	   ExceptionR)   t   exc_infot   Closet   ost   closet   EnvironmentErrort   msvcrtt   open_osfhandlet   Detacht   fdopen(   R   R5   t   bufsizet
   executableRt   RZ   Ru   t
   preexec_fnt	   close_fdst   shellt   cwdt   envRw   t   startupinfot   creationflagst   p2creadt   p2cwritet   c2preadt   c2pwritet   errreadt   errwritet   to_closet   exc_typet	   exc_valuet	   exc_tracet   fd(    (    s    /usr/lib/python2.7/subprocess.pyR   N  sl    						-	c         C   s(   | j  d d  } | j  d d  } | S(   Ns   
s   
s   (   t   replace(   R   t   data(    (    s    /usr/lib/python2.7/subprocess.pyt   _translate_newlines  s    c         C   sL   |  j  s d  S|  j d |  |  j d  k rH t d  k	 rH t j |   n  d  S(   NR&   (   t   _child_createdR(   R   R   R'   RO   (   R   t   _maxint(    (    s    /usr/lib/python2.7/subprocess.pyt   __del__  s
    	c         C   s   |  j  |  j |  j g j d  d k rd } d } |  j  r | r y |  j  j |  Wq t k
 r } | j t j k r | j t j	 k r   q q Xn  |  j  j
   nV |  j r t |  j j  } |  j j
   n+ |  j r t |  j j  } |  j j
   n  |  j   | | f S|  j |  S(   sf  Interact with process: Send data to stdin.  Read data from
        stdout and stderr, until end-of-file is reached.  Wait for
        process to terminate.  The optional input argument should be a
        string to be sent to the child process, or None, if no data
        should be sent to the child.

        communicate() returns a tuple (stdout, stderr).i   N(   Rt   RZ   Ru   t   countR   t   writeR   R2   t   EPIPEt   EINVALR~   R7   t   readRU   t   _communicate(   R   t   inputRZ   Ru   R6   (    (    s    /usr/lib/python2.7/subprocess.pyR[     s(    '	$		

c         C   s
   |  j    S(   sS   Check if child process has terminated. Set and return returncode
        attribute.(   R(   (   R   (    (    s    /usr/lib/python2.7/subprocess.pyR     s    c         C   s5  t    } | d k r7 | d k r7 | d k r7 d | f Sd \ } } d \ } } d \ }	 }
 | d k r t j t j  } | d k rt j d d  \ } } qnc | t k r t j d d  \ } } n< t | t t	 f  r t
 j |  } n t
 j | j    } |  j |  } | j |  | t k r>| j |  n  | d k rt j t j  } | d k rt j d d  \ } } qnc | t k rt j d d  \ } } n< t | t t	 f  rt
 j |  } n t
 j | j    } |  j |  } | j |  | t k r!| j |  n  | d k rit j t j  }
 |
 d k rt j d d  \ } }
 qnx | t k rt j d d  \ }	 }
 nQ | t k r| }
 n< t | t t	 f  rt
 j |  }
 n t
 j | j    }
 |  j |
  }
 | j |
  | t k r| j |	  n  | | | | |	 |
 f | f S(   s|   Construct and return tuple with IO objects:
            p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
            i    N(   NNNNNN(   NN(   NN(   NN(   t   setR   t   _subprocesst   GetStdHandleR   t
   CreatePipeR   Ro   Rp   Rq   R   t   get_osfhandlet   filenot   _make_inheritablet   addR    R!   R   (   R   Rt   RZ   Ru   R   R   R   R   R   R   R   t   _(    (    s    /usr/lib/python2.7/subprocess.pyRx     sd    	$
	c         C   s+   t  j t  j   | t  j   d d t  j  S(   s2   Return a duplicate of handle, which is inheritablei    i   (   R   t   DuplicateHandlet   GetCurrentProcesst   DUPLICATE_SAME_ACCESS(   R   t   handle(    (    s    /usr/lib/python2.7/subprocess.pyR   6  s    c         C   s   t  j j t  j j t j d   d  } t  j j |  s t  j j t  j j t j  d  } t  j j |  s t	 d   q n  | S(   s,   Find and return absolut path to w9xpopen.exei    s   w9xpopen.exesZ   Cannot locate w9xpopen.exe, which is needed for Popen to work with your shell or platform.(
   R}   t   pathRd   t   dirnameR   t   GetModuleFileNamet   existsR)   t   exec_prefixt   RuntimeError(   R   t   w9xpopen(    (    s    /usr/lib/python2.7/subprocess.pyt   _find_w9xpopen=  s    			c      
      s  t  | t j  s! t |  } n  | d k r9 t   } n  d | | | f k r~ | j t j O_ | | _	 | | _
 | | _ n  |
 r(| j t j O_ t j | _ t j j d d  } d j | |  } t j   d k s t j j |  j   d k r(|  j   } d | | f } |	 t j O}	 q(n    f d   } zj y> t j | | d d t |  |	 | | | 	 \ } } } } Wn% t j k
 r} t | j    n XWd | d k	 r| |  n  | d k	 r| |  n  | d k	 r| |  n  Xt |  _  | |  _! | |  _" | j#   d S(	   s$   Execute program (MS Windows version)t   COMSPECs   cmd.exes
   {} /c "{}"I       s   command.coms   "%s" %sc            s   |  j      j |   d  S(   N(   R|   R+   (   R   (   R   (    s    /usr/lib/python2.7/subprocess.pyt   _close_in_parentw  s    
N($   Ro   t   typest   StringTypesRk   R   R   R   R   R#   R   R   R   R$   R"   R   R}   t   environRX   t   formatt
   GetVersionR   t   basenamet   lowerR   R   t   CreateProcessRp   R   R   t   WindowsErrorR5   R0   R   t   _handleRv   R|   (   R   R5   R   R   R   R   R   Rw   R   R   R   R   R   R   R   R   R   R   t   comspecR   R   t   hpt   htRv   t   tidR6   (    (   R   s    /usr/lib/python2.7/subprocess.pyRy   N  sR    		 
			c         C   sF   |  j  d k r? | |  j d  | k r? | |  j  |  _  q? n  |  j  S(   s   Check if child process has terminated.  Returns returncode
            attribute.

            This method is called by __del__, so it can only refer to objects
            in its local scope.

            i    N(   R   R   R   (   R   R&   t   _WaitForSingleObjectt   _WAIT_OBJECT_0t   _GetExitCodeProcess(    (    s    /usr/lib/python2.7/subprocess.pyR(     s    c         C   sD   |  j  d k r= t j |  j t j  t j |  j  |  _  n  |  j  S(   sO   Wait for child process to terminate.  Returns returncode
            attribute.N(   R   R   R   t   WaitForSingleObjectR   t   INFINITEt   GetExitCodeProcess(   R   (    (    s    /usr/lib/python2.7/subprocess.pyRU     s
    
c         C   s   | j  | j    d  S(   N(   RO   R   (   R   t   fht   buffer(    (    s    /usr/lib/python2.7/subprocess.pyt   _readerthread  s    c         C   s  d  } d  } |  j rY g  } t j d |  j d |  j | f  } | j t  | j   n  |  j r g  } t j d |  j d |  j | f  } | j t  | j   n  |  j	 r%| d  k	 ry |  j	 j
 |  Wqt k
 r} | j t j k r q| j t j k rq  qXn  |  j	 j   n  |  j r;| j   n  |  j rQ| j   n  | d  k	 rj| d } n  | d  k	 r| d } n  |  j rt t d  r| r|  j |  } n  | r|  j |  } qn  |  j   | | f S(   Nt   targetR5   i    t   newlines(   R   RZ   t	   threadingt   ThreadR   t	   setDaemonR0   t   startRu   Rt   R   R   R2   R   R   R~   Rd   Rw   t   hasattrt   fileR   RU   (   R   R   RZ   Ru   t   stdout_threadt   stderr_threadR6   (    (    s    /usr/lib/python2.7/subprocess.pyR     sP    			
		
c         C   s   | t  j k r |  j   ne | t  j k rD t j |  j t  j  n= | t  j k rl t j |  j t  j  n t d j	 |    d S(   s)   Send a signal to the process
            s   Unsupported signal: {}N(
   t   signalt   SIGTERMt	   terminatet   CTRL_C_EVENTR}   t   killRv   t   CTRL_BREAK_EVENTR,   R   (   R   t   sig(    (    s    /usr/lib/python2.7/subprocess.pyt   send_signal  s    c         C   sv   y t  j |  j d  WnX t k
 rq } | j d k r>   n  t  j |  j  } | t  j k re   n  | |  _ n Xd S(   s#   Terminates the process
            i   i   N(   R   t   TerminateProcessR   R1   t   winerrorR   t   STILL_ACTIVER   (   R   R6   t   rc(    (    s    /usr/lib/python2.7/subprocess.pyR     s    c         C   s  t    } d \ } } d \ } } d \ }	 }
 | d k r< n^ | t k rp |  j   \ } } | j | | f  n* t | t t f  r | } n | j   } | d k r n^ | t k r |  j   \ } } | j | | f  n* t | t t f  r | } n | j   } | d k rn | t k rJ|  j   \ }	 }
 | j |	 |
 f  n] | t	 k r}| d k	 rk| }
 qt
 j j   }
 n* t | t t f  r| }
 n | j   }
 | | | | |	 |
 f | f S(   s|   Construct and return tuple with IO objects:
            p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
            N(   NN(   NN(   NN(   R   R   R   t   pipe_cloexect   updateRo   Rp   Rq   R   R   R)   t
   __stdout__(   R   Rt   RZ   Ru   R   R   R   R   R   R   R   (    (    s    /usr/lib/python2.7/subprocess.pyRx     sF    					c         C   s~   y t  j } Wn t k
 r& d } n Xt  j  | t  j  } | r_ t  j  | t  j | | B n t  j  | t  j | | @ d  S(   Ni   (   t   fcntlt
   FD_CLOEXECt   AttributeErrort   F_GETFDt   F_SETFD(   R   R   t   cloexect   cloexec_flagt   old(    (    s    /usr/lib/python2.7/subprocess.pyt   _set_cloexec_flagN  s    
c         C   s6   t  j   \ } } |  j |  |  j |  | | f S(   s#   Create a pipe with FDs set CLOEXEC.(   R}   t   pipeR   (   R   t   rt   w(    (    s    /usr/lib/python2.7/subprocess.pyR   [  s    c         C   s   t  t d  r6 t j d |  t j | d t  nG xD t d t  D]3 } | | k r^ qF n  y t j |  WqF qF XqF Wd  S(   Nt
   closerangei   i   (   R   R}   R   t   MAXFDt   xrangeR~   (   R   t   butt   i(    (    s    /usr/lib/python2.7/subprocess.pyt
   _close_fdsg  s    t   _noop_context_managerc           B   s   e  Z d    Z d   Z RS(   c         C   s   d  S(   N(    (   R   (    (    s    /usr/lib/python2.7/subprocess.pyt	   __enter__~  R`   c         G   s   d  S(   N(    (   R   R5   (    (    s    /usr/lib/python2.7/subprocess.pyt   __exit__  R`   (   R   R	   R   R   (    (    (    s    /usr/lib/python2.7/subprocess.pyR   {  s   	c   !         s  t  | t j  r | g } n t |  } |
 rV d d g | } | rV | | d <qV n  | d k ro | d } n   f d   }   j   \ } } zz  j  t j   } t j	   Wd QXy t
 j     _ Wn | r t j   n    n Xt   _   j d k r0zy| d k	 r)t
 j |  n  | d k	 rEt
 j |  n  | d k	 rat
 j |  n  t
 j |  | d k rt
 j |  } n  | d k s| d k rt
 j |  } n    f d   } | | d  | | d  | | d  d h } xL | | | g D]; } | | k r| d k rt
 j |  | j |  qqW| d k	 r`t
 j |  n  | rp|   n  | r  j d	 |  n  | d k rt
 j | |  n t
 j | | |  Wn\ t j   \ } } } t j | | |  } d
 j |  | _ t
 j | t j |   n XWd t
 j  d  Xn  | rCt j   n  Wd t
 j |  Xt! t
 j" | d  } g  } x, | r| j# |  t! t
 j" | d  } qsWd
 j |  } Wd | d k	 r| d k	 r| |  n  | d k	 r| d k	 r| |  n  | d k	 r!| d k	 r!| |  n  t
 j |  X| d
 k ry t! t
 j$   j d  Wn+ t% k
 r} | j& t& j' k r  qn Xt j( |  }  |   n  d S(   s   Execute program (POSIX version)s   /bin/shs   -ci    c            s   t  j |     j |   d  S(   N(   R}   R~   R+   (   R   (   R   (    s    /usr/lib/python2.7/subprocess.pyR     s    Ni   c            sB   |  | k r   j  |  t  n |  d  k	 r> t j |  |  n  d  S(   N(   R   Ra   R   R}   t   dup2(   t   aRF   (   R   (    s    /usr/lib/python2.7/subprocess.pyt   _dup2  s    i   R   R`   i   i   ()   Ro   R   R   t   listR   R   t   _disabling_gc_lockt   gct	   isenabledt   disableR}   t   forkRv   t   enableR0   R   R~   t   dupR   t   chdirR   t   execvpt   execvpeR)   R{   t	   tracebackt   format_exceptionRd   t   child_tracebackR   t   picklet   dumpst   _exitR7   R   RO   t   waitpidR1   R2   t   ECHILDt   loads(!   R   R5   R   R   R   R   R   Rw   R   R   R   R   R   R   R   R   R   R   R   t   errpipe_readt   errpipe_writet   gc_was_enabledR  t   closedR   R   R   t   tbt	   exc_linesR   t   pickle_bitsR6   t   child_exception(    (   R   R   s    /usr/lib/python2.7/subprocess.pyRy     s    
	 	
		!	
c         C   sl   | |  r | |  |  _  nI | |  r= | |  |  _  n+ | |  r\ | |  |  _  n t d   d  S(   Ns   Unknown child exit status!(   R   R   (   R   t   stst   _WIFSIGNALEDt	   _WTERMSIGt
   _WIFEXITEDt   _WEXITSTATUSt   _WIFSTOPPEDt	   _WSTOPSIG(    (    s    /usr/lib/python2.7/subprocess.pyt   _handle_exitstatus  s    c   	      C   s   |  j  d k r y; | |  j |  \ } } | |  j k rI |  j |  n  Wq | k
 r } | d k	 rt | |  _  n  | j | k r d |  _  q q Xn  |  j  S(   s   Check if child process has terminated.  Returns returncode
            attribute.

            This method is called by __del__, so it cannot reference anything
            outside of the local scope (nor can any methods it calls).

            i    N(   R   R   Rv   R'  R2   (	   R   R&   t   _waitpidt   _WNOHANGt	   _os_errort   _ECHILDRv   R   R6   (    (    s    /usr/lib/python2.7/subprocess.pyR(   +  s    	c         C   s   x |  j  d k r y" t t j |  j d  \ } } Wn: t k
 rp } | j t j k r^   n  |  j } d } n X| |  j k r |  j	 |  q q W|  j  S(   sO   Wait for child process to terminate.  Returns returncode
            attribute.i    N(
   R   R   R7   R}   R  Rv   R1   R2   R  R'  (   R   Rv   R   R6   (    (    s    /usr/lib/python2.7/subprocess.pyRU   F  s    "	
c         C   s   |  j  r/ |  j  j   | s/ |  j  j   q/ n  t rM |  j |  \ } } n |  j |  \ } } | d  k	 r d j |  } n  | d  k	 r d j |  } n  |  j r t	 t
 d  r | r |  j |  } n  | r |  j |  } q n  |  j   | | f S(   NR`   R   (   Rt   t   flushR~   t	   _has_pollt   _communicate_with_pollt   _communicate_with_selectR   Rd   Rw   R   R   R   RU   (   R   R   RZ   Ru   (    (    s    /usr/lib/python2.7/subprocess.pyR   [  s$    	
c            s>  d  } d  } i    i  } t j       f d   }    f d   } |  j rm | rm | |  j t j  n  t j t j B} |  j r | |  j |  g  | |  j j   <} n  |  j	 r | |  j	 |  g  | |  j	 j   <} n  d } xH  r3y  j   }	 Wn5 t j
 k
 r9}
 |
 j d t j k r3q n    n Xx |	 D] \ } } | t j @r| | | t !} y | t j | |  7} Wn5 t k
 r}
 |
 j t j k r| |  q  q,X| t |  k r,| |  q,qA| | @r"t j | d  } | s| |  n  | | j |  qA| |  qAWq W| | f S(   Nc            s*    j  |  j   |  |    |  j   <d  S(   N(   t   registerR   (   t   file_objt	   eventmask(   t   fd2filet   poller(    s    /usr/lib/python2.7/subprocess.pyt   register_and_append  s    c            s,    j  |     |  j     j |   d  S(   N(   t
   unregisterR~   t   pop(   R   (   R3  R4  (    s    /usr/lib/python2.7/subprocess.pyt   close_unregister_and_remove  s    i    i   (   R   t   selectR   Rt   t   POLLOUTt   POLLINt   POLLPRIRZ   R   Ru   R   R5   R2   R3   t	   _PIPE_BUFR}   R   R1   R   Rb   R   RO   (   R   R   RZ   Ru   t	   fd2outputR5  R8  t   select_POLLIN_POLLPRIt   input_offsett   readyR6   R   t   modet   chunkR   (    (   R3  R4  s    /usr/lib/python2.7/subprocess.pyR.  |  sT    			
c         C   s  g  } g  } d  } d  } |  j r: | r: | j |  j  n  |  j r\ | j |  j  g  } n  |  j r~ | j |  j  g  } n  d } x| s | ry" t j | | g   \ } } }	 Wn5 t j k
 r }
 |
 j d t j	 k r q n    n X|  j | k r| | | t
 !} y t j |  j j   |  } WnH t k
 rv}
 |
 j t j k rp|  j j   | j |  j  q  qX| | 7} | t |  k r|  j j   | j |  j  qn  |  j | k rt j |  j j   d  } | d k r|  j j   | j |  j  n  | j |  n  |  j | k r t j |  j j   d  } | d k rr|  j j   | j |  j  n  | j |  q q W| | f S(   Ni    i   R`   (   R   Rt   RO   RZ   Ru   R9  R   R5   R2   R3   R=  R}   R   R   R1   R   R~   R+   Rb   R   (   R   R   t   read_sett	   write_setRZ   Ru   R@  t   rlistt   wlistt   xlistR6   RC  t   bytes_writtenR   (    (    s    /usr/lib/python2.7/subprocess.pyR/    s\    				"
c         C   s   t  j |  j |  d S(   s)   Send a signal to the process
            N(   R}   R   Rv   (   R   R   (    (    s    /usr/lib/python2.7/subprocess.pyR     s    c         C   s   |  j  t j  d S(   s/   Terminate the process with SIGTERM
            N(   R   R   R   (   R   (    (    s    /usr/lib/python2.7/subprocess.pyR     s    c         C   s   |  j  t j  d S(   s*   Kill the process with SIGKILL
            N(   R   R   t   SIGKILL(   R   (    (    s    /usr/lib/python2.7/subprocess.pyR     s    N(5   R   R	   R
   Ra   R   R   R   R   R)   R*   R   R[   R   Rs   Rx   R   R   Ry   R   R   t   WAIT_OBJECT_0R   R(   RU   R   R   R   R   R   R0   R   R   R   R   t   LockR  t   objectR   R}   t   WIFSIGNALEDt   WTERMSIGt	   WIFEXITEDt   WEXITSTATUSt
   WIFSTOPPEDt   WSTOPSIGR'  R  t   WNOHANGR   R2   R  R.  R/  (    (    (    s    /usr/lib/python2.7/subprocess.pyR   )  s`   "			^	"		F			Q	
		;				4							!	=	9		c          C   s(  t  d g d t j   d }  d GH|  GHt j   d k r` t  d g d d   } | j   n  d GHt  d	 g d t } t  d
 d g d | j d t } t | j   d  GHHd GHy t  d g  j   GHWnF t k
 r} | j	 t	 j
 k rd GHd GH| j GHq$d G| j	 GHn Xt j d IJd  S(   Nt   psRZ   i    s   Process list:t   idR   c           S   s   t  j d  S(   Nid   (   R}   t   setuid(    (    (    s    /usr/lib/python2.7/subprocess.pyt   <lambda>  R`   s   Looking for 'hda'...t   dmesgt   grept   hdaRt   s   Trying a weird file...s   /this/path/does/not/exists'   The file didn't exist.  I thought so...s   Child traceback:t   Errors   Gosh.  No error.(   R   R   R[   R}   t   getuidRU   RZ   t   reprR1   R2   t   ENOENTR  R)   Ru   (   t   plistt   pt   p1t   p2R6   (    (    s    /usr/lib/python2.7/subprocess.pyt   _demo_posix  s*    !c          C   sl   d GHt  d d t d t }  t  d d |  j d t } t | j   d  GHd GHt  d	  } | j   d  S(
   Ns%   Looking for 'PROMPT' in set output...R   RZ   R   s   find "PROMPT"Rt   i    s   Executing calc...t   calc(   R   R   R0   RZ   R^  R[   RU   (   Rb  Rc  Ra  (    (    s    /usr/lib/python2.7/subprocess.pyt   _demo_windows+  s    t   __main__(5   R
   R)   t   platformRs   R}   R   R  R  R   R2   Rz   R   R   R   R   R   R   R9  R   R-  t   ImportErrorR   R   R  RM   R=  t   __all__R   R   R   R    R!   R"   R#   R$   Rc   t   sysconfR   R'   R/   R   R   R7   RT   R   R   R   Rk   RM  R   Rd  Rf  R   (    (    (    s    /usr/lib/python2.7/subprocess.pyt   <module>   sp   
:
						!	F   	)	
