Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7d1d4363
Commit
7d1d4363
authored
Jul 14, 2006
by
Peter Astrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug #1223937: CalledProcessError.errno -> CalledProcessError.returncode.
parent
8c051da2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
13 deletions
+21
-13
Doc/lib/libsubprocess.tex
Doc/lib/libsubprocess.tex
+3
-4
Lib/subprocess.py
Lib/subprocess.py
+13
-8
Lib/test/test_subprocess.py
Lib/test/test_subprocess.py
+1
-1
Misc/NEWS
Misc/NEWS
+4
-0
No files found.
Doc/lib/libsubprocess.tex
View file @
7d1d4363
...
@@ -140,7 +140,7 @@ The arguments are the same as for the Popen constructor. Example:
...
@@ -140,7 +140,7 @@ The arguments are the same as for the Popen constructor. Example:
Run command with arguments. Wait for command to complete. If the exit
Run command with arguments. Wait for command to complete. If the exit
code was zero then return, otherwise raise
\exception
{
CalledProcessError.
}
code was zero then return, otherwise raise
\exception
{
CalledProcessError.
}
The
\exception
{
CalledProcessError
}
object will have the return code in the
The
\exception
{
CalledProcessError
}
object will have the return code in the
\member
{
errno
}
attribute.
\member
{
returncode
}
attribute.
The arguments are the same as for the Popen constructor. Example:
The arguments are the same as for the Popen constructor. Example:
...
@@ -164,9 +164,8 @@ should prepare for \exception{OSError} exceptions.
...
@@ -164,9 +164,8 @@ should prepare for \exception{OSError} exceptions.
A
\exception
{
ValueError
}
will be raised if
\class
{
Popen
}
is called
A
\exception
{
ValueError
}
will be raised if
\class
{
Popen
}
is called
with invalid arguments.
with invalid arguments.
check
_
call() will raise
\exception
{
CalledProcessError
}
, which is a
check
_
call() will raise
\exception
{
CalledProcessError
}
, if the called
subclass of
\exception
{
OSError
}
, if the called process returns a
process returns a non-zero return code.
non-zero return code.
\subsubsection
{
Security
}
\subsubsection
{
Security
}
...
...
Lib/subprocess.py
View file @
7d1d4363
...
@@ -121,7 +121,7 @@ check_call(*popenargs, **kwargs):
...
@@ -121,7 +121,7 @@ check_call(*popenargs, **kwargs):
Run command with arguments. Wait for command to complete. If the
Run command with arguments. Wait for command to complete. If the
exit code was zero then return, otherwise raise
exit code was zero then return, otherwise raise
CalledProcessError. The CalledProcessError object will have the
CalledProcessError. The CalledProcessError object will have the
return code in the
errno
attribute.
return code in the
returncode
attribute.
The arguments are the same as for the Popen constructor. Example:
The arguments are the same as for the Popen constructor. Example:
...
@@ -141,8 +141,8 @@ should prepare for OSErrors.
...
@@ -141,8 +141,8 @@ should prepare for OSErrors.
A ValueError will be raised if Popen is called with invalid arguments.
A ValueError will be raised if Popen is called with invalid arguments.
check_call() will raise CalledProcessError,
which is a subclass of
check_call() will raise CalledProcessError,
if the called process
OSError, if the called process
returns a non-zero return code.
returns a non-zero return code.
Security
Security
...
@@ -360,11 +360,16 @@ import types
...
@@ -360,11 +360,16 @@ import types
import
traceback
import
traceback
# Exception classes used by this module.
# Exception classes used by this module.
class
CalledProcessError
(
OSError
):
class
CalledProcessError
(
Exception
):
"""This exception is raised when a process run by check_call() returns
"""This exception is raised when a process run by check_call() returns
a non-zero exit status. The exit status will be stored in the
a non-zero exit status. The exit status will be stored in the
errno attribute. This exception is a subclass of
returncode attribute."""
OSError."""
def
__init__
(
self
,
returncode
,
cmd
):
self
.
returncode
=
returncode
self
.
cmd
=
cmd
def
__str__
(
self
):
return
"Command '%s' returned non-zero exit status %d"
%
(
self
.
cmd
,
self
.
returncode
)
if
mswindows
:
if
mswindows
:
import
threading
import
threading
...
@@ -442,7 +447,7 @@ def check_call(*popenargs, **kwargs):
...
@@ -442,7 +447,7 @@ def check_call(*popenargs, **kwargs):
"""Run command with arguments. Wait for command to complete. If
"""Run command with arguments. Wait for command to complete. If
the exit code was zero then return, otherwise raise
the exit code was zero then return, otherwise raise
CalledProcessError. The CalledProcessError object will have the
CalledProcessError. The CalledProcessError object will have the
return code in the
errno
attribute.
return code in the
returncode
attribute.
The arguments are the same as for the Popen constructor. Example:
The arguments are the same as for the Popen constructor. Example:
...
@@ -453,7 +458,7 @@ def check_call(*popenargs, **kwargs):
...
@@ -453,7 +458,7 @@ def check_call(*popenargs, **kwargs):
if
cmd
is
None
:
if
cmd
is
None
:
cmd
=
popenargs
[
0
]
cmd
=
popenargs
[
0
]
if
retcode
:
if
retcode
:
raise
CalledProcessError
(
retcode
,
"Command %s returned non-zero exit status"
%
cmd
)
raise
CalledProcessError
(
retcode
,
cmd
)
return
retcode
return
retcode
...
...
Lib/test/test_subprocess.py
View file @
7d1d4363
...
@@ -68,7 +68,7 @@ class ProcessTestCase(unittest.TestCase):
...
@@ -68,7 +68,7 @@ class ProcessTestCase(unittest.TestCase):
subprocess
.
check_call
([
sys
.
executable
,
"-c"
,
subprocess
.
check_call
([
sys
.
executable
,
"-c"
,
"import sys; sys.exit(47)"
])
"import sys; sys.exit(47)"
])
except
subprocess
.
CalledProcessError
,
e
:
except
subprocess
.
CalledProcessError
,
e
:
self
.
assertEqual
(
e
.
errno
,
47
)
self
.
assertEqual
(
e
.
returncode
,
47
)
else
:
else
:
self
.
fail
(
"Expected CalledProcessError"
)
self
.
fail
(
"Expected CalledProcessError"
)
...
...
Misc/NEWS
View file @
7d1d4363
...
@@ -576,6 +576,10 @@ Extension Modules
...
@@ -576,6 +576,10 @@ Extension Modules
Library
Library
-------
-------
-
Bug
#
1223937
:
subprocess
.
CalledProcessError
reports
the
exit
status
of
the
process
using
the
returncode
attribute
,
instead
of
abusing
errno
.
-
Patch
#
1475231
:
``
doctest
``
has
a
new
``
SKIP
``
option
,
which
causes
-
Patch
#
1475231
:
``
doctest
``
has
a
new
``
SKIP
``
option
,
which
causes
a
doctest
to
be
skipped
(
the
code
is
not
run
,
and
the
expected
output
a
doctest
to
be
skipped
(
the
code
is
not
run
,
and
the
expected
output
or
exception
is
ignored
).
or
exception
is
ignored
).
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment