Skip to content

Commit

Permalink
more renames (C modules)
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Apr 17, 2024
1 parent c625ef9 commit 122363a
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 39 deletions.
2 changes: 1 addition & 1 deletion psutil/_psbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion psutil/_psosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion psutil/_psutil_bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion psutil/_psutil_osx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion psutil/arch/freebsd/proc_socks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion psutil/arch/freebsd/proc_socks.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

#include <Python.h>

PyObject* psutil_proc_connections(PyObject* self, PyObject* args);
PyObject* psutil_proc_net_connections(PyObject* self, PyObject* args);
2 changes: 1 addition & 1 deletion psutil/arch/netbsd/proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion psutil/arch/netbsd/socks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
2 changes: 1 addition & 1 deletion psutil/arch/osx/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion psutil/arch/osx/proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
"""
Expand Down
46 changes: 23 additions & 23 deletions psutil/tests/test_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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='???')


Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -428,56 +428,56 @@ 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)
self.assertIn(conn.type, (SOCK_STREAM, SOCK_DGRAM))
# 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)
Expand Down
9 changes: 6 additions & 3 deletions psutil/tests/test_testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 122363a

Please sign in to comment.