diff options
author | Georg Brandl <georg@python.org> | 2006-04-03 12:26:26 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2006-04-03 12:26:26 (GMT) |
commit | ad89dc879473e932a2b2daadfa94e7405cb938dc (patch) | |
tree | f0936026528b3d047d941da341d0d9ee8646273c | |
parent | 59c3acc3cd5b08d0304e87e1b2b54a4f82bc4fc9 (diff) | |
download | cpython-ad89dc879473e932a2b2daadfa94e7405cb938dc.zip cpython-ad89dc879473e932a2b2daadfa94e7405cb938dc.tar.gz cpython-ad89dc879473e932a2b2daadfa94e7405cb938dc.tar.bz2 |
Bug #1451503: allow unicode filenames in os.startfile().
-rw-r--r-- | Modules/posixmodule.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 50ee0e3..db6f673 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7467,6 +7467,41 @@ win32_startfile(PyObject *self, PyObject *args) char *filepath; char *operation = NULL; HINSTANCE rc; +#ifdef Py_WIN_WIDE_FILENAMES + if (unicode_file_names()) { + PyObject *unipath, *woperation; + if (!PyArg_ParseTuple(args, "U|s:startfile", + &unipath, &operation)) { + PyErr_Clear(); + goto normal; + } + + woperation = PyUnicode_DecodeASCII(operation, + strlen(operation), NULL); + if (!woperation) { + PyErr_Clear(); + goto normal; + } + + Py_BEGIN_ALLOW_THREADS + rc = ShellExecuteW((HWND)0, operation, + PyUnicode_AS_UNICODE(unipath), + PyUnicode_AS_UNICODE(woperation), + NULL, NULL, SW_SHOWNORMAL); + Py_END_ALLOW_THREADS + + Py_DECREF(woperation); + if (rc <= (HINSTANCE)32) { + PyObject *errval = win32_error_unicode("startfile", + PyUnicode_AS_UNICODE(unipath)); + return errval; + } + Py_INCREF(Py_None); + return Py_None; + } +#endif + +normal: if (!PyArg_ParseTuple(args, "et|s:startfile", Py_FileSystemDefaultEncoding, &filepath, &operation)) |