summaryrefslogtreecommitdiff
path: root/psutil
diff options
context:
space:
mode:
authorMatthieu Darbois <mayeut@users.noreply.github.com>2022-09-19 11:51:34 +0200
committerGitHub <noreply@github.com>2022-09-19 11:51:34 +0200
commitf6d01ace5d86435a1b865fd066c68eb2ca433d76 (patch)
tree6d6a3247bdfbf83e12afd741708a62a0510ec106 /psutil
parent40c9c545191204ff623aa2f95d1e6b1b0dbac5f3 (diff)
downloadpsutil-f6d01ace5d86435a1b865fd066c68eb2ca433d76.tar.gz
net_if_stats() -> flags: do not return unicode on Python 2 (#2142)
Do not use unicode string for network interface flags on Python 2 Update network interface flags tests to work on CentOS 6 (CI tests are currently failing) Signed-off-by: mayeut <mayeut@users.noreply.github.com>
Diffstat (limited to 'psutil')
-rw-r--r--psutil/_psutil_posix.c6
-rwxr-xr-xpsutil/tests/test_linux.py9
2 files changed, 14 insertions, 1 deletions
diff --git a/psutil/_psutil_posix.c b/psutil/_psutil_posix.c
index 7742eb41..07c10398 100644
--- a/psutil/_psutil_posix.c
+++ b/psutil/_psutil_posix.c
@@ -434,7 +434,11 @@ append_flag(PyObject *py_retlist, const char * flag_name)
{
PyObject *py_str = NULL;
- py_str = PyUnicode_DecodeFSDefault(flag_name);
+#if PY_MAJOR_VERSION >= 3
+ py_str = PyUnicode_FromString(flag_name);
+#else
+ py_str = PyString_FromString(flag_name);
+#endif
if (! py_str)
return 0;
if (PyList_Append(py_retlist, py_str)) {
diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py
index feec0a59..c53dfd8a 100755
--- a/psutil/tests/test_linux.py
+++ b/psutil/tests/test_linux.py
@@ -1010,6 +1010,15 @@ class TestSystemNetIfStats(PsutilTestCase):
ifconfig_flags = set(match.group(2).lower().split(","))
psutil_flags = set(stats.flags.split(","))
self.assertEqual(ifconfig_flags, psutil_flags)
+ else:
+ # ifconfig has a different output on CentOS 6
+ # let's try that
+ match = re.search(r"(.*) MTU:(\d+) Metric:(\d+)", out)
+ if match and len(match.groups()) >= 3:
+ matches_found += 1
+ ifconfig_flags = set(match.group(1).lower().split())
+ psutil_flags = set(stats.flags.split(","))
+ self.assertEqual(ifconfig_flags, psutil_flags)
if not matches_found:
raise self.fail("no matches were found")