]> granicus.if.org Git - python/commitdiff
Issue #8412: os.system() now accepts bytes, bytearray and str with
authorVictor Stinner <victor.stinner@haypocalc.com>
Fri, 16 Apr 2010 11:45:13 +0000 (11:45 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Fri, 16 Apr 2010 11:45:13 +0000 (11:45 +0000)
surrogates.

Misc/NEWS
Modules/posixmodule.c

index 7465609d4a19fc6dee2e231deaf7179c88c29fd7..18d7ca9bb77773cec6c672a409cf746529952cb9 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -312,6 +312,9 @@ C-API
 Library
 -------
 
+- Issue #8412: os.system() now accepts bytes, bytearray and str with
+  surrogates.
+
 - Issue #2987: RFC2732 support for urlparse (IPv6 addresses). Patch by Tony
   Locke and Hans Ulrich Niedermann.
 
index e6ef4107a121ac2d389dc06f104c7f4f68f06762..fb22eb6bece19f882e190b95c3f26b147e1f453f 100644 (file)
@@ -2688,18 +2688,23 @@ posix_system(PyObject *self, PyObject *args)
        wchar_t *command;
        if (!PyArg_ParseTuple(args, "u:system", &command))
                return NULL;
+
+       Py_BEGIN_ALLOW_THREADS
+       sts = _wsystem(command);
+       Py_END_ALLOW_THREADS
 #else
+       PyObject *command_obj;
        char *command;
-       if (!PyArg_ParseTuple(args, "s:system", &command))
+       if (!PyArg_ParseTuple(args, "O&:system",
+                             PyUnicode_FSConverter, &command_obj))
                return NULL;
-#endif
+
+       command = bytes2str(command_obj, 1);
        Py_BEGIN_ALLOW_THREADS
-#ifdef MS_WINDOWS
-       sts = _wsystem(command);
-#else
        sts = system(command);
-#endif
        Py_END_ALLOW_THREADS
+       release_bytes(command_obj);
+#endif
        return PyLong_FromLong(sts);
 }
 #endif