NodeconQuery: Make ipaddress module usage unconditional.

Closes #107
This commit is contained in:
Chris PeBenito 2017-09-14 21:29:57 -04:00
parent 904a83b27e
commit bfa50a42f8
3 changed files with 4 additions and 27 deletions

View File

@ -16,10 +16,7 @@
# License along with SETools. If not, see
# <http://www.gnu.org/licenses/>.
#
try:
import ipaddress
except ImportError: # pragma: no cover
pass
import ipaddress
import logging
from socket import AF_INET, AF_INET6
@ -87,10 +84,7 @@ class NodeconQuery(MatchContext, PolicyQuery):
@network.setter
def network(self, value):
if value:
try:
self._network = ipaddress.ip_network(value)
except NameError: # pragma: no cover
raise RuntimeError("Nodecon IP address/network functions require Python 3.3+.")
self._network = ipaddress.ip_network(value)
else:
self._network = None
@ -108,14 +102,9 @@ class NodeconQuery(MatchContext, PolicyQuery):
for nodecon in self.policy.nodecons():
if self.network:
try:
netmask = ipaddress.ip_address(nodecon.netmask)
except NameError: # pragma: no cover
# Should never actually hit this since the self.network
# setter raises the same exception.
raise RuntimeError("Nodecon IP address/network functions require Python 3.3+.")
netmask = ipaddress.ip_address(nodecon.netmask)
# Python 3.3's IPv6Network constructor does not support
# Python 3.4's IPv6Network constructor does not support
# expanded netmasks, only CIDR numbers. Convert netmask
# into CIDR.
# This is Brian Kernighan's method for counting set bits.

View File

@ -126,14 +126,6 @@ class NodeconQueryTab(AnalysisTab):
self.criteria_frame.setHidden(not self.criteria_expander.isChecked())
self.notes.setHidden(not self.notes_expander.isChecked())
# Network criteria is available only on Python 3.3+
if sys.version_info < (3, 3):
self.network_criteria.setEnabled(False)
self.network_criteria.setToolTip("This feature requires Python 3.3 or newer.")
self.network.setToolTip("This feature requires Python 3.3 or newer.")
self.network_exact.setToolTip("This feature requires Python 3.3 or newer.")
self.network_overlap.setToolTip("This feature requires Python 3.3 or newer.")
# Range criteria is available only if policy is MLS
if not self.policy.mls:
self.range_criteria.setEnabled(False)

View File

@ -213,7 +213,6 @@ class NodeconQueryTest(unittest.TestCase):
nodecons = sorted(n.address for n in q.results())
self.assertListEqual(["10.1.55.1"], nodecons)
@unittest.skipIf(sys.version_info < (3, 3), "Requires Python 3.3+.")
def test_100_v4network_equal(self):
"""Nodecon query with IPv4 equal network"""
q = NodeconQuery(self.p, network="10.1.100.0/24", network_overlap=False)
@ -221,7 +220,6 @@ class NodeconQueryTest(unittest.TestCase):
nodecons = sorted(n.address for n in q.results())
self.assertListEqual(["10.1.100.0"], nodecons)
@unittest.skipIf(sys.version_info < (3, 3), "Requires Python 3.3+.")
def test_101_v4network_overlap(self):
"""Nodecon query with IPv4 network overlap"""
q = NodeconQuery(self.p, network="10.1.101.128/25", network_overlap=True)
@ -229,7 +227,6 @@ class NodeconQueryTest(unittest.TestCase):
nodecons = sorted(n.address for n in q.results())
self.assertListEqual(["10.1.101.0"], nodecons)
@unittest.skipIf(sys.version_info < (3, 3), "Requires Python 3.3+.")
def test_110_v6network_equal(self):
"""Nodecon query with IPv6 equal network"""
q = NodeconQuery(self.p, network="1100::/16", network_overlap=False)
@ -237,7 +234,6 @@ class NodeconQueryTest(unittest.TestCase):
nodecons = sorted(n.address for n in q.results())
self.assertListEqual(["1100::"], nodecons)
@unittest.skipIf(sys.version_info < (3, 3), "Requires Python 3.3+.")
def test_111_v6network_overlap(self):
"""Nodecon query with IPv6 network overlap"""
q = NodeconQuery(self.p, network="1110:8000::/17", network_overlap=True)