Skip to content

Commit b6b4737

Browse files
committed
Remove no longer needed workaround for subprocess pre 2.7
1 parent 8887b22 commit b6b4737

File tree

1 file changed

+5
-42
lines changed

1 file changed

+5
-42
lines changed

lib/matplotlib/compat/subprocess.py

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,61 +31,24 @@
3131
__all__ = ['Popen', 'PIPE', 'STDOUT', 'check_output', 'CalledProcessError']
3232

3333

34+
3435
if hasattr(subprocess, 'Popen'):
3536
Popen = subprocess.Popen
3637
# Assume that it also has the other constants.
3738
PIPE = subprocess.PIPE
3839
STDOUT = subprocess.STDOUT
3940
CalledProcessError = subprocess.CalledProcessError
41+
check_output = subprocess.check_output
4042
else:
4143
# In restricted environments (such as Google App Engine), these are
4244
# non-existent. Replace them with dummy versions that always raise OSError.
4345
def Popen(*args, **kwargs):
4446
raise OSError("subprocess.Popen is not supported")
47+
48+
def check_output(*args, **kwargs):
49+
raise OSError("subprocess.check_output is not supported")
4550
PIPE = -1
4651
STDOUT = -2
4752
# There is no need to catch CalledProcessError. These stubs cannot raise
4853
# it. None in an except clause will simply not match any exceptions.
4954
CalledProcessError = None
50-
51-
52-
def _check_output(*popenargs, **kwargs):
53-
r"""Run command with arguments and return its output as a byte
54-
string.
55-
56-
If the exit code was non-zero it raises a CalledProcessError. The
57-
CalledProcessError object will have the return code in the
58-
returncode
59-
attribute and output in the output attribute.
60-
61-
The arguments are the same as for the Popen constructor. Example::
62-
63-
>>> check_output(["ls", "-l", "/dev/null"])
64-
'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n'
65-
66-
The stdout argument is not allowed as it is used internally.
67-
To capture standard error in the result, use stderr=STDOUT.::
68-
69-
>>> check_output(["/bin/sh", "-c",
70-
... "ls -l non_existent_file ; exit 0"],
71-
... stderr=STDOUT)
72-
'ls: non_existent_file: No such file or directory\n'
73-
"""
74-
if 'stdout' in kwargs:
75-
raise ValueError('stdout argument not allowed, it will be overridden.')
76-
process = Popen(stdout=PIPE, *popenargs, **kwargs)
77-
output, unused_err = process.communicate()
78-
retcode = process.poll()
79-
if retcode:
80-
cmd = kwargs.get("args")
81-
if cmd is None:
82-
cmd = popenargs[0]
83-
raise subprocess.CalledProcessError(retcode, cmd, output=output)
84-
return output
85-
86-
87-
# python2.7's subprocess provides a check_output method
88-
if hasattr(subprocess, 'check_output'):
89-
check_output = subprocess.check_output
90-
else:
91-
check_output = _check_output

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy