add-determinism 0.7.3

RPM buildroot helper to strip nondeterministic bits in files
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
a

Z��^!Bc@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
Z
zddlZWney�dZYn0zddlZWney�dZYn0gd�ZzddlZddlZdZWn.ey�dZddlZddlZddlZYn`0ddlmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*e�+gd��Gd	d
�d
e,�Z-Gdd�de-�Z.Gd
d�de-�Z/e�r�Gdd�d�Z0Gdd�de1�Z2n&e3edd�Z4e5ed��r�ej6Z7nej8Z7e�r�dZ9dd�Z:ngZ9dd�Z:dZ;dZ<dZ=dd�Z>dd�Z?dd �d!d"�Z@d#d$�ZAdd �d%d&�ZBGd'd(�d(eC�ZDddddd)�d*d+�ZEd,d-�ZFd.d/�ZGd0d1�ZHd2d3�ZIeI�ZJGd4d5�d5eC�ZKdS)6a�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
getoutput(...): Runs a command in the shell, waits for it to complete,
    then returns the output
getstatusoutput(...): Runs a command in the shell, waits for it to complete,
    then returns a (exitcode, output) tuple
�N)�	monotonic)�Popen�PIPE�STDOUT�call�
check_call�getstatusoutput�	getoutput�check_output�run�CalledProcessError�DEVNULL�SubprocessError�TimeoutExpired�CompletedProcessTF)�CREATE_NEW_CONSOLE�CREATE_NEW_PROCESS_GROUP�STD_INPUT_HANDLE�STD_OUTPUT_HANDLE�STD_ERROR_HANDLE�SW_HIDE�STARTF_USESTDHANDLES�STARTF_USESHOWWINDOW�ABOVE_NORMAL_PRIORITY_CLASS�BELOW_NORMAL_PRIORITY_CLASS�HIGH_PRIORITY_CLASS�IDLE_PRIORITY_CLASS�NORMAL_PRIORITY_CLASS�REALTIME_PRIORITY_CLASS�CREATE_NO_WINDOW�DETACHED_PROCESS�CREATE_DEFAULT_ERROR_MODE�CREATE_BREAKAWAY_FROM_JOB)rrrrrrrr�STARTUPINFOrrrrrrrrr r!c@seZdZdS)r
N)�__name__�
__module__�__qualname__�r&r&�"/usr/lib64/python3.9/subprocess.pyr
i�r
c@�<eZdZdZd
dd�Zdd�Zedd��Zejd	d��ZdS)rz�Raised when run() is called with check=True and the process
    returns a non-zero exit status.

    Attributes:
      cmd, returncode, stdout, stderr, output
    NcC�||_||_||_||_dS�N)�
returncode�cmd�output�stderr)�selfr,r-r.r/r&r&r'�__init__s�zCalledProcessError.__init__cCsf|jrR|jdkrRzd|jt�|j�fWStyNd|j|jfYS0nd|j|jfSdS)NrzCommand '%s' died with %r.z)Command '%s' died with unknown signal %d.z.Command '%s' returned non-zero exit status %d.)r,r-�signalZSignals�
ValueError�r0r&r&r'�__str__ys�
��zCalledProcessError.__str__cC�|jS)z+Alias for output attribute, to match stderr�r.r5r&r&r'�stdout��zCalledProcessError.stdoutcC�
||_dSr+r8�r0�valuer&r&r'r9���NN�	r#r$r%�__doc__r1r6�propertyr9�setterr&r&r&r'rls

rc@r))rz�This exception is raised when the timeout expires while waiting for a
    child process.

    Attributes:
        cmd, output, stdout, stderr, timeout
    NcCr*r+)r-�timeoutr.r/)r0r-rDr.r/r&r&r'r1�r2zTimeoutExpired.__init__cCsd|j|jfS)Nz'Command '%s' timed out after %s seconds)r-rDr5r&r&r'r6�s
�zTimeoutExpired.__str__cCr7r+r8r5r&r&r'r9��zTimeoutExpired.stdoutcCr;r+r8r<r&r&r'r9�r>r?r@r&r&r&r'r�s

rc@s,eZdZddddddd�dd�Zdd�ZdS)r"rN��dwFlags�	hStdInput�
hStdOutput�	hStdError�wShowWindow�lpAttributeListcCs0||_||_||_||_||_|p(dgi|_dS)N�handle_listrF)r0rGrHrIrJrKrLr&r&r'r1�szSTARTUPINFO.__init__cCs@|j��}d|vr"t|d�|d<t|j|j|j|j|j|d�S)NrMrF)	rL�copy�listr"rGrHrIrJrK)r0Z	attr_listr&r&r'rN�s
�zSTARTUPINFO.copy)r#r$r%r1rNr&r&r&r'r"�s�	r"c@s2eZdZdZejfdd�Zdd�Zdd�ZeZ	dS)	�HandleFcCs|jsd|_||�dS)NT)�closed)r0�CloseHandler&r&r'�Close�szHandle.ClosecCs |jsd|_t|�Std��dS)NTzalready closed)rQ�intr4r5r&r&r'�Detach�sz
Handle.DetachcCsd|jjt|�fS)Nz%s(%d))�	__class__r#rTr5r&r&r'�__repr__��zHandle.__repr__N)
r#r$r%rQ�_winapirRrSrUrW�__del__r&r&r&r'rP�s
rPZPIPE_BUFi�PollSelectorcCsdSr+r&r&r&r&r'�_cleanup�rXr\c	CsZtdurdStdd�D]<}|jtjd�}|durzt�|�WqtyRYq0qdS)N��
_deadstate)�_active�_internal_poll�sys�maxsize�remover4)ZinstZresr&r&r'r\�s�����i����i����cCs*g}tjj}|dkr&|�dd|�|S)zgReturn a list of command-line arguments reproducing the current
    optimization settings in sys.flags.r�-ZO)ra�flagsZoptimize�append)�argsr=r&r&r'�"_optim_args_from_interpreter_flagss
ricCsVddddddd�}t�}|��D].\}}ttj|�}|dkr |�d	||�q tjjrd|�d
�n$tjjrv|�d�tjjr�|�d�tj	d
d
�}tjj
}ttdi�}d|v}|dkr�|�d�n|r�|�d�|r�|�d�|D]}|�d|�q�|�r
|�d�dD]B}||v�r||}	|	du�r4|}
nd||	f}
|�d|
f��q|S)z}Return a list of command-line arguments reproducing the current
    settings in sys.flags, sys.warnoptions and sys._xoptions.ZdZBZS�vZbZq)ZdebugZdont_write_bytecodeZno_siteZverbose�
bytes_warningZquietrrez-Iz-Ez-sNZ	_xoptions�dev�zerror::BytesWarningzdefault::BytesWarningZdefaultz-W)�-Xrl)ZfaulthandlerZtracemallocZ
importtimeZshowrefcountZutf8Z	oldparserTz%s=%srn)
ri�items�getattrrarfrgZisolatedZignore_environmentZno_user_siteZwarnoptionsrkrc�extend)Zflag_opt_maprhZflagZoptrjZwarnoptsrkZxoptionsZdev_moder=�argr&r&r'�_args_from_interpreter_flagssP�






rs�rDcOsft|i|���D}z|j|d�WWd�S|���Yn0Wd�n1sX0YdS)z�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"])
    rtN)r�wait�kill)rD�	popenargs�kwargsZpr&r&r'rUsrcOs:t|i|��}|r6|�d�}|dur,|d}t||��dS)aORun 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"])
    rhNr)r�getr)rwrx�retcoder-r&r&r'rfs


rcOsTd|vrtd��d|vr<|ddur<|�dd�r4dnd|d<t|t|d	d
�|��jS)aRun command with arguments and return its output.

    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"])
    b'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)
    b'ls: non_existent_file: No such file or directory\n'

    There is an additional 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 too will be used internally.  Example:

    >>> check_output(["sed", "-e", "s/foo/bar/"],
    ...              input=b"when in the course of fooman events\n")
    b'when in the course of barman events\n'

    By default, all communication is in bytes, and therefore any "input"
    should be bytes, and the return value will be bytes.  If in text mode,
    any "input" should be a string, and the return value will be a string
    decoded according to locale encoding, or by "encoding" if set. Text mode
    is triggered by setting any of text, encoding, errors or universal_newlines.
    r9z3stdout argument not allowed, it will be overridden.�inputN�universal_newlinesF�r(T)r9rD�check)r4ryr
rr9)rDrwrxr&r&r'r	ys#�r	c@s4eZdZdZd	dd�Zdd�Zeej�Z	dd�Z
dS)
raEA 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).
    NcCr*r+)rhr,r9r/)r0rhr,r9r/r&r&r'r1�r2zCompletedProcess.__init__cCshd�|j�d�|j�g}|jdur4|�d�|j��|jdurP|�d�|j��d�t|�jd�|��S)Nz	args={!r}zreturncode={!r}zstdout={!r}zstderr={!r}z{}({})z, )	�formatrhr,r9rgr/�typer#�join)r0rhr&r&r'rW�s

�

zCompletedProcess.__repr__cCs |jrt|j|j|j|j��dS)z6Raise CalledProcessError if the exit code is non-zero.N)r,rrhr9r/r5r&r&r'�check_returncode�s�z!CompletedProcess.check_returncoder?)r#r$r%rAr1rW�classmethod�types�GenericAlias�__class_getitem__r�r&r&r&r'r�s


	
r)r{�capture_outputrDr~cOs<|dur&|�d�durtd��t|d<|r^|�d�dusF|�d�durNtd��t|d<t|d<t|i|����}z|j||d�\}}Wn`ty�}	z4|��tr�|��\|	_|	_	n|�
��WYd}	~	nd}	~	0|���Yn0|��}
|�r|
�rt|
|j
||d��Wd�n1�s"0Yt|j
|
||�S)	aKRun 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 bytes or 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.

    By default, all communication is in bytes, and therefore any "input" should
    be bytes, and the stdout and stderr will be bytes. If in text mode, any
    "input" should be a string, and stdout and stderr will be strings decoded
    according to locale encoding, or by "encoding" if set. Text mode is
    triggered by setting any of text, encoding, errors or universal_newlines.

    The other arguments are the same as for the Popen constructor.
    N�stdinz/stdin and input arguments may not both be used.r9r/z@stdout and stderr arguments may not be used with capture_output.rt�r.r/)ryr4rr�communicaterrv�
_mswindowsr9r/ru�pollrrhr)r{r�rDr~rwrxZprocessr9r/�excrzr&r&r'r
�s6�&r
cCs�g}d}ttj|�D]�}g}|r*|�d�d|vp>d|vp>|}|rN|�d�|D]b}|dkrj|�|�qR|dkr�|�dt|�d�g}|�d�qR|r�|�|�g}|�|�qR|r�|�|�|r|�|�|�d�qd�|�S)	a�
    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.
    Fz z	z"z\�z\"r})�map�os�fsdecoderg�lenrqr�)Zseq�resultZ	needquoterrZbs_bufZcr&r&r'�list2cmdlines4




r�c
Csnzt|ddtd�}d}Wn0tyH}z|j}|j}WYd}~n
d}~00|dd�dkrf|dd�}||fS)a�Return (exitcode, output) of executing cmd in a shell.

    Execute the string 'cmd' in a shell with 'check_output' and
    return a 2-tuple (status, output). The locale encoding is used
    to decode the output and process newlines.

    A trailing newline is stripped from the output.
    The exit status for the command can be interpreted
    according to the rules for the function 'wait'. Example:

    >>> import subprocess
    >>> subprocess.getstatusoutput('ls /bin/ls')
    (0, '/bin/ls')
    >>> subprocess.getstatusoutput('cat /bin/junk')
    (1, 'cat: /bin/junk: No such file or directory')
    >>> subprocess.getstatusoutput('/bin/junk')
    (127, 'sh: /bin/junk: not found')
    >>> subprocess.getstatusoutput('/bin/kill $$')
    (-15, '')
    T)�shell�textr/rNrd�
)r	rrr.r,)r-�dataZexitcodeZexr&r&r'rZsrcCst|�dS)a%Return output (stdout or stderr) of executing cmd in a shell.

    Like getstatusoutput(), except the exit status is ignored and the return
    value is a string containing the command's output.  Example:

    >>> import subprocess
    >>> subprocess.getoutput('ls /bin/ls')
    '/bin/ls'
    rm)r)r-r&r&r'rys
rc
Cs�tsttd�sdStjdkr dSzjt�d�}|jdd�}t|�dkrHt�|d	}t	t
t|d�d
���}tjdkr�|dkr�|d
kr�WdSWnttt
fy�Yn0dS)a�Check if posix_spawn() can be used for subprocess.

    subprocess requires a posix_spawn() implementation that properly reports
    errors to the parent process, & sets errno on the following failures:

    * Process attribute actions failed.
    * File actions failed.
    * exec() failed.

    Prefer an implementation which can use vfork() in some cases for best
    performance.
    �posix_spawnFZdarwinTZCS_GNU_LIBC_VERSIONrm)Zmaxsplitr�rZ.ZlinuxZglibc)r�i)r��hasattrr�raZplatformZconfstr�splitr�r4�tupler�rTZAttributeError�OSError)ZverZpartsZlibcZversionr&r&r'�_use_posix_spawn�s 



r�c@s�eZdZdZdZdMdddddddd�d	d
�Zdd�Zeej	�Z
ed
d��Zej
dd��Zdd�Zdd�Zdd�Zejejfdd�Zdd�Zdd�ZdNdd�Zdd�Zd d!�ZdOd"d#�ZdPd$d%�Zd&d'�Ze�r4d(d)�Zd*d+�Z d,d-�Z!d.d/�Z"de#j$e#j%e#j&fd0d1�Z'd2d3�Z(d4d5�Z)d6d7�Z*d8d9�Z+d:d;�Z,e,Z-n~d<d)�Zd=d>�Z.d?d/�Z"e/j0e/j1e/j2fd@dA�Z3de/j4e/j5e6j7fdBd1�Z'dCdD�Z8dEd3�Z(dFd7�Z*dGdH�Z9dId9�Z+dJd;�Z,dKdL�Z-dS)QraP 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.

      text: If true, decode stdin, stdout and stderr using the given encoding
          (if set) or the system default otherwise.

      universal_newlines: Alias of text, provided for backwards compatibility.

      startupinfo and creationflags (Windows only)

      restore_signals (POSIX only)

      start_new_session (POSIX only)

      group (POSIX only)

      extra_groups (POSIX only)

      user (POSIX only)

      umask (POSIX only)

      pass_fds (POSIX only)

      encoding and errors: Text mode encoding and error handling to use for
          file objects stdin, stdout and stderr.

    Attributes:
        stdin, stdout, stderr, pid, returncode
    FrdNTrr&)�user�group�extra_groups�encoding�errorsr��umaskc(CsFt�t��|_d|_d|_|dur(d}t|t�s:td��t	rP|dur�t
d��n8|rh|sht�dt
�d}|
durxt
d��|d	kr�t
d
��||_d|_d|_d|_d|_d|_||_||_|dur�|dur�t|�t|�kr�td��|�|||�\}}}}}}t	�rN|dk�rt�|��d	�}|dk�r4t�|��d	�}|dk�rNt�|��d	�}|�pb|�pb|�pb||_d|_d|_|j�r�|d
k�r�d}d}nd}d} |du�rtt d��s�t
d��nPt|t!��r�t"du�r�t
d��t"�#|�j$} n$t|t��r�|} ntd�%t&|����| d	k�rt
d| ����d}!|du�r�tt d��sBt
d��nt|t!��rVt
d��g}!|D]b}"t|"t!��r�t"du�r�t
d��|!�'t"�#|"�j$�n*t|"t��r�|!�'|"�ntd�%t&|"�����q^|!D]}#|#d	k�r�t
d|#�����q�d}$|du�rhtt d��s
t
d��nFt|t!��r6t(du�r(t
d��t(�)|�j*}$nt|t��rH|}$ntd��|$d	k�rht
d|$����z�|dk�r�t+�,|d|�|_|j�r�t+j-|jd|||d�|_|dk�r�t+�,|d|�|_|j�r�t+j-|j||d �|_|dk�rt+�,|d|�|_|j�rt+j-|j||d �|_|�.||||||
||
||	|||||||| |!|$||�Wn�t/d|j|j|jf�D](}%z|%�0�Wnt1�y�Yn0�qd|j�s:g}&|t2k�r�|&�'|�|t2k�r�|&�'|�|t2k�r�|&�'|�t|d!��r�|&�'|j3�|&D]F}'z*t	�rt|'t4��r|'�5�n
t �0|'�Wnt1�y4Yn0�q�Yn0dS)"zCreate new Popen instance.NFrdzbufsize must be an integerz0preexec_fn is not supported on Windows platformszpass_fds overriding close_fds.Tz2startupinfo is only supported on Windows platformsrz4creationflags is only supported on Windows platformszlCannot disambiguate when both text and universal_newlines are supplied but different. Pass one or the other.g�?rmZsetregidz>The 'group' parameter is not supported on the current platformzHThe group parameter cannot be a string on systems without the grp modulez,Group must be a string or an integer, not {}z!Group ID cannot be negative, got Z	setgroupszEThe 'extra_groups' parameter is not supported on the current platformz#Groups must be a list, not a stringzIItems in extra_groups cannot be strings on systems without the grp modulez9Items in extra_groups must be a string or integer, not {}Zsetreuidz=The 'user' parameter is not supported on the current platformzGThe user parameter cannot be a string on systems without the pwd modulez#User must be a string or an integerz User ID cannot be negative, got Zwb)Z
write_through�line_bufferingr�r�Zrb)r�r��_devnull)6r\�	threadingZLock�
_waitpid_lock�_input�_communication_started�
isinstancerT�	TypeErrorr�r4�warnings�warn�RuntimeWarningrhr�r9r/�pidr,r�r��boolr
�_get_handles�msvcrtZopen_osfhandlerU�	text_mode�_sigint_wait_secs�_closed_child_pipe_fdsr�r��str�grpZgetgrnamZgr_gidrr�rg�pwdZgetpwnamZpw_uid�io�openZ
TextIOWrapper�_execute_childZfilter�closer�rr�rPrS)(r0rhZbufsize�
executabler�r9r/�
preexec_fn�	close_fdsr��cwd�envr|�startupinfo�
creationflags�restore_signals�start_new_session�pass_fdsr�r�r�r�r�r�r��p2cread�p2cwrite�c2pread�c2pwrite�errread�errwriter��gid�gidsZextra_groupZ	gid_check�uidZfZto_close�fdr&r&r'r1�s.	


��






�



�







�
�
��	








zPopen.__init__cCsDd|jj�d|j�dt|j��d�}t|�dkr@|dd�d}|S)Nz<z: returncode: z args: z>iPiLz...>)rVr#r,rOrhr�)r0Zobj_reprr&r&r'rW�s����zPopen.__repr__cCr7r+)r�r5r&r&r'r|�r>zPopen.universal_newlinescCst|�|_dSr+)r�r�)r0r|r&r&r'r|�rEcCs |�||�}|�dd��dd�S)Nz
r�z
)�decodeZreplace)r0r�r�r�r&r&r'�_translate_newlines�szPopen._translate_newlinescCs|Sr+r&r5r&r&r'�	__enter__�rXzPopen.__enter__cCs�|jr|j��|jr |j��z^|jr2|j��W|tkrv|jdkrlz|j|jd�WntyjYn0d|_dS|��nT|tkr�|jdkr�z|j|jd�Wnty�Yn0d|_YdS|��0dS)Nrrt)	r9r�r/r��KeyboardInterruptr��_waitrru)r0Zexc_typer=Z	tracebackr&r&r'�__exit__�s2



�
zPopen.__exit__cCsT|js
dS|jdur(|d|jt|d�|j|d�|jdurPtdurPt�|�dS)Nzsubprocess %s is still running)Zsourcer])�_child_createdr,r�ZResourceWarningr`r_rg)r0Z_maxsizeZ_warnr&r&r'rZs

�z
Popen.__del__cCs"t|d�st�tjtj�|_|jS)Nr�)r�r�r�ZdevnullZO_RDWRr�r5r&r&r'�_get_devnull s
zPopen._get_devnullc
Cs�|rZz|j�|�WnDty&Yn4tyX}z|jtjkrBn�WYd}~n
d}~00z|j��WnDtyzYn4ty�}z|jtjkr�n�WYd}~n
d}~00dSr+)r��write�BrokenPipeErrorr��errnoZEINVALr�)r0r{r�r&r&r'�_stdin_write%s"zPopen._stdin_writecCsV|jr|rtd��|dur�|js�|j|j|jg�d�dkr�d}d}|jrT|�|�n6|jrp|j��}|j��n|jr�|j��}|j��|�	�n�|dur�t
�|}nd}z�z|�|||�\}}Wndt�y(|dur�t
|j|�|��}n|j}d|_z|j|d�Wnt�y Yn0�Yn0Wd|_nd|_0|j	|�|�d�}||fS)a9Interact with process: Send data to stdin and close it.
        Read data from stdout and stderr, until end-of-file is
        reached.  Wait for process to terminate.

        The optional "input" argument should be data to be sent to the
        child process, or None, if no data should be sent to the child.
        communicate() returns a tuple (stdout, stderr).

        By default, all communication is in bytes, and therefore any
        "input" should be bytes, and the (stdout, stderr) will be bytes.
        If in text mode (indicated by self.text_mode), any "input" should
        be a string, and (stdout, stderr) will be strings decoded
        according to locale encoding, or by "encoding" if set. Text mode
        is triggered by setting any of text, encoding, errors or
        universal_newlines.
        z.Cannot send input after starting communicationNr�rrtT)r�r4r�r9r/Zcountr��readr�ru�_time�_communicater��minr��_remaining_timer�r)r0r{rDr9r/�endtime�sigint_timeout�stsr&r&r'r�>sH
�



�
zPopen.communicatecCs|��S)zSCheck if child process has terminated. Set and return returncode
        attribute.)r`r5r&r&r'r��r:z
Popen.pollcCs|durdS|t�SdS)z5Convenience for _communicate when computing timeouts.N)r�)r0r�r&r&r'r��szPopen._remaining_timecCsL|durdS|st�|krHt|j||r0d�|�nd|r@d�|�ndd��dS)z2Convenience for checking if a timeout has expired.Nr(r�)r�rrhr�)r0r��orig_timeoutZ
stdout_seqZ
stderr_seq�skip_check_and_raiser&r&r'�_check_timeout�s�zPopen._check_timeoutcCs�|durt�|}z|j|d�WSty�|durJt|j|�|��}n|j}d|_z|j|d�WntyxYn0�Yn0dS)z=Wait for child process to terminate; returns self.returncode.Nrtr)r�r�r�r�r�r�r)r0rDr�r�r&r&r'ru�s 
�z
Popen.waitc	Cst|dd�}t����}trX|dkr.|�|j�|dkrB|�|j�|dkr�|�|j�nr|dkr~|dkr~||kr~|�tj|�|dkr�|dkr�||kr�|�tj|�|dkr�|dkr�||kr�|�tj|�|dur�|�tj|�Wd�n1s�0Yd|_dS)Nr�rdT)	rp�
contextlibZ	ExitStackr�ZcallbackrSr�r�r�)	r0r�r�r�r�r�r�Z
devnull_fdZstackr&r&r'�_close_pipe_fds�s$
,zPopen._close_pipe_fdscCs~|dur|dur|durdSd\}}d\}}d\}}	|durtt�tj�}|dur�t�dd�\}}
t|�}t�|
�nh|tkr�t�dd�\}}t|�t|�}}n<|tkr�t�	|�
��}n$t|t�r�t�	|�}nt�	|�
��}|�|�}|du�r*t�tj�}|du�r�t�dd�\}
}t|�}t�|
�nn|tk�rXt�dd�\}}t|�t|�}}n@|tk�rrt�	|�
��}n&t|t��r�t�	|�}nt�	|�
��}|�|�}|du�r�t�tj�}	|	du�rdt�dd�\}
}	t|	�}	t�|
�n~|tk�rt�dd�\}}	t|�t|	�}}	nP|tk�r$|}	n@|tk�r>t�	|�
��}	n&t|t��rVt�	|�}	nt�	|�
��}	|�|	�}	||||||	fS)�|Construct and return tuple with IO objects:
            p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
            N)rdrdrdrdrdrd�rdrdr)rYZGetStdHandlerZ
CreatePiperPrRrrr�Z
get_osfhandler�r�rT�fileno�_make_inheritablerrr)r0r�r9r/r�r�r�r�r�r�Z_r&r&r'r��sp












�zPopen._get_handlescCs&t�t��|t��ddtj�}t|�S)z2Return a duplicate of handle, which is inheritablerrm)rYZDuplicateHandleZGetCurrentProcessZDUPLICATE_SAME_ACCESSrP)r0�handleZhr&r&r'r�s
�zPopen._make_inheritablecCstdd�|D��S)z�Filter out console handles that can't be used
            in lpAttributeList["handle_list"] and make sure the list
            isn't empty. This also removes duplicate handles.cSs,h|]$}|d@dks$t�|�tjkr|�qS)�)rYZGetFileTypeZFILE_TYPE_CHAR)�.0r�r&r&r'Z	<setcomp>,s
��z,Popen._filter_handle_list.<locals>.<setcomp>)rO)r0rMr&r&r'�_filter_handle_list%szPopen._filter_handle_listc Cs8t|t�rnNt|t�r.|
r"td��t|g�}n,t|tj�rR|
rFtd��t|g�}nt|�}|durlt�|�}|dur|t�}n|�	�}d|||fv}|r�|j
tjO_
||_
||_||_|j}t|o�d|vo�|d�}|s�|�r^|�r^|dur�i}|_t|�dg��}|d<|�r0|t|�t|�t|�g7}|�|�|dd�<|�r^|�sZt�dt�d}|
�r�|j
tjO_
tj|_tj�dd	�}d
�||�}|du�r�t�|�}t�d||||�z@t� ||ddt|�|	|||�	\}}}}W|�!|||
|||�n|�!|||
|||�0d|_"t#|�|_$||_%t�&|�dS)
z$Execute program (MS Windows version)z$bytes args is not allowed on Windows�0path-like args is not allowed when shell is trueNrdrMz?startupinfo.lpAttributeList['handle_list'] overriding close_fdsFZCOMSPECzcmd.exez
{} /c "{}"�subprocess.PopenT)'r�r��bytesr�r�r��PathLiker�r"rNrGrYrrHrIrJrLr�rOryrTr�r�r�r�rrrK�environrra�auditZ
CreateProcessr�r�rP�_handler�rR) r0rhr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�Zunused_restore_signalsZ
unused_gidZunused_gidsZ
unused_uidZunused_umaskZunused_start_new_sessionZuse_std_handlesZattribute_listZhave_handle_listrMZcomspecZhpZhtr�Ztidr&r&r'r�2s�


��
�
�

���
zPopen._execute_childcCs,|jdur&||jd�|kr&||j�|_|jS)z�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.

            Nr)r,r�)r0r^Z_WaitForSingleObjectZ_WAIT_OBJECT_0Z_GetExitCodeProcessr&r&r'r`�s
zPopen._internal_pollcCs^|durtj}nt|d�}|jdurXt�|j|�}|tjkrJt|j|��t�	|j�|_|jS)z-Internal implementation of wait() on Windows.Ni�)
rYZINFINITErTr,�WaitForSingleObjectr�ZWAIT_TIMEOUTrrh�GetExitCodeProcess)r0rDZtimeout_millisr�r&r&r'r��s
�
zPopen._waitcCs|�|���|��dSr+)rgr�r�)r0ZfhZbufferr&r&r'�
_readerthread�szPopen._readerthreadcCs\|jrBt|d�sBg|_tj|j|j|jfd�|_d|j_|j��|j	r�t|d�s�g|_
tj|j|j	|j
fd�|_d|j_|j��|jr�|�
|�|jdur�|j�|�|��|j��r�t|j|��|j	dur�|j�|�|��|j��r�t|j|��d}d}|j�r|j}|j��|j	�r0|j
}|j	��|du�rB|d}|du�rT|d}||fS)N�_stdout_buff)ZtargetrhT�_stderr_buffr)r9r�r�r�ZThreadr�Z
stdout_threadZdaemonZstartr/r�Z
stderr_threadr�r�r�r�Zis_aliverrhr�)r0r{r�r�r9r/r&r&r'r��sN
��

��









zPopen._communicatecCsl|jdurdS|tjkr"|��nF|tjkr>t�|jtj�n*|tjkrZt�|jtj�nt	d�
|���dS)�Send a signal to the process.NzUnsupported signal: {})r,r3�SIGTERM�	terminateZCTRL_C_EVENTr�rvr�ZCTRL_BREAK_EVENTr4r�r0Zsigr&r&r'�send_signal�s




zPopen.send_signalcCsV|jdurdSzt�|jd�Wn0tyPt�|j�}|tjkrF�||_Yn0dS)zTerminates the process.Nrm)r,rYZTerminateProcessr�ZPermissionErrorr�ZSTILL_ACTIVE)r0Zrcr&r&r'r	s

zPopen.terminatec
Cs,d\}}d\}}d\}}	|dur"n@|tkr8t��\}}n*|tkrJ|��}nt|t�rZ|}n|��}|durln@|tkr�t��\}}n*|tkr�|��}nt|t�r�|}n|��}|dur�nf|tkr�t��\}}	nP|tkr�|dkr�|}	n
t	j
��}	n.|tk�r|��}	nt|t��r|}	n|��}	||||||	fS)r�r�Nrd)rr��piperr�r�rTr�rraZ
__stdout__)
r0r�r9r/r�r�r�r�r�r�r&r&r'r�sL





�cCs�|durtj}i}|rJg}dD]"}
tt|
d�}|dur|�|�q||d<g}|||	fD]}|dkrX|�tj|f�qX|df|df|
dffD]"\}}|dkr�|�tj||f�q�|r�||d<tj|||fi|��|_d	|_	|�
|||||	|
�dS)
z'Execute program using os.posix_spawn().N)ZSIGPIPEZSIGXFZZSIGXFSZZ	setsigdefrdrrmr��file_actionsT)r�r�rpr3rgZPOSIX_SPAWN_CLOSEZPOSIX_SPAWN_DUP2r�r�r�r�)r0rhr�r�r�r�r�r�r�r�r�rxZsigsetZsignameZsignumrr�Zfd2r&r&r'�_posix_spawnTs8��zPopen._posix_spawnc-st|ttf�r|g}n(t|tj�r6|
r.td��|g}nt|�}|
rlttd�rPdnd}|dg|}�rl�|d<�dur||d�t�	d�|||�t
�rFtj����rF|du�rF|�sF|�sF|du�rF|d	ks�|d
k�rF|d	ks�|d
k�rF|d	ks�|d
k�rF|�sF|du�rF|du�rF|du�rF|dk�rF|�
|�|||||
|||�
dS�}t��\}}g}|dk�r||�|�t�|�}�qZ|D]}t�|��q��zh�z|du�r�g}|��D]>\}}t�|�}d|v�r�td
��|�|dt�|���q�nd}t����tj����r�f} nt�fdd�t�|�D��} t|�}!|!�|�t�|| |tttt|!���|||||
||||||||||||�|_d|_Wt�|�nt�|�0|� |||
|||�t!�}"t�"|d�}#|"|#7}"|#�r�t#|"�dk�r��q�q�Wt�|�nt�|�0|"�rz6t�$|jd�\}$}%|$|jk�r<|�%|%�ntj&|_'Wnt(�yZYn0z|"�)dd
�\}&}'}(|(�*�}(Wn*t�y�d}&d}'d�+t|"��}(Yn0t,t-|&�*d�t.�})t/|)t0��r|'�rt|'d�}*|(dk}+|+�r�d}(|},n|},|*dk�rt�1|*�}(|)|*|(|,��|)|(��dS)zExecute program (POSIX version)r�Zgetandroidapilevelz/system/bin/shz/bin/shz-crNr�rdr�r�s=z!illegal environment variable namec3s"|]}tj�t�|���VqdSr+)r��pathr��fsencode)r�Zdir�r�r&r'Z	<genexpr>�s�z'Popen._execute_child.<locals>.<genexpr>TiP�s:sSubprocessErrors0z#Bad exception data from child: {!r}ZasciiiZnoexecr})2r�r�r�r�r�r�rOr�rar��_USE_POSIX_SPAWNrZdirnamerrrgZdupr�rorr4r�Z
get_exec_pathZsetZadd�_posixsubprocessZ	fork_execZsortedr�rTr�r�r�Z	bytearrayr�r��waitpid�_handle_exitstatusrbr,�ChildProcessErrorr�r�rrp�builtinsr
Z
issubclassr�Zstrerror)-r0rhr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�Z
unix_shellZorig_executableZerrpipe_readZ
errpipe_writeZlow_fds_to_closeZlow_fdZenv_listZkrjZexecutable_listZfds_to_keepZerrpipe_dataZpartr�r�Zexception_nameZ	hex_errnoZerr_msgZchild_exception_typeZ	errno_numZchild_exec_never_calledZerr_filenamer&r	r'r�{s��
�����������	�
���
��





�
�
�

��

�


cCs$||�r||�|_n
||�|_dS)�:All callers to this function MUST hold self._waitpid_lock.N)r,)r0r��waitstatus_to_exitcodeZ_WIFSTOPPEDZ	_WSTOPSIGr&r&r'r
szPopen._handle_exitstatusc
Cs�|jdur�|j�d�sdSz�zF|jdur<|jWW|j��S||j|�\}}||jkr`|�|�WnDty�}z,|dur�||_n|j|kr�d|_WYd}~n
d}~00W|j��n|j��0|jS)z�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).

            NFr)r,r��acquire�releaser�r
r�r�)r0r^Z_waitpidZ_WNOHANGZ_ECHILDr�r�Zer&r&r'r`+s$	


�

cCs<zt�|j|�\}}Wnty2|j}d}Yn0||fS)rr)r�rr�r)r0Z
wait_flagsr�r�r&r&r'�	_try_waitNs
zPopen._try_waitcCsP|jdur|jS|dur�t�|}d}|j�d�r�zX|jdurLW|j��q�|�tj�\}}||jkr~|�	|�W|j��q�W|j��n|j��0|�
|�}|dkr�t|j|��t
|d|d�}t�|�q&nv|jdu�rJ|j�P|jdu�rWd��qJ|�d�\}}||jk�r(|�	|�Wd�q�1�s>0Yq�|jS)z+Internal implementation of wait() on POSIX.Ng����Mb@?Frr�g�������?)r,r�r�rrrr��WNOHANGr�r
r�rrhr��timeZsleep)r0rDr�Zdelayr�r�Z	remainingr&r&r'r�[s>



�


�
,c
Cs2|jrT|jsTz|j��Wnty,Yn0|sTz|j��WntyRYn0d}d}|js�i|_|jrzg|j|j<|jr�g|j|j<|jr�|j|j}|jr�|j|j}|�|�|j	r�t
|j	�}t����}|jr�|r�|�|jt
j�|j�r|jj�s|�|jt
j�|j�r2|jj�s2|�|jt
j�|���r�|�|�}|du�rv|dk�rv|j||||dd�td��|�|�}	|�||||�|	D]�\}
}|
j|ju�r0||j|jt�}z|jt�|
j|�7_Wn*t�y|�|
j�|
j��Yn*0|jt|j	�k�r�|�|
j�|
j��nP|
j|j|jfv�r�t�|
jd�}
|
�sn|�|
j�|
j��|j|
j�|
��q��q2Wd�n1�s�0Y|j |�|�d�|du�r�d�!|�}|du�r�d�!|�}|j"�r*|du�r
|�#||jj$|jj%�}|du�r*|�#||jj$|jj%�}||fS)NrT)r�zN_check_timeout(..., skip_check_and_raise=True) failed to raise TimeoutExpired.i�rtr()&r�r�Zflushr�r�Z_fileobj2outputr9r/�_save_inputr�Z
memoryview�_PopenSelectorZregister�	selectorsZEVENT_WRITErQZ
EVENT_READZget_mapr�r�ZRuntimeError�selectZfileobj�
_input_offset�	_PIPE_BUFr�r�r�Z
unregisterr�r�rgrur�r�r�r�r�)r0r{r�r�r9r/Z
input_viewZselectorrDZreadyZkeyZeventsZchunkr�r&r&r'r��s�





��
�
:




�
�cCsF|jrB|jdurBd|_||_|durB|jrB|j�|jj|jj�|_dS)Nr)r�r�rr�Zencoder�r�)r0r{r&r&r'r�s�zPopen._save_inputcCs(|��|jdurdSt�|j|�dS)r�N)r�r,r�rvr�rr&r&r'r�s
cC�|�tj�dS)z/Terminate the process with SIGTERM
            N)rr3rr5r&r&r'rr:cCr)z*Kill the process with SIGKILL
            N)rr3ZSIGKILLr5r&r&r'rvr:z
Popen.kill)rdNNNNNTFNNNNrTFr&r?)Fr+):r#r$r%rAr�r1rWr�r�r�r�rBr|rCr�r�r�rarbr�r�rZr�r�r�r�r�r�rur�r�r�r�r�r�rYr�Z
WAIT_OBJECT_0r�r`r�r�r�rrrvrr�rZ
WIFSTOPPEDZWSTOPSIGr
rrr�ZECHILDrrr&r&r&r'r�s�5��j	



D	�

H	
o�
46'&�
�
#
)fr)LrArr�r�r�rr3rar�r�r�rr�r�r�ZImportErrorr�Z__all__r�rYr�ZModuleNotFoundErrorrrrrrrrrrrrrrrrrrrrr r!rqZ	Exceptionr
rrr"rTrPrprr�r[rZSelectSelectorr_r\rrrrirsrrr	Zobjectrr
r�rrr�r
rr&r&r&r'Z<module>
s�"

P

%	


;/%�EI
/