[Python-checkins] r50638 - in python/trunk: Doc/lib/libsubprocess.tex Lib/subprocess.py Lib/test/test_subprocess.py Misc/NEWS

peter.astrand python-checkins at python.org
Fri Jul 14 16:04:46 CEST 2006


Author: peter.astrand
Date: Fri Jul 14 16:04:45 2006
New Revision: 50638

Modified:
   python/trunk/Doc/lib/libsubprocess.tex
   python/trunk/Lib/subprocess.py
   python/trunk/Lib/test/test_subprocess.py
   python/trunk/Misc/NEWS
Log:
Bug #1223937: CalledProcessError.errno -> CalledProcessError.returncode.

Modified: python/trunk/Doc/lib/libsubprocess.tex
==============================================================================
--- python/trunk/Doc/lib/libsubprocess.tex	(original)
+++ python/trunk/Doc/lib/libsubprocess.tex	Fri Jul 14 16:04:45 2006
@@ -140,7 +140,7 @@
 Run command with arguments.  Wait for command to complete. If the exit
 code was zero then return, otherwise raise \exception{CalledProcessError.}
 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:
 
@@ -164,9 +164,8 @@
 A \exception{ValueError} will be raised if \class{Popen} is called
 with invalid arguments.
 
-check_call() will raise \exception{CalledProcessError}, which is a
-subclass of \exception{OSError}, if the called process returns a
-non-zero return code.
+check_call() will raise \exception{CalledProcessError}, if the called
+process returns a non-zero return code.
 
 
 \subsubsection{Security}

Modified: python/trunk/Lib/subprocess.py
==============================================================================
--- python/trunk/Lib/subprocess.py	(original)
+++ python/trunk/Lib/subprocess.py	Fri Jul 14 16:04:45 2006
@@ -121,7 +121,7 @@
     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 errno attribute.
+    return code in the returncode attribute.
 
     The arguments are the same as for the Popen constructor.  Example:
 
@@ -141,8 +141,8 @@
 
 A ValueError will be raised if Popen is called with invalid arguments.
 
-check_call() will raise CalledProcessError, which is a subclass of
-OSError, if the called process returns a non-zero return code.
+check_call() will raise CalledProcessError, if the called process
+returns a non-zero return code.
 
 
 Security
@@ -360,11 +360,16 @@
 import traceback
 
 # Exception classes used by this module.
-class CalledProcessError(OSError):
+class CalledProcessError(Exception):
     """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
-    errno attribute.  This exception is a subclass of
-    OSError."""
+    returncode attribute."""
+    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:
     import threading
@@ -442,7 +447,7 @@
     """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 errno attribute.
+    return code in the returncode attribute.
 
     The arguments are the same as for the Popen constructor.  Example:
 
@@ -453,7 +458,7 @@
     if cmd is None:
         cmd = popenargs[0]
     if retcode:
-        raise CalledProcessError(retcode, "Command %s returned non-zero exit status" % cmd)
+        raise CalledProcessError(retcode, cmd)
     return retcode
 
 

Modified: python/trunk/Lib/test/test_subprocess.py
==============================================================================
--- python/trunk/Lib/test/test_subprocess.py	(original)
+++ python/trunk/Lib/test/test_subprocess.py	Fri Jul 14 16:04:45 2006
@@ -68,7 +68,7 @@
             subprocess.check_call([sys.executable, "-c",
                                    "import sys; sys.exit(47)"])
         except subprocess.CalledProcessError, e:
-            self.assertEqual(e.errno, 47)
+            self.assertEqual(e.returncode, 47)
         else:
             self.fail("Expected CalledProcessError")
 

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Fri Jul 14 16:04:45 2006
@@ -576,6 +576,10 @@
 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
   a doctest to be skipped (the code is not run, and the expected output
   or exception is ignored).


More information about the Python-checkins mailing list