Skip to content

Commit 301bbdf

Browse files
Andy Groverstratakis
authored andcommitted
python3: Allow unicode strings as arg to get_interfaces_info
Going along with the previous "s*" change, allow the function to take either a bytestring or a string. Otherwise .get_interfaces_info(b"eth1") works on python3 but .get_interfaces_info("eth1") doesn't. Signed-off-by: Andy Grover <agrover@redhat.com>
1 parent e445d9f commit 301bbdf

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

python-ethtool/ethtool.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ static PyObject *get_interfaces_info(PyObject *self __unused, PyObject *args) {
223223
fetch_devs_len = 1;
224224
fetch_devs = calloc(1, sizeof(char *));
225225
fetch_devs[0] = PyBytes_AsString(inargs);
226+
#if PY_MAJOR_VERSION >= 3
227+
} else if( PyUnicode_Check(inargs) ) { /* Input argument is just a ustring */
228+
fetch_devs_len = 1;
229+
fetch_devs = calloc(1, sizeof(char *));
230+
fetch_devs[0] = PyUnicode_AsUTF8(inargs);
231+
#endif
226232
} else if( PyTuple_Check(inargs) ) { /* Input argument is a tuple list with devices */
227233
int j = 0;
228234

0 commit comments

Comments
 (0)