From 3b32d9d05a785a744f5e315ef9267d67723e082c Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Tue, 3 Feb 2015 21:19:13 +0100 Subject: Fix failing dmidecode.pythonmap() on Python 3 Python 3 uses the Unicode type for strings but it did only support the Bytes type. So the loading of XML-to-Python-dict-map would fail. This patch preserves the Bytes type support while adding Unicode support, which is what is done other places in the code as well. Signed-off-by: David Sommerseth --- src/dmidecodemodule.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/dmidecodemodule.c b/src/dmidecodemodule.c index 8db99cb..b31c002 100644 --- a/src/dmidecodemodule.c +++ b/src/dmidecodemodule.c @@ -659,12 +659,17 @@ static PyObject *dmidecode_set_dev(PyObject * self, PyObject * arg) static PyObject *dmidecode_set_pythonxmlmap(PyObject * self, PyObject * arg) { - if(PyBytes_Check(arg)) { + char *fname = NULL; + + if (PyUnicode_Check(arg)) { + fname = PyUnicode_AsUTF8(arg); + } else if (PyBytes_Check(arg)) { + fname = PyBytes_AsString(arg); + } + if (fname) { struct stat fileinfo; - char *fname = PyBytes_AsString(arg); memset(&fileinfo, 0, sizeof(struct stat)); - if( stat(fname, &fileinfo) != 0 ) { PyReturnError(PyExc_IOError, "Could not access the file '%s'", fname); } -- cgit