|
1 | 1 | """Some backported features for subprocess.""" |
2 | 2 |
|
3 | 3 | from __future__ import absolute_import |
| 4 | + |
4 | 5 | import sys |
5 | | -import subprocess |
6 | | -from subprocess import (Popen, PIPE, STDOUT, CalledProcessError, |
7 | | - call, check_call, check_output) |
| 6 | +import time |
| 7 | + |
| 8 | +from subprocess import Popen, PIPE, STDOUT, check_call, check_output |
| 9 | + |
8 | 10 | if sys.platform == 'win32': |
9 | 11 | from subprocess import STARTUPINFO |
10 | | -from subprocess import * |
11 | | - |
| 12 | + assert STARTUPINFO |
12 | 13 |
|
13 | | -try: |
14 | | - TimeoutExpired |
15 | | -except NameError: |
16 | | - import time |
| 14 | +assert check_call |
| 15 | +assert check_output |
| 16 | +assert PIPE |
| 17 | +assert STDOUT |
17 | 18 |
|
| 19 | +if sys.version_info[0] == 2: |
18 | 20 | class SubprocessError(Exception): |
19 | 21 |
|
20 | 22 | """Exception classes used by this module.""" |
21 | 23 |
|
22 | | - class CalledProcessError(SubprocessError): |
23 | | - |
24 | | - """Raised when a process run by check_call() or check_output(). |
25 | | -
|
26 | | - Returns a non-zero exit status. |
27 | | -
|
28 | | - """ |
29 | | - |
30 | | - def __init__(self, returncode, cmd, output=None): |
31 | | - self.returncode = returncode |
32 | | - self.cmd = cmd |
33 | | - self.output = output |
34 | | - |
35 | | - def __str__(self): |
36 | | - return ("Command '%s' returned non-zero exit status %d" % |
37 | | - (self.cmd, self.returncode)) |
38 | | - |
39 | 24 | class TimeoutExpired(SubprocessError): |
40 | 25 |
|
41 | 26 | """Raised when the timeout expires while waiting for a child |
@@ -72,7 +57,6 @@ def Popen_communicate(self, input=None, timeout=None): |
72 | 57 | self.wait(timeout) |
73 | 58 | return _Popen_communicate(self, input) |
74 | 59 |
|
75 | | - subprocess.CalledProcessError = CalledProcessError |
76 | 60 | _Popen_init = Popen.__init__ |
77 | 61 | _Popen_wait = Popen.wait |
78 | 62 | _Popen_communicate = Popen.communicate |
|
0 commit comments