Skip to content

Commit ecad90e

Browse files
authored
Remove unused ModbusAccessControl. (#989)
1 parent 2b63ddb commit ecad90e

File tree

2 files changed

+0
-93
lines changed

2 files changed

+0
-93
lines changed

pymodbus/device.py

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,69 +13,6 @@
1313
from pymodbus.utilities import dict_property
1414

1515

16-
# ---------------------------------------------------------------------------#
17-
# Network Access Control
18-
# ---------------------------------------------------------------------------#
19-
class ModbusAccessControl(Singleton):
20-
"""Simple implementation of a Network Management System table.
21-
22-
Its purpose is to control access to the server (if it is used).
23-
We assume that if an entry is in the table, it is allowed accesses to
24-
resources. However, if the host does not appear in the table (all
25-
unknown hosts) its connection will simply be closed.
26-
27-
Since it is a singleton, only one version can possible exist and all
28-
instances pull from here.
29-
"""
30-
31-
__nmstable = [
32-
"127.0.0.1",
33-
]
34-
35-
def __iter__(self):
36-
"""Iterate over the network access table.
37-
38-
:returns: An iterator of the network access table
39-
"""
40-
return self.__nmstable.__iter__()
41-
42-
def __contains__(self, host):
43-
"""Check if a host is allowed to access resources.
44-
45-
:param host: The host to check
46-
"""
47-
return host in self.__nmstable
48-
49-
def add(self, host):
50-
"""Add allowed host(s) from the NMS table.
51-
52-
:param host: The host to add
53-
"""
54-
if not isinstance(host, list):
55-
host = [host]
56-
for entry in host:
57-
if entry not in self.__nmstable:
58-
self.__nmstable.append(entry)
59-
60-
def remove(self, host):
61-
"""Remove allowed host(s) from the NMS table.
62-
63-
:param host: The host to remove
64-
"""
65-
if not isinstance(host, list):
66-
host = [host]
67-
for entry in host:
68-
if entry in self.__nmstable:
69-
self.__nmstable.remove(entry)
70-
71-
def check(self, host):
72-
"""Check if a host is allowed to access resources.
73-
74-
:param host: The host to check
75-
"""
76-
return host in self.__nmstable
77-
78-
7916
# ---------------------------------------------------------------------------#
8017
# Modbus Plus Statistics
8118
# ---------------------------------------------------------------------------#
@@ -657,7 +594,6 @@ def getDiagnosticRegister(self): # pylint: disable=invalid-name
657594
# Exported Identifiers
658595
# ---------------------------------------------------------------------------#
659596
__all__ = [
660-
"ModbusAccessControl",
661597
"ModbusPlusStatistics",
662598
"ModbusDeviceIdentification",
663599
"DeviceInformationFactory",

test/test_device.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from pymodbus.constants import DeviceInformation
66
from pymodbus.device import (
77
DeviceInformationFactory,
8-
ModbusAccessControl,
98
ModbusControlBlock,
109
ModbusDeviceIdentification,
1110
ModbusPlusStatistics,
@@ -43,14 +42,12 @@ def setUp(self):
4342
}
4443
self.ident = ModbusDeviceIdentification(self.info)
4544
self.control = ModbusControlBlock()
46-
self.access = ModbusAccessControl()
4745
self.control.reset()
4846

4947
def tearDown(self):
5048
"""Clean up the test environment"""
5149
del self.ident
5250
del self.control
53-
del self.access
5451

5552
def test_update_identity(self):
5653
"""Test device identification reading"""
@@ -272,32 +269,6 @@ def test_modbus_control_block_invalid_diagnostic(self):
272269
self.assertEqual(None, self.control.getDiagnostic(None))
273270
self.assertEqual(None, self.control.getDiagnostic([1, 2, 3]))
274271

275-
def test_add_remove__single_clients(self):
276-
"""Test adding and removing a host"""
277-
self.assertFalse(self.access.check("192.168.1.1"))
278-
self.access.add("192.168.1.1")
279-
self.assertTrue(self.access.check("192.168.1.1"))
280-
self.access.add("192.168.1.1")
281-
self.access.remove("192.168.1.1")
282-
self.assertFalse(self.access.check("192.168.1.1"))
283-
284-
def test_add_remove_multiple_clients(self):
285-
"""Test adding and removing a host"""
286-
clients = ["192.168.1.1", "192.168.1.2", "192.168.1.3"]
287-
self.access.add(clients)
288-
for host in clients:
289-
self.assertTrue(self.access.check(host))
290-
self.access.remove(clients)
291-
292-
def test_network_access_list_iterator(self):
293-
"""Test adding and removing a host"""
294-
clients = ["127.0.0.1", "192.168.1.1", "192.168.1.2", "192.168.1.3"]
295-
self.access.add(clients)
296-
for host in self.access:
297-
self.assertTrue(host in clients)
298-
for host in clients:
299-
self.assertTrue(host in self.access)
300-
301272
def test_clearing_control_events(self):
302273
"""Test adding and clearing modbus events"""
303274
self.assertEqual(self.control.Events, [])

0 commit comments

Comments
 (0)