From 122363a8eeff964fcec7dc4dbcf7280e57225485 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Wed, 17 Apr 2024 21:17:05 +0200 Subject: [PATCH] more renames (C modules) --- psutil/_psbsd.py | 2 +- psutil/_psosx.py | 2 +- psutil/_psutil_bsd.c | 2 +- psutil/_psutil_osx.c | 2 +- psutil/arch/freebsd/proc_socks.c | 2 +- psutil/arch/freebsd/proc_socks.h | 2 +- psutil/arch/netbsd/proc.h | 2 +- psutil/arch/netbsd/socks.h | 2 +- psutil/arch/osx/proc.c | 2 +- psutil/arch/osx/proc.h | 2 +- psutil/tests/__init__.py | 4 +-- psutil/tests/test_connections.py | 46 ++++++++++++++++---------------- psutil/tests/test_testutils.py | 9 ++++--- psutil/tests/test_unicode.py | 2 +- 14 files changed, 42 insertions(+), 39 deletions(-) diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py index 482298c143..b11b81c350 100644 --- a/psutil/_psbsd.py +++ b/psutil/_psbsd.py @@ -835,7 +835,7 @@ def net_connections(self, kind='inet'): elif OPENBSD: rawlist = cext.net_connections(self.pid, families, types) else: - rawlist = cext.proc_connections(self.pid, families, types) + rawlist = cext.proc_net_connections(self.pid, families, types) for item in rawlist: fd, fam, type, laddr, raddr, status = item[:6] diff --git a/psutil/_psosx.py b/psutil/_psosx.py index c0595bd1ff..1067094679 100644 --- a/psutil/_psosx.py +++ b/psutil/_psosx.py @@ -508,7 +508,7 @@ def net_connections(self, kind='inet'): % (kind, ', '.join([repr(x) for x in conn_tmap])) ) families, types = conn_tmap[kind] - rawlist = cext.proc_connections(self.pid, families, types) + rawlist = cext.proc_net_connections(self.pid, families, types) ret = [] for item in rawlist: fd, fam, type, laddr, raddr, status = item diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c index fde3916d31..6517d5800a 100644 --- a/psutil/_psutil_bsd.c +++ b/psutil/_psutil_bsd.c @@ -63,7 +63,7 @@ static PyMethodDef mod_methods[] = { {"proc_oneshot_info", psutil_proc_oneshot_info, METH_VARARGS}, {"proc_threads", psutil_proc_threads, METH_VARARGS}, #if defined(PSUTIL_FREEBSD) - {"proc_connections", psutil_proc_connections, METH_VARARGS}, + {"proc_net_connections", psutil_proc_net_connections, METH_VARARGS}, #endif {"proc_cwd", psutil_proc_cwd, METH_VARARGS}, #if defined(__FreeBSD_version) && __FreeBSD_version >= 800000 || PSUTIL_OPENBSD || defined(PSUTIL_NETBSD) diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c index 369fbbfb48..4aa11d1700 100644 --- a/psutil/_psutil_osx.c +++ b/psutil/_psutil_osx.c @@ -23,7 +23,7 @@ static PyMethodDef mod_methods[] = { // --- per-process functions {"proc_cmdline", psutil_proc_cmdline, METH_VARARGS}, - {"proc_connections", psutil_proc_connections, METH_VARARGS}, + {"proc_net_connections", psutil_proc_net_connections, METH_VARARGS}, {"proc_cwd", psutil_proc_cwd, METH_VARARGS}, {"proc_environ", psutil_proc_environ, METH_VARARGS}, {"proc_exe", psutil_proc_exe, METH_VARARGS}, diff --git a/psutil/arch/freebsd/proc_socks.c b/psutil/arch/freebsd/proc_socks.c index 737467a8cb..c84c3b04a8 100644 --- a/psutil/arch/freebsd/proc_socks.c +++ b/psutil/arch/freebsd/proc_socks.c @@ -178,7 +178,7 @@ psutil_search_tcplist(char *buf, struct kinfo_file *kif) { PyObject * -psutil_proc_connections(PyObject *self, PyObject *args) { +psutil_proc_net_connections(PyObject *self, PyObject *args) { // Return connections opened by process. pid_t pid; int i; diff --git a/psutil/arch/freebsd/proc_socks.h b/psutil/arch/freebsd/proc_socks.h index a7996b1074..edc29b7aaf 100644 --- a/psutil/arch/freebsd/proc_socks.h +++ b/psutil/arch/freebsd/proc_socks.h @@ -6,4 +6,4 @@ #include -PyObject* psutil_proc_connections(PyObject* self, PyObject* args); +PyObject* psutil_proc_net_connections(PyObject* self, PyObject* args); diff --git a/psutil/arch/netbsd/proc.h b/psutil/arch/netbsd/proc.h index 8c51914d7e..138ff6ebd2 100644 --- a/psutil/arch/netbsd/proc.h +++ b/psutil/arch/netbsd/proc.h @@ -15,8 +15,8 @@ int psutil_get_proc_list(kinfo_proc **procList, size_t *procCount); char *psutil_get_cmd_args(pid_t pid, size_t *argsize); PyObject *psutil_proc_cmdline(PyObject *self, PyObject *args); -PyObject *psutil_proc_connections(PyObject *self, PyObject *args); PyObject *psutil_proc_cwd(PyObject *self, PyObject *args); +PyObject *psutil_proc_net_connections(PyObject *self, PyObject *args); PyObject *psutil_proc_num_fds(PyObject *self, PyObject *args); PyObject *psutil_proc_threads(PyObject *self, PyObject *args); PyObject* psutil_proc_exe(PyObject* self, PyObject* args); diff --git a/psutil/arch/netbsd/socks.h b/psutil/arch/netbsd/socks.h index 9e6a97c0a8..9c2a87d4d7 100644 --- a/psutil/arch/netbsd/socks.h +++ b/psutil/arch/netbsd/socks.h @@ -6,5 +6,5 @@ * found in the LICENSE file. */ -PyObject *psutil_proc_connections(PyObject *, PyObject *); PyObject *psutil_net_connections(PyObject *, PyObject *); +PyObject *psutil_proc_net_connections(PyObject *, PyObject *); diff --git a/psutil/arch/osx/proc.c b/psutil/arch/osx/proc.c index 6f66c8613f..2cdb9911c0 100644 --- a/psutil/arch/osx/proc.c +++ b/psutil/arch/osx/proc.c @@ -857,7 +857,7 @@ psutil_proc_open_files(PyObject *self, PyObject *args) { * - /usr/include/sys/proc_info.h */ PyObject * -psutil_proc_connections(PyObject *self, PyObject *args) { +psutil_proc_net_connections(PyObject *self, PyObject *args) { pid_t pid; int num_fds; int i; diff --git a/psutil/arch/osx/proc.h b/psutil/arch/osx/proc.h index 63f16ccdd2..f18f5f1fd6 100644 --- a/psutil/arch/osx/proc.h +++ b/psutil/arch/osx/proc.h @@ -8,13 +8,13 @@ PyObject *psutil_pids(PyObject *self, PyObject *args); PyObject *psutil_proc_cmdline(PyObject *self, PyObject *args); -PyObject *psutil_proc_connections(PyObject *self, PyObject *args); PyObject *psutil_proc_cwd(PyObject *self, PyObject *args); PyObject *psutil_proc_environ(PyObject *self, PyObject *args); PyObject *psutil_proc_exe(PyObject *self, PyObject *args); PyObject *psutil_proc_kinfo_oneshot(PyObject *self, PyObject *args); PyObject *psutil_proc_memory_uss(PyObject *self, PyObject *args); PyObject *psutil_proc_name(PyObject *self, PyObject *args); +PyObject *psutil_proc_net_connections(PyObject *self, PyObject *args); PyObject *psutil_proc_num_fds(PyObject *self, PyObject *args); PyObject *psutil_proc_open_files(PyObject *self, PyObject *args); PyObject *psutil_proc_pidtaskinfo_oneshot(PyObject *self, PyObject *args); diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index 7f88b26645..b18b742396 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -105,7 +105,7 @@ # sync primitives 'call_until', 'wait_for_pid', 'wait_for_file', # network - 'check_net_address', 'filter_proc_connections', + 'check_net_address', 'filter_proc_net_connections', 'get_free_port', 'bind_socket', 'bind_unix_socket', 'tcp_socketpair', 'unix_socketpair', 'create_sockets', # compat @@ -1884,7 +1884,7 @@ def check_status(conn): check_status(conn) -def filter_proc_connections(cons): +def filter_proc_net_connections(cons): """Our process may start with some open UNIX sockets which are not initialized by us, invalidating unit tests. """ diff --git a/psutil/tests/test_connections.py b/psutil/tests/test_connections.py index 0c56144610..ce3439e226 100755 --- a/psutil/tests/test_connections.py +++ b/psutil/tests/test_connections.py @@ -35,7 +35,7 @@ from psutil.tests import bind_unix_socket from psutil.tests import check_connection_ntuple from psutil.tests import create_sockets -from psutil.tests import filter_proc_connections +from psutil.tests import filter_proc_net_connections from psutil.tests import reap_children from psutil.tests import retry_on_failure from psutil.tests import serialrun @@ -48,21 +48,21 @@ SOCK_SEQPACKET = getattr(socket, "SOCK_SEQPACKET", object()) -def this_proc_connections(kind): +def this_proc_net_connections(kind): cons = psutil.Process().net_connections(kind=kind) if kind in ("all", "unix"): - return filter_proc_connections(cons) + return filter_proc_net_connections(cons) return cons @serialrun class ConnectionTestCase(PsutilTestCase): def setUp(self): - self.assertEqual(this_proc_connections(kind='all'), []) + self.assertEqual(this_proc_net_connections(kind='all'), []) def tearDown(self): # Make sure we closed all resources. - self.assertEqual(this_proc_connections(kind='all'), []) + self.assertEqual(this_proc_net_connections(kind='all'), []) def compare_procsys_connections(self, pid, proc_cons, kind='all'): """Given a process PID and its list of connections compare @@ -94,11 +94,11 @@ def test_system(self): def test_process(self): with create_sockets(): - for conn in this_proc_connections(kind='all'): + for conn in this_proc_net_connections(kind='all'): check_connection_ntuple(conn) def test_invalid_kind(self): - self.assertRaises(ValueError, this_proc_connections, kind='???') + self.assertRaises(ValueError, this_proc_net_connections, kind='???') self.assertRaises(ValueError, psutil.net_connections, kind='???') @@ -107,7 +107,7 @@ class TestUnconnectedSockets(ConnectionTestCase): """Tests sockets which are open but not connected to anything.""" def get_conn_from_sock(self, sock): - cons = this_proc_connections(kind='all') + cons = this_proc_net_connections(kind='all') smap = dict([(c.fd, c) for c in cons]) if NETBSD or FREEBSD: # NetBSD opens a UNIX socket to /var/log/run @@ -147,7 +147,7 @@ def check_socket(self, sock): # XXX Solaris can't retrieve system-wide UNIX sockets if sock.family == AF_UNIX and HAS_NET_CONNECTIONS_UNIX: - cons = this_proc_connections(kind='all') + cons = this_proc_net_connections(kind='all') self.compare_procsys_connections(os.getpid(), cons, kind='all') return conn @@ -209,17 +209,17 @@ class TestConnectedSocket(ConnectionTestCase): @unittest.skipIf(SUNOS, "unreliable on SUONS") def test_tcp(self): addr = ("127.0.0.1", 0) - self.assertEqual(this_proc_connections(kind='tcp4'), []) + self.assertEqual(this_proc_net_connections(kind='tcp4'), []) server, client = tcp_socketpair(AF_INET, addr=addr) try: - cons = this_proc_connections(kind='tcp4') + cons = this_proc_net_connections(kind='tcp4') self.assertEqual(len(cons), 2) self.assertEqual(cons[0].status, psutil.CONN_ESTABLISHED) self.assertEqual(cons[1].status, psutil.CONN_ESTABLISHED) # May not be fast enough to change state so it stays # commenteed. # client.close() - # cons = this_proc_connections(kind='all') + # cons = this_proc_net_connections(kind='all') # self.assertEqual(len(cons), 1) # self.assertEqual(cons[0].status, psutil.CONN_CLOSE_WAIT) finally: @@ -231,7 +231,7 @@ def test_unix(self): testfn = self.get_testfn() server, client = unix_socketpair(testfn) try: - cons = this_proc_connections(kind='unix') + cons = this_proc_net_connections(kind='unix') assert not (cons[0].laddr and cons[0].raddr), cons assert not (cons[1].laddr and cons[1].raddr), cons if NETBSD or FREEBSD: @@ -257,7 +257,7 @@ def test_unix(self): class TestFilters(ConnectionTestCase): def test_filters(self): def check(kind, families, types): - for conn in this_proc_connections(kind=kind): + for conn in this_proc_net_connections(kind=kind): self.assertIn(conn.family, families) self.assertIn(conn.type, types) if not SKIP_SYSCONS: @@ -428,48 +428,48 @@ def check_conn(proc, conn, family, type, laddr, raddr, status, kinds): def test_count(self): with create_sockets(): # tcp - cons = this_proc_connections(kind='tcp') + cons = this_proc_net_connections(kind='tcp') self.assertEqual(len(cons), 2 if supports_ipv6() else 1) for conn in cons: self.assertIn(conn.family, (AF_INET, AF_INET6)) self.assertEqual(conn.type, SOCK_STREAM) # tcp4 - cons = this_proc_connections(kind='tcp4') + cons = this_proc_net_connections(kind='tcp4') self.assertEqual(len(cons), 1) self.assertEqual(cons[0].family, AF_INET) self.assertEqual(cons[0].type, SOCK_STREAM) # tcp6 if supports_ipv6(): - cons = this_proc_connections(kind='tcp6') + cons = this_proc_net_connections(kind='tcp6') self.assertEqual(len(cons), 1) self.assertEqual(cons[0].family, AF_INET6) self.assertEqual(cons[0].type, SOCK_STREAM) # udp - cons = this_proc_connections(kind='udp') + cons = this_proc_net_connections(kind='udp') self.assertEqual(len(cons), 2 if supports_ipv6() else 1) for conn in cons: self.assertIn(conn.family, (AF_INET, AF_INET6)) self.assertEqual(conn.type, SOCK_DGRAM) # udp4 - cons = this_proc_connections(kind='udp4') + cons = this_proc_net_connections(kind='udp4') self.assertEqual(len(cons), 1) self.assertEqual(cons[0].family, AF_INET) self.assertEqual(cons[0].type, SOCK_DGRAM) # udp6 if supports_ipv6(): - cons = this_proc_connections(kind='udp6') + cons = this_proc_net_connections(kind='udp6') self.assertEqual(len(cons), 1) self.assertEqual(cons[0].family, AF_INET6) self.assertEqual(cons[0].type, SOCK_DGRAM) # inet - cons = this_proc_connections(kind='inet') + cons = this_proc_net_connections(kind='inet') self.assertEqual(len(cons), 4 if supports_ipv6() else 2) for conn in cons: self.assertIn(conn.family, (AF_INET, AF_INET6)) self.assertIn(conn.type, (SOCK_STREAM, SOCK_DGRAM)) # inet6 if supports_ipv6(): - cons = this_proc_connections(kind='inet6') + cons = this_proc_net_connections(kind='inet6') self.assertEqual(len(cons), 2) for conn in cons: self.assertEqual(conn.family, AF_INET6) @@ -477,7 +477,7 @@ def test_count(self): # Skipped on BSD becayse by default the Python process # creates a UNIX socket to '/var/run/log'. if HAS_NET_CONNECTIONS_UNIX and not (FREEBSD or NETBSD): - cons = this_proc_connections(kind='unix') + cons = this_proc_net_connections(kind='unix') self.assertEqual(len(cons), 3) for conn in cons: self.assertEqual(conn.family, AF_UNIX) diff --git a/psutil/tests/test_testutils.py b/psutil/tests/test_testutils.py index 6d8524fa96..17cc9eb085 100755 --- a/psutil/tests/test_testutils.py +++ b/psutil/tests/test_testutils.py @@ -36,7 +36,7 @@ from psutil.tests import call_until from psutil.tests import chdir from psutil.tests import create_sockets -from psutil.tests import filter_proc_connections +from psutil.tests import filter_proc_net_connections from psutil.tests import get_free_port from psutil.tests import is_namedtuple from psutil.tests import mock @@ -320,7 +320,7 @@ def test_unix_socketpair(self): p = psutil.Process() num_fds = p.num_fds() self.assertEqual( - filter_proc_connections(p.net_connections(kind='unix')), [] + filter_proc_net_connections(p.net_connections(kind='unix')), [] ) name = self.get_testfn() server, client = unix_socketpair(name) @@ -329,7 +329,10 @@ def test_unix_socketpair(self): assert stat.S_ISSOCK(os.stat(name).st_mode) self.assertEqual(p.num_fds() - num_fds, 2) self.assertEqual( - len(filter_proc_connections(p.net_connections(kind='unix'))), 2 + len( + filter_proc_net_connections(p.net_connections(kind='unix')) + ), + 2, ) self.assertEqual(server.getsockname(), name) self.assertEqual(client.getpeername(), name) diff --git a/psutil/tests/test_unicode.py b/psutil/tests/test_unicode.py index 81b44109be..7fb2ef1990 100755 --- a/psutil/tests/test_unicode.py +++ b/psutil/tests/test_unicode.py @@ -253,7 +253,7 @@ def test_proc_open_files(self): ) @unittest.skipIf(not POSIX, "POSIX only") - def test_proc_connections(self): + def test_proc_net_connections(self): name = self.get_testfn(suffix=self.funky_suffix) try: sock = bind_unix_socket(name)