
j\c        	   @   ss  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 d l
 Z
 d d l Z d e f d     YZ d e f d     YZ d e f d	     YZ e rd d l Z d d l Z d d l Z d
 d7 d     YZ d d8 d     YZ n d d l Z e e d  Z d d l Z d d l Z y d d l Z Wn3 e k
 rd Z d d l Z e j d e   n Xy d d l Z Wn e k
 rd d l! Z n Xe" e d d  Z# e" e d d  Z$ d   Z% e re j& Z' n	 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/ m0 Z0 d Z1 e( j2 d d d  d! d" d# d$ d% g  n  y e j3 d&  Z4 Wn d' Z4 n Xg  Z5 d(   Z6 d Z7 d) Z8 d* Z9 d+   Z: d,   Z; d d-  Z< e e d.  re j= Z< n  d/   Z> d0   Z? d1   Z@ d2 eA f d3     YZB d4   ZC d5   ZD eA   ZE d eA f d6     YZF d S(9   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
========
run(...): Runs a command, waits for it to complete, then returns a
          CompletedProcess instance.
Popen(...): A class for flexibly executing a command in a new process

Constants
---------
DEVNULL: Special value that indicates that os.devnull should be used
PIPE:    Special value that indicates a pipe should be created
STDOUT:  Special value that indicates that stderr should go to stdout


Older 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
iNt   win32t   SubprocessErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s+   lib/python2.7/site-packages/subprocess32.pyR   5   s    t   CalledProcessErrorc           B   sG   e  Z d  Z d d d  Z d   Z d   Z d   Z e e e  Z	 RS(   s   Raised when run() is called with check=True and the process
    returns a non-zero exit status.

    Attributes:
      cmd, returncode, stdout, stderr, output
    c         C   sG   | |  _  | |  _ | |  _ | |  _ t t |   j | | | |  d  S(   N(   t
   returncodet   cmdt   outputt   stderrt   superR   t   __init__(   t   selfR   R   R   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR
   ?   s    				c         C   sE   |  j  r- |  j  d k  r- d |  j |  j  f Sd |  j |  j  f Sd  S(   Ni    s!   Command '%s' died with signal %d.s.   Command '%s' returned non-zero exit status %d.(   R   R   (   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyt   __str__G   s
    c         C   s   |  j  S(   s+   Alias for output attribute, to match stderr(   R   (   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyt   __stdout_getterP   s    c         C   s   | |  _  d  S(   N(   R   (   R   t   value(    (    s+   lib/python2.7/site-packages/subprocess32.pyt   __stdout_setterU   s    N(
   R   R   t   __doc__t   NoneR
   R   t"   _CalledProcessError__stdout_gettert"   _CalledProcessError__stdout_settert   propertyt   stdout(    (    (    s+   lib/python2.7/site-packages/subprocess32.pyR   8   s   				t   TimeoutExpiredc           B   sG   e  Z d  Z d d d  Z d   Z d   Z d   Z e e e  Z	 RS(   s   This exception is raised when the timeout expires while waiting for a
    child process.

    Attributes:
        cmd, output, stdout, stderr, timeout
    c         C   sG   | |  _  | |  _ | |  _ | |  _ t t |   j | | | |  d  S(   N(   R   t   timeoutR   R   R	   R   R
   (   R   R   R   R   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR
   d   s
    				c         C   s   d |  j  |  j f S(   Ns'   Command '%s' timed out after %s seconds(   R   R   (   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR   k   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR   p   s    c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR   t   s    N(
   R   R   R   R   R
   R   t   _TimeoutExpired__stdout_gettert   _TimeoutExpired__stdout_setterR   R   (    (    (    s+   lib/python2.7/site-packages/subprocess32.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+   lib/python2.7/site-packages/subprocess32.pyR      s
   t
   pywintypesc           B   s   e  Z e Z RS(    (   R   R   t   IOErrort   error(    (    (    s+   lib/python2.7/site-packages/subprocess32.pyR       s   t   pollsq   The _posixsubprocess module is not being used. Child process reliability may suffer if your program uses threads.t   PIPE_BUFi   t
   FD_CLOEXECi   c         C   sW   t  j  |  t  j  } | r8 t  j  |  t  j | t B n t  j  |  t  j | t @ d  S(   N(   t   fcntlt   F_GETFDt   F_SETFDt   _FD_CLOEXEC(   t   fdt   cloexect   old(    (    s+   lib/python2.7/site-packages/subprocess32.pyt   _set_cloexec   s    c          C   s2   t  j   }  t |  d t  t |  d t  |  S(   Ni    i   (   t   ost   pipeR-   t   True(   t   fds(    (    s+   lib/python2.7/site-packages/subprocess32.pyt   _create_pipe   s    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_USESHOWWINDOWi  R9   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+   lib/python2.7/site-packages/subprocess32.pyt   _cleanup   s    iic          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   getattrRE   t   flagst   appendt   warnoptions(   t   flag_opt_mapt   argst   flagt   optRX   (    (    s+   lib/python2.7/site-packages/subprocess32.pyt   _args_from_interpreter_flags   s(    
c         G   sV   xO t  rQ y |  |   SWq t t f k
 rM } | j t j k rG q n    q Xq Wd  S(   N(   R0   t   OSErrorR!   t   errnot   EINTR(   t   funcRf   t   e(    (    s+   lib/python2.7/site-packages/subprocess32.pyt   _eintr_retry_call   s    	c         C   s7   |  d k r t j }  n  |  j d t j  j t j  S(   s   Returns the sequence of directories that will be searched for the
    named executable (similar to a shell) when launching a process.

    *env* must be an environment variable dict or None.  If *env* is None,
    os.environ will be used.
    t   PATHN(   R   R.   t   environt   gett   defpatht   splitt   pathsep(   t   env(    (    s+   lib/python2.7/site-packages/subprocess32.pyt   _get_exec_path  s    t   get_exec_pathc          O   sd   | j  d d  } t |  |   } y | j d |  SWn( t k
 r_ | j   | j     n Xd S(   s   Run command with arguments.  Wait for command to complete or
    timeout, then return the returncode attribute.

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

    retcode = call(["ls", "-l"])
    R   N(   t   popR   R3   t   waitR   t   kill(   t	   popenargst   kwargsR   t   p(    (    s+   lib/python2.7/site-packages/subprocess32.pyR6     s    

c          O   sS   t  |  |   } | rO | j d  } | d k r= |  d } n  t | |   n  d S(   sO  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 call function.  Example:

    check_call(["ls", "-l"])
    Rf   i    N(   R6   Rr   R   R   (   R|   R}   t   retcodeR   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR7   '  s    
c          O   s   | j  d d  } d | k r- t d   n  t d t |  |  } y | j d |  \ } } WnE t k
 r | j   | j   \ } } t | j | d |  n X| j	   } | r t
 | | j 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'
    R   R   s3   stdout argument not allowed, it will be overridden.R   N(   Ry   R   RH   R3   R4   t   communicateR   R{   Rf   R#   R   (   R|   R}   R   t   processR   t
   unused_errR   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR8   :  s    
t   CompletedProcessc           B   s/   e  Z d  Z d d d  Z d   Z d   Z RS(   sC  A process that has finished running.
    This is returned by run().
    Attributes:
      args: The list or str args passed to run().
      returncode: The exit code of the process, negative for signals.
      stdout: The standard output (None if not captured).
      stderr: The standard error (None if not captured).
    c         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   Rf   R   R   R   (   R   Rf   R   R   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR
   g  s    			c         C   s   d j  |  j  d j  |  j  g } |  j d  k	 rO | j d j  |  j   n  |  j d  k	 rz | j d j  |  j   n  d j  t |   j d j	 |   S(   Ns	   args={!r}s   returncode={!r}s   stdout={!r}s   stderr={!r}s   {}({})s   , (
   t   formatRf   R   R   R   Rc   R   t   typeR   t   join(   R   Rf   (    (    s+   lib/python2.7/site-packages/subprocess32.pyt   __repr__m  s    c         C   s1   |  j  r- t |  j  |  j |  j |  j   n  d S(   s6   Raise CalledProcessError if the exit code is non-zero.N(   R   R   Rf   R   R   (   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyt   check_returncodev  s    	N(   R   R   R   R   R
   R   R   (    (    (    s+   lib/python2.7/site-packages/subprocess32.pyR   ^  s   		c    	      O   sw  | j  d d  } | j  d d  } | j  d t  } | d k	 rj d | k r] t d   n  t | d <n  t |  |   } z | j   y | j | d | \ } } Wnh t k
 r | j	   | j   \ } } t | j
 | d | d |  n | j	   | j     n X| j   } | rI| rIt | | j
 d | d |  n  Wd | j d d d  Xt | j
 | | |  S(	   s`  Run command with arguments and return a CompletedProcess instance.
    The returned instance will have attributes args, returncode, stdout and
    stderr. By default, stdout and stderr are not captured, and those attributes
    will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.
    If check is True and the exit code was non-zero, it raises a
    CalledProcessError. The CalledProcessError object will have the return code
    in the returncode attribute, and output & stderr attributes if those streams
    were captured.
    If timeout is given, and the process takes too long, a TimeoutExpired
    exception will be raised.
    There is an optional argument "input", allowing you to
    pass a string to the subprocess's stdin.  If you use this argument
    you may not also use the Popen constructor's "stdin" argument, as
    it will be used internally.
    The other arguments are the same as for the Popen constructor.
    If universal_newlines=True is passed, the "input" argument must be a
    string and stdout/stderr in the returned object will be strings rather than
    bytes.
    t   inputR   t   checkt   stdins/   stdin and input arguments may not both be used.R   R   N(   Ry   R   t   FalseRH   R4   R3   t	   __enter__R   R   R{   Rf   Rz   R#   R   t   __exit__R   (	   R|   R}   R   R   R   R   R   R   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyt   run}  s6    



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    (   R   Rc   t   lent   extendR   (   t   seqt   resultt	   needquotet   argt   bs_buft   c(    (    s+   lib/python2.7/site-packages/subprocess32.pyt   list2cmdline  s4    	c           B   s!  e  Z d  e e e e e e e e e e e d  e e f  d  Z d   Z d   Z d   Z	 e
 j e d  Z d   Z d   Z e e d  Z d	   Z d
   Z d   Z e r,d   Z d   Z d   Z d   Z e e j e j e j d  Z e e d  Z d   Z d   Z  d   Z! d   Z" e" Z# n d   Z e$ e% d  rVe& d    Z' n e& d    Z' d   Z( d   Z) d   Z e% j* e% j+ e% j, e% j- e% j. e% j/ d  Z0 e e% j1 e% j2 e% j3 e4 j5 d  Z d   Z6 e e d   Z d!   Z  d"   Z7 d#   Z8 d$   Z! d%   Z" d&   Z# RS('   i    c         C   s~  t    t j   |  _ t |  _ d |  _ t |  _ t	 | t
 t f  sU t d   n  t r | d k	 rv t d   n  | d k	 p | d k	 p | d k	 } | t k r | r t } q t } qY| rY| rYt d   qYn} | t k r t } n  | r#| r#d d l } | j d t  t } n  | d k	 r>t d   n  | d k rYt d	   n  | |  _ d |  _ d |  _ d |  _ d |  _ d |  _ | |  _ |  j | | |  \ } } } } } } t r=| d k rt j | j   d  } n  | d k rt j | j   d  } n  | d k r=t j | j   d  } q=n  | d k rd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  t |  _! t } z^ yG |  j" | | | | | |
 | | | | |	 | | | | | | | |  Wn t }   n XWd | ryxK t# d |  j |  j |  j f  D]( } y | j$   Wqt% k
 rqXqW|  j! syg  } | t& k r| j' |  n  | t& k r| j' |  n  | t& k r| j' |  n  t( |  d  r=| j' |  j)  n  x6 | D]+ } y t j$ |  WqDt% k
 rnqDXqDWqyn  Xd 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/stderriNs   pass_fds overriding close_fds.s2   startupinfo is only supported on Windows platformsi    s4   creationflags is only supported on Windows platformst   wbt   rUt   rbt   _devnull(*   RK   t	   threadingt   Lockt   _waitpid_lockR   t   _child_createdR   t   _inputt   _communication_startedt
   isinstancet   intt   longt	   TypeErrort	   mswindowsRH   t   _PLATFORM_DEFAULT_CLOSE_FDSR0   t   warningst   warnt   RuntimeWarningRf   R   R   R   t   pidR   t   universal_newlinest   _get_handlest   msvcrtt   open_osfhandlet   DetachR.   t   fdopent   _closed_child_pipe_fdst   _execute_childt   filtert   closet   EnvironmentErrorR4   Rc   t   hasattrR   (   R   Rf   t   bufsizet
   executableR   R   R   t
   preexec_fnt	   close_fdst   shellt   cwdRv   R   t   startupinfot   creationflagst   restore_signalst   start_new_sessiont   pass_fdst   any_stdio_setR   t   p2creadt   p2cwritet   c2preadt   c2pwritet   errreadt   errwritet   exception_cleanup_neededt   ft   to_closeR*   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR
     s    														'		(	c         C   s   |  S(   N(    (   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR     s    c         C   sY   |  j  r |  j  j   n  |  j r2 |  j j   n  |  j rK |  j j   n  |  j   d  S(   N(   R   R   R   R   Rz   (   R   R   R   t	   traceback(    (    s+   lib/python2.7/site-packages/subprocess32.pyR     s    			c         C   s(   | j  d d  } | j  d d  } | S(   Ns   
s   
s   (   t   replace(   R   t   data(    (    s+   lib/python2.7/site-packages/subprocess32.pyt   _translate_newlines  s    c         C   sU   t  |  d t  s d  S|  j d |  |  j d  k rQ | d  k	 rQ | j |   n  d  S(   NR   RB   (   Ra   R   RD   R   R   Rc   (   R   t   _maxintRC   (    (    s+   lib/python2.7/site-packages/subprocess32.pyt   __del__  s
    c         C   s4   t  |  d  s- t j t j t j  |  _ n  |  j S(   NR   (   R   R.   t   opent   devnullt   O_RDWRR   (   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyt   _get_devnull  s    c         C   s   | r` y |  j  j |  Wq` t k
 r\ } | j t j k rA q] | j t j k rV q]   q` Xn  y |  j  j   Wn4 t k
 r } | j t j t j f k r q   n Xd  S(   N(   R   t   writeR   Rk   t   EPIPEt   EINVALR   (   R   R   Rn   (    (    s+   lib/python2.7/site-packages/subprocess32.pyt   _stdin_write  s    
c         C   s`  |  j  r | r t d   n  | d k	 r= t j   | } n d } | d k r|  j  r|  j |  j |  j g j d  d k rd } d } |  j r |  j |  nV |  j r t	 |  j j
  } |  j j   n+ |  j r t	 |  j j
  } |  j j   n  |  j   | | f Sz |  j | | |  \ } } Wd t |  _  X|  j d |  j |   } | | f 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).s.   Cannot send input after starting communicationi   NR   (   R   RH   R   t   timeR   R   R   t   countR   Ro   t   readR   Rz   t   _communicateR0   t   _remaining_time(   R   R   R   t   endtimeR   R   t   sts(    (    s+   lib/python2.7/site-packages/subprocess32.pyR     s0    	'			


c         C   s
   |  j    S(   N(   RD   (   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR#     s    c         C   s"   | d k r d S| t j   Sd S(   s5   Convenience for _communicate when computing timeouts.N(   R   R   (   R   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR     s    c         C   s;   | d k r d St j   | k r7 t |  j |   n  d S(   s2   Convenience for checking if a timeout has expired.N(   R   R   R   Rf   (   R   R   t   orig_timeout(    (    s+   lib/python2.7/site-packages/subprocess32.pyt   _check_timeout  s    c         C   s  | d k r( | d k r( | d k r( d Sd \ } } d \ } } d \ } }	 | d k r t j t j  } | d k rt j d d  \ } }
 qn | t k r t j d d  \ } } nZ | t k r t j |  j	    } n6 t
 | t  r t j |  } n t j | j    } |  j |  } | d k rlt j t j  } | d k rt j d d  \ }
 } qn | t k rt j d d  \ } } nZ | t k rt j |  j	    } n6 t
 | t  rt j |  } n t j | j    } |  j |  } | d k rDt j t j  }	 |	 d k rt j d d  \ }
 }	 qn | t k rkt j d d  \ } }	 no | t k r| }	 nZ | t k rt j |  j	    }	 n6 t
 | t  rt j |  }	 n t j | j    }	 |  j |	  }	 | | | | | |	 f S(   s|   Construct and return tuple with IO objects:
            p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
            ii    N(   iiiiii(   ii(   ii(   ii(   R   t   _subprocesst   GetStdHandleR;   t
   CreatePipeR4   t   DEVNULLR   t   get_osfhandleR   R   R   t   filenot   _make_inheritableR<   R=   R5   (   R   R   R   R   R   R   R   R   R   R   t   _(    (    s+   lib/python2.7/site-packages/subprocess32.pyR     s\    $	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+   lib/python2.7/site-packages/subprocess32.pyR   L  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   pathR   t   dirnameR   t   GetModuleFileNamet   existsRE   t   exec_prefixt   RuntimeError(   R   t   w9xpopen(    (    s+   lib/python2.7/site-packages/subprocess32.pyt   _find_w9xpopenS  s    			c      
   C   s?  | s t  d   t | t j  s4 t |  } n  |	 d
 k rL t   }	 n  d | | | f k r |	 j t j	 O_ | |	 _
 | |	 _ | |	 _ n  | r;|	 j t j O_ t j |	 _ t j j d d  } | d d | } t j   d k st j j |  j   d k r;|  j   } d	 | | f } |
 t j O}
 q;n  zj y> t j | | d
 d
 t |  |
 | | |	 	 \ } } } } Wn% t j k
 r} t | j    n XWd
 | d k r| j   n  | d k r| j   n  | d k r| j   n  t  |  d  rt j! |  j"  n  Xt# |  _$ | |  _% | |  _& | j   d
 S(   s$   Execute program (MS Windows version)s"   pass_fds not supported on Windows.it   COMSPECs   cmd.exes    /c s   "%s"l        s   command.coms   "%s" %sNR   ('   t   AssertionErrorR   t   typest   StringTypesR   R   R   R   R   R?   R   R   R   R@   R>   R   R.   Rq   Rr   t
   GetVersionR   t   basenamet   lowerR   R9   t   CreateProcessR   R    R"   t   WindowsErrorRf   t   CloseR   R   R   R0   R   t   _handleR   (   R   Rf   R   R   R   R   R   Rv   R   R   R   R   R   R   R   R   R   R   t   unused_restore_signalst   unused_start_new_sessiont   comspecR   t   hpt   htR   t   tidRn   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR   d  sV    			
			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   RB   t   _WaitForSingleObjectt   _WAIT_OBJECT_0t   _GetExitCodeProcess(    (    s+   lib/python2.7/site-packages/subprocess32.pyRD     s    c         C   s   | d k	 r |  j |  } n  | d k r6 t j } n t | d  } |  j d k r t j |  j |  } | t k r t	 |  j
 |   n  t j |  j  |  _ n  |  j S(   sO   Wait for child process to terminate.  Returns returncode
            attribute.i  N(   R   R   R   t   INFINITER   R   t   WaitForSingleObjectR  t   _WAIT_TIMEOUTR   Rf   t   GetExitCodeProcess(   R   R   R   t   timeout_millisR   (    (    s+   lib/python2.7/site-packages/subprocess32.pyRz     s    	c         C   s!   | j  | j    | j   d  S(   N(   Rc   R   R   (   R   t   fht   buffer(    (    s+   lib/python2.7/site-packages/subprocess32.pyt   _readerthread  s    c         C   s^  |  j  rh t |  d  rh g  |  _ t j d |  j d |  j  |  j f  |  _ t |  j _ |  j j	   n  |  j
 r t |  d  r g  |  _ t j d |  j d |  j
 |  j f  |  _ t |  j _ |  j j	   n  |  j r |  j |  n  |  j  d  k	 r8|  j j |  j |   |  j j   r8t |  j |   q8n  |  j
 d  k	 r|  j j |  j |   |  j j   rt |  j |   qn  d  } d  } |  j  r|  j } |  j  j   n  |  j
 r|  j } |  j
 j   n  | d  k	 r| d } n  | d  k	 r	| d } n  |  j rTt t d  rT| r9|  j |  } n  | rT|  j |  } qTn  | | f S(   Nt   _stdout_bufft   targetRf   t   _stderr_buffi    t   newlines(   R   R   R  R   t   ThreadR  t   stdout_threadR0   t   daemont   startR   R  t   stderr_threadR   R   R   R   R   t   isAliveR   Rf   R   R   t   fileR   (   R   R   R   R   R   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR     sP    							c         C   s   |  j  d k	 r d S| t j k r/ |  j   n` | t j k rW t j |  j t j  n8 | t j	 k r t j |  j t j	  n t
 d |   d S(   s   Send a signal to the process.Ns   Unsupported signal: %s(   R   R   t   signalt   SIGTERMt	   terminatet   CTRL_C_EVENTR.   R{   R   t   CTRL_BREAK_EVENTRH   (   R   t   sig(    (    s+   lib/python2.7/site-packages/subprocess32.pyt   send_signal  s    c         C   s*   |  j  d k	 r d St j |  j d  d S(   s   Terminates the process.Ni   (   R   R   R   t   TerminateProcessR  (   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR%  +  s    c   
      C   s  d \ } } d \ } } d \ } }	 | d k r3 n] | t k rQ t   \ } } n? | t k rl |  j   } n$ t | t  r | } n | j   } | d k r n] | t k r t   \ } } n? | t k r |  j   } n$ t | t  r | } n | j   } | d k rn | t k r)t   \ } }	 nr | t k r\| d k rJ| }	 qt	 j
 j   }	 n? | t k rw|  j   }	 n$ t | t  r| }	 n | j   }	 | | | | | |	 f S(   s|   Construct and return tuple with IO objects:
            p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
            i(   ii(   ii(   iiN(   R   R4   R2   R   R   R   R   R   R5   RE   t
   __stdout__(
   R   R   R   R   R   R   R   R   R   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR   8  sJ    				t
   closerangec         C   s   t  j |  |  d  S(   N(   R.   R,  (   t   fd_lowt   fd_high(    (    s+   lib/python2.7/site-packages/subprocess32.pyt   _closerangeo  s    c         C   sq   xj t  |  |  D]Y } xP t rh y t j |  Wq t t f k
 rd } | j t j k r` q n  Pq Xq Wq Wd  S(   N(   t   xrangeR0   R.   R   Rj   R!   Rk   Rl   (   R-  R.  R*   Rn   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR/  s  s    	c         C   s(   |  j  d |  |  j  | d t  d  S(   Ni   i   (   R/  t   MAXFD(   R   t   but(    (    s+   lib/python2.7/site-packages/subprocess32.pyt
   _close_fds  s    c         C   sc   d } x7 | D]/ } | | k r |  j  | |  | d } q q W| t k r_ |  j  | t  n  d  S(   Ni   i   (   R/  R1  (   R   t   fds_to_keept   start_fdR*   (    (    s+   lib/python2.7/site-packages/subprocess32.pyt   _close_all_but_a_sorted_few_fds  s    c   2         s+  t  | t j  r | g } n t |  } | rV d d g | }   rV   | d <qV n    d k ro | d   n    } t   \ } } zzt rt j     f d    | d k	 r g  | j	   D]& \ } }  |  d  |  ^ q } n d } t
 j j    r    f } n> t |  }   f d   | D } t  f d   | D  } t |  } | j |  t j | | | t |  | | | | | | | | | | | | |  |  _ t |  _ not j   } t j   y t
 j   |  _ Wn | r
t j   n    n Xt |  _ |  j d k r$t } yW| d k rNt
 j |  n  | d k rjt
 j |  n  | d k rt
 j |  n  t
 j |  | d k rt
 j |  } n  | d k s| d	 k rt
 j |  } n  d
   } | | d  | | d	  | | d  t   }  xL | | | g D]; }! |! d k r$|! |  k r$t
 j |!  |  j |!  q$q$W| d k	 rt
 j |  n  | rd }" x? |" D]4 }# t t  |#  rt  j  t! t  |#  t  j"  qqWn  | rt t
 d  rt
 j#   n  t } | r|   n  | rS| r@t |  } | j |  |  j$ t |   qS|  j% d |  n  | d k rrt
 j&   |  n t
 j'   | |  Wn yp t j(   d  \ }$ }% t  |% t)  r|% j* }& n d }& | sd }% n  d |$ j+ |& |% f }' t
 j, | |'  Wqt- k
 rqXn Xt
 j. d  n  | r7t j   n  Wd t
 j |  Xt! |  d d  }( | d k r| d k r| |( k rt
 j |  n  | d k r| d k r| |( k rt
 j |  n  | d k r| d k r| |( k rt
 j |  n  |( d k	 rt
 j |(  n  t |  _/ d }) xF t rjt0 t
 j1 | d  }* |) |* 7}) |* sct2 |)  d k r%Pq%q%WWd t
 j |  X|) d k r'y t0 t
 j3 |  j d  Wn+ t) k
 r}+ |+ j* t* j4 k r  qn Xy |) j5 d d  \ }, }- }. Wn- t6 k
 rd }, d }- d t7 |)  }. n Xt! t8 |, t9  }/ t: |/ t)  r|- rt; |- d  }& |. d k }0 |0 rqd }. n  |& d k rt
 j< |&  }. |& t* j= k r|0 r|. d t7 |  7}. q|. d t7 |  7}. qn  |/ |& |.   n  y |/ |.  }1 Wn' t- k
 rt9 d |/ |. f  }1 n X|1  n  d S(    s   Execute program (POSIX version)s   /bin/shs   -ci    c            s'   t  |  t  r |  S|  j   d  Sd S(   s+   Encode s for use in the env, fs or cmdline.t   strictN(   R   t   strt   encode(   RR   (   t   fs_encoding(    s+   lib/python2.7/site-packages/subprocess32.pyt	   fs_encode  s    t   =c         3   s$   |  ] } t  j j |    Vq d  S(   N(   R.   R   R   (   t   .0t   dir(   R   (    s+   lib/python2.7/site-packages/subprocess32.pys	   <genexpr>  s   c         3   s   |  ] }   |  Vq d  S(   N(    (   R=  t   exe(   R;  (    s+   lib/python2.7/site-packages/subprocess32.pys	   <genexpr>  s   ii   c         S   s?   |  | k r t  |  t  n |  d k r; t j |  |  n  d  S(   Ni(   R-   R   R.   t   dup2(   t   aRZ   (    (    s+   lib/python2.7/site-packages/subprocess32.pyt   _dup2  s    i   t   SIGPIPEt   SIGXFZt   SIGXFSZt   setsidR2  t   noexecs   %s:%x:%si   NR   R   iP  t   :R   t   0s   Bad exception data from child: i   s   : sD   Could not re-raise %r exception from the child with error message %r(   RC  RD  RE  (>   R   R   R   t   listR   R2   t   _posixsubprocessRE   t   getfilesystemencodingR`   R.   R   R   Rw   t   tuplet   sett   addt	   fork_exect   sortedR   R0   R   t   gct	   isenabledt   disablet   forkt   enableR   R   t   dupt   chdirR   R#  Ra   t   SIG_DFLRF  R6  R3  t   execvpt   execvpet   exc_infoRj   Rk   R   R   t	   Exceptiont   _exitR   Ro   R   R   t   waitpidt   ECHILDRt   RH   t   reprt
   exceptionsR   t
   issubclassR   t   strerrort   ENOENT(2   R   Rf   R   R   R   R   R   Rv   R   R   R   R   R   R   R   R   R   R   R   R   t   orig_executablet   errpipe_readt   errpipe_writet   kRX   t   env_listt   executable_listt	   path_listR4  t   gc_was_enabledt   reached_preexecRB  t   closedR*   t   signalsR(  t   exc_typet	   exc_valuet	   errno_numt   messaget
   devnull_fdt   errpipe_datat   partRn   t   exception_namet	   hex_errnot   err_msgt   child_exception_typet   child_exec_never_calledt	   exception(    (   R   R;  R:  s+   lib/python2.7/site-packages/subprocess32.pyR     s@   	9

			
		$$$		

	c         C   sl   | |  r | |  |  _  nI | |  r= | |  |  _  n+ | |  r\ | |  |  _  n t d   d S(   s:   All callers to this function MUST hold self._waitpid_lock.s   Unknown child exit status!N(   R   R   (   R   R   t   _WIFSIGNALEDt	   _WTERMSIGt
   _WIFEXITEDt   _WEXITSTATUSt   _WIFSTOPPEDt	   _WSTOPSIG(    (    s+   lib/python2.7/site-packages/subprocess32.pyt   _handle_exitstatus  s    c   	      C   s   |  j  d k r |  j j t  s% d Sz yQ |  j  d k	 rA |  j  S| |  j |  \ } } | |  j k rx |  j |  n  WnF | k
 r } | d k	 r | |  _  q | j | k r d |  _  q n XWd |  j j   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   R   t   acquireR   R   R  Rk   t   release(	   R   RB   t   _waitpidt   _WNOHANGt	   _os_errort   _ECHILDR   R   Rn   (    (    s+   lib/python2.7/site-packages/subprocess32.pyRD     s"    	c         C   si   y" t  t j |  j |  \ } } Wn: t k
 r^ } | j t j k rL   n  |  j } d } n X| | f S(   s:   All callers to this function MUST hold self._waitpid_lock.i    (   Ro   R.   R_  R   Rj   Rk   R`  (   R   t
   wait_flagsR   R   Rn   (    (    s+   lib/python2.7/site-packages/subprocess32.pyt	   _try_wait  s    "	
c         C   s  |  j  d k	 r |  j  S| d k	 s. | d k	 rn | d k rM t j   | } qn | d k rn |  j |  } qn n  | d k	 ryd } xut ru|  j j t  rzp |  j  d k	 r Pn  |  j t	 j
  \ } } | |  j k s | d k s t  | |  j k r
|  j |  Pn  Wd |  j j   Xn  |  j |  } | d k rOt |  j |   n  t | d | d  } t j |  q Wn x| |  j  d k r|  j j   zK |  j  d k	 rPn  |  j d  \ } } | |  j k r|  j |  n  Wd |  j j   Xq|W|  j  S(   sO   Wait for child process to terminate.  Returns returncode
            attribute.gMb@?i    Ni   g?(   R   R   R   R   R0   R   R  R   R  R.   t   WNOHANGR   R   R  R  R   Rf   t   mint   sleep(   R   R   R   t   delayR   R   t	   remaining(    (    s+   lib/python2.7/site-packages/subprocess32.pyRz     sF    	!c         C   s"  |  j  r9 |  j r9 |  j  j   | s9 |  j  j   q9 n  t r] |  j | | |  \ } } n |  j | | |  \ } } |  j d |  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  | | f S(   NR   R   R  (   R   R   t   flushR   t	   _has_pollt   _communicate_with_pollt   _communicate_with_selectRz   R   R   R   R   R   R"  R   (   R   R   R   R   R   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR     s(    c            s  d  } d  }  j s! i   _ n  t j        f d   }    f d   }  j rv | rv |  j t j  n   j s i   _  j r g   j  j j	   <n   j
 r g   j  j
 j	   <q n  t j t j B}  j r|  j |   j  j j	   } n   j
 rC|  j
 |   j  j
 j	   } n   j r j d  k rd  _ |  _  j rt  j t  r j j  j j pt j     _ qn  xB j ry   j  j |   }	 Wn5 t j k
 r}
 |
 j d t j k rqn    n X j | |  x |	 D] \ } } | t j @r j  j  j t !}  j t j | |  7_  j t  j  k r| |  qq,| | @rt j  | d  } | s| |  n   j | j! |  q,| |  q,WqW| | f S(   Nc            s-     j  |  j   |  |   j |  j   <d  S(   N(   t   registerR   t   _fd2file(   t   file_objt	   eventmask(   t   pollerR   (    s+   lib/python2.7/site-packages/subprocess32.pyt   register_and_append7  s    c            s2     j  |    j |  j    j j |   d  S(   N(   t
   unregisterR  R   Ry   (   R*   (   R  R   (    s+   lib/python2.7/site-packages/subprocess32.pyt   close_unregister_and_remove;  s    i    i   ("   R   R   R  t   selectR#   R   t   POLLOUTt
   _fd2outputR   R   R   t   POLLINt   POLLPRIR   t   _input_offsetR   R   t   unicodeR9  t   encodingRE   t   getdefaultencodingR   R"   Rf   Rk   Rl   R   t	   _PIPE_BUFR.   R   R   R   Rc   (   R   R   R   R   R   R   R  R  t   select_POLLIN_POLLPRIt   readyRn   R*   t   modet   chunkR   (    (   R  R   s+   lib/python2.7/site-packages/subprocess32.pyR  /  sd    										$
c         C   s  |  j  s g  |  _ g  |  _ |  j r@ | r@ |  j j |  j  n  |  j r_ |  j j |  j  n  |  j r |  j j |  j  q n  |  j r |  j d  k r d |  _	 | |  _ |  j
 r t |  j t  r |  j j |  j j p t j    |  _ q n  d  } d  } |  j r)|  j  sg  |  _ n  |  j } n  |  j rS|  j  sGg  |  _ n  |  j } n  xn|  j sh|  j ry4 t j |  j |  j g  |  j |   \ } } } Wn5 t j k
 r}	 |	 j d t j k rqVn    n X| p| p| st |  j |   n  |  j | |  |  j | k r|  j |  j	 |  j	 t !}
 y t j |  j j   |
  } WnK t k
 r}	 |	 j t j  k r|  j j! |  j  |  j j"   q  qX|  j	 | 7_	 |  j	 t# |  j  k r|  j j"   |  j j! |  j  qn  |  j | k rWt j$ |  j j   d  } | d k rG|  j j"   |  j j! |  j  n  | j |  n  |  j | k rVt j$ |  j j   d  } | d k r|  j j"   |  j j! |  j  n  | j |  qVqVW| | f S(   Ni    i   R   (%   R   t	   _read_sett
   _write_setR   Rc   R   R   R   R   R  R   R   R  R9  R  RE   R  R  R  R  R   R"   Rf   Rk   Rl   R   R   R  R.   R   R   R   R   RG   R   R   R   (   R   R   R   R   R   R   t   rlistt   wlistt   xlistRn   R  t   bytes_writtenR   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR  x  s~    								$				c         C   s)   |  j  d k r% t j |  j |  n  d S(   s)   Send a signal to the process
            N(   R   R   R.   R{   R   (   R   R(  (    (    s+   lib/python2.7/site-packages/subprocess32.pyR)    s    c         C   s   |  j  t j  d S(   s/   Terminate the process with SIGTERM
            N(   R)  R#  R$  (   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR%    s    c         C   s   |  j  t j  d S(   s*   Kill the process with SIGKILL
            N(   R)  R#  t   SIGKILL(   R   (    (    s+   lib/python2.7/site-packages/subprocess32.pyR{     s    (9   R   R   R   R   R   R0   R
   R   R   R   RE   RF   RC   R   R   R   R   R#   R   R   R   R   R   R   R   R   R  t   WAIT_OBJECT_0R  RD   Rz   R  R   R)  R%  R{   R   R.   t   staticmethodR/  R3  R6  t   WIFSIGNALEDt   WTERMSIGt	   WIFEXITEDt   WEXITSTATUSt
   WIFSTOPPEDt   WSTOPSIGR  R_  R  R"   Rk   R`  R  R  R  (    (    (    s+   lib/python2.7/site-packages/subprocess32.pyR3     sl   			
			-				?			S		>				6			 	#	4	$	I	Q		(    (    (G   R   RE   t   platformR   R.   Rk   Rb  R   R   R   RR  R#  R]  R   R   R   R   R   R   R   R    R  R   R  R&   t   picklet   _posixsubprocess32RK  t   ImportErrorR   R   R   R   t   dummy_threadingRa   R  R)   R-   t   cloexec_pipeR2   t   __all__R9   R:   R;   R<   R=   R>   R?   R@   R  R   t   sysconfR1  RC   RK   R4   R5   R   Ri   Ro   Rw   Rx   R6   R7   R8   t   objectR   R   R   R   R3   (    (    (    s+   lib/python2.7/site-packages/subprocess32.pyt   <module>&   s   %			:
			
			$	4	F	