Skip to content

Commit 0f36da1

Browse files
committed
Change some parts from bytes to str
1 parent 0fe94d0 commit 0f36da1

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

python-ethtool/etherinfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static void callback_nl_link(struct nl_object *obj, void *arg)
6767
if( ethi->hwaddress ) {
6868
Py_XDECREF(ethi->hwaddress);
6969
}
70-
ethi->hwaddress = PyBytes_FromFormat("%s", hwaddr);
70+
ethi->hwaddress = PyStr_FromFormat("%s", hwaddr);
7171
}
7272

7373

python-ethtool/ethtool.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,25 +223,20 @@ static PyObject *get_interfaces_info(PyObject *self __unused, PyObject *args) {
223223

224224
/* Parse input arguments if we got them */
225225
if( inargs != NULL ) {
226-
if( PyBytes_Check(inargs) ) { /* Input argument is just a string */
226+
if( PyStr_Check(inargs) ) { /* Input argument is just a string */
227227
fetch_devs_len = 1;
228228
fetch_devs = calloc(1, sizeof(char *));
229-
fetch_devs[0] = PyBytes_AsString(inargs);
230-
#if PY_MAJOR_VERSION >= 3
231-
} else if( PyUnicode_Check(inargs) ) { /* Input argument is just a ustring */
232-
fetch_devs_len = 1;
233-
fetch_devs = calloc(1, sizeof(char *));
234-
fetch_devs[0] = PyUnicode_AsUTF8(inargs);
235-
#endif
229+
fetch_devs[0] = PyStr_AsString(inargs);
230+
236231
} else if( PyTuple_Check(inargs) ) { /* Input argument is a tuple list with devices */
237232
int j = 0;
238233

239234
fetch_devs_len = PyTuple_Size(inargs);
240235
fetch_devs = calloc(fetch_devs_len+1, sizeof(char *));
241236
for( i = 0; i < fetch_devs_len; i++ ) {
242237
PyObject *elmt = PyTuple_GetItem(inargs, i);
243-
if( elmt && PyBytes_Check(elmt) ) {
244-
fetch_devs[j++] = PyBytes_AsString(elmt);
238+
if( elmt && PyStr_Check(elmt) ) {
239+
fetch_devs[j++] = PyStr_AsString(elmt);
245240
}
246241
}
247242
fetch_devs_len = j;
@@ -252,8 +247,8 @@ static PyObject *get_interfaces_info(PyObject *self __unused, PyObject *args) {
252247
fetch_devs = calloc(fetch_devs_len+1, sizeof(char *));
253248
for( i = 0; i < fetch_devs_len; i++ ) {
254249
PyObject *elmt = PyList_GetItem(inargs, i);
255-
if( elmt && PyBytes_Check(elmt) ) {
256-
fetch_devs[j++] = PyBytes_AsString(elmt);
250+
if( elmt && PyStr_Check(elmt) ) {
251+
fetch_devs[j++] = PyStr_AsString(elmt);
257252
}
258253
}
259254
fetch_devs_len = j;

python-ethtool/netlink-address.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
/* Python object corresponding to a (struct rtnl_addr) */
1717
#include <Python.h>
18+
#include "include/py3c/compat.h"
1819
#include <bytesobject.h>
1920
#include "structmember.h"
2021

@@ -55,7 +56,7 @@ PyNetlinkIPaddress_from_rtnl_addr(struct rtnl_addr *addr)
5556
PyErr_SetFromErrno(PyExc_RuntimeError);
5657
goto error;
5758
}
58-
py_obj->local = PyBytes_FromString(buf);
59+
py_obj->local = PyStr_FromString(buf);
5960
if (!py_obj->local) {
6061
goto error;
6162
}
@@ -85,7 +86,7 @@ PyNetlinkIPaddress_from_rtnl_addr(struct rtnl_addr *addr)
8586
PyErr_SetFromErrno(PyExc_RuntimeError);
8687
goto error;
8788
}
88-
py_obj->ipv4_broadcast = PyBytes_FromString(buf);
89+
py_obj->ipv4_broadcast = PyStr_FromString(buf);
8990
if (!py_obj->ipv4_broadcast) {
9091
goto error;
9192
}
@@ -94,7 +95,7 @@ PyNetlinkIPaddress_from_rtnl_addr(struct rtnl_addr *addr)
9495
/* Set IP address scope: */
9596
memset(&buf, 0, sizeof(buf));
9697
rtnl_scope2str(rtnl_addr_get_scope(addr), buf, sizeof(buf));
97-
py_obj->scope = PyBytes_FromString(buf);
98+
py_obj->scope = PyStr_FromString(buf);
9899

99100
return (PyObject*)py_obj;
100101

0 commit comments

Comments
 (0)