summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2015-02-03 21:19:13 +0100
committerDavid Sommerseth <davids@redhat.com>2015-02-03 21:19:13 +0100
commit3b32d9d05a785a744f5e315ef9267d67723e082c (patch)
tree1f98276536e6a6d479c74ea12b3f97e98213b9af
parent5cc3d02060f67317049b6e0549c87a407e030e61 (diff)
downloadpython-dmidecode-3b32d9d05a785a744f5e315ef9267d67723e082c.tar.gz
python-dmidecode-3b32d9d05a785a744f5e315ef9267d67723e082c.tar.xz
python-dmidecode-3b32d9d05a785a744f5e315ef9267d67723e082c.zip
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 <davids@redhat.com>
-rw-r--r--src/dmidecodemodule.c11
1 files 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);
}