summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2015-02-12 11:35:32 -0800
committerGiampaolo Rodola <g.rodola@gmail.com>2015-02-12 11:35:32 -0800
commitbcfdbdcd170eaff681890631222132294efc6782 (patch)
tree02196501fdf7de99a30c37698e491457f0fcf937
parent85c400d21181dc532f55c97d75fce2254731cd88 (diff)
downloadpsutil-bcfdbdcd170eaff681890631222132294efc6782.tar.gz
fix compilation error on windows + py3; fix a couple of other minor things
-rw-r--r--psutil/__init__.py3
-rw-r--r--psutil/_psutil_windows.c11
-rw-r--r--psutil/_pswindows.py8
-rw-r--r--test/test_psutil.py2
4 files changed, 20 insertions, 4 deletions
diff --git a/psutil/__init__.py b/psutil/__init__.py
index 5ba1d8d0..0ee23fdb 100644
--- a/psutil/__init__.py
+++ b/psutil/__init__.py
@@ -1850,7 +1850,8 @@ def net_if_addrs():
try:
fam = socket.AddressFamily(fam)
except ValueError:
- pass
+ if os.name == 'nt' and fam == -1:
+ fam = _psplatform.AF_LINK
ret[name].append(_common.snic(fam, addr, mask, broadcast))
return dict(ret)
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index bb07ef80..0ee9d9a3 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -3069,7 +3069,14 @@ psutil_net_if_addrs(PyObject *self, PyObject *args)
}
*--ptr = '\0';
+#if PY_MAJOR_VERSION >= 3
+ py_mac_address = PyUnicode_FromString(buff);
+#else
py_mac_address = PyString_FromString(buff);
+#endif
+ if (py_mac_address == NULL)
+ goto error;
+
Py_INCREF(Py_None);
Py_INCREF(Py_None);
py_tuple = Py_BuildValue(
@@ -3114,7 +3121,11 @@ psutil_net_if_addrs(PyObject *self, PyObject *args)
PyErr_SetFromWindowsErr(GetLastError());
goto error;
}
+#if PY_MAJOR_VERSION >= 3
+ py_address = PyUnicode_FromString(buff);
+#else
py_address = PyString_FromString(buff);
+#endif
if (py_address == NULL)
goto error;
diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py
index 52443cf5..1ddcd520 100644
--- a/psutil/_pswindows.py
+++ b/psutil/_pswindows.py
@@ -34,8 +34,8 @@ else:
__extra__all__ = ["ABOVE_NORMAL_PRIORITY_CLASS", "BELOW_NORMAL_PRIORITY_CLASS",
"HIGH_PRIORITY_CLASS", "IDLE_PRIORITY_CLASS",
"NORMAL_PRIORITY_CLASS", "REALTIME_PRIORITY_CLASS",
- #
"CONN_DELETE_TCB",
+ "AF_LINK",
]
# --- module level constants (gets pushed up to psutil module)
@@ -44,7 +44,11 @@ CONN_DELETE_TCB = "DELETE_TCB"
WAIT_TIMEOUT = 0x00000102 # 258 in decimal
ACCESS_DENIED_SET = frozenset([errno.EPERM, errno.EACCES,
cext.ERROR_ACCESS_DENIED])
-AF_LINK = -1
+if enum is None:
+ AF_LINK = -1
+else:
+ AddressFamily = enum.IntEnum('AddressFamily', {'AF_LINK': -1})
+ AF_LINK = AddressFamily.AF_LINK
TCP_STATUSES = {
cext.MIB_TCP_STATE_ESTAB: _common.CONN_ESTABLISHED,
diff --git a/test/test_psutil.py b/test/test_psutil.py
index 979c77a5..c248651a 100644
--- a/test/test_psutil.py
+++ b/test/test_psutil.py
@@ -1061,7 +1061,7 @@ class TestSystemAPIs(unittest.TestCase):
self.assertIsInstance(addr.broadcast, (str, type(None)))
self.assertIn(addr.family, families)
if sys.version_info >= (3, 4):
- self.assertIsInstance(addr.family, socket.AddressFamily)
+ self.assertIsInstance(addr.family, enum.IntEnum)
if addr.family == socket.AF_INET:
s = socket.socket(addr.family)
with contextlib.closing(s):