Skip to content

Commit ecb8d47

Browse files
author
ldx
committed
Use separate function for Table6 avail checks.
1 parent a58c2a0 commit ecb8d47

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

iptc/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
.. moduleauthor:: Nilvec <[email protected]>
88
"""
99

10-
from ip4tc import Table, Chain, Rule, Match, Target, Policy, IPTCError
11-
from ip6tc import is_table_available, Table6, Rule6
10+
from ip4tc import (is_table_available, Table, Chain, Rule, Match, Target,
11+
Policy, IPTCError)
12+
from ip6tc import is_table6_available, Table6, Rule6
1213
from xtables import XTablesError
1314

1415
__all__ = []

iptc/ip6tc.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@
1515
_IFNAMSIZ = 16
1616

1717

18-
def is_table_available(name):
19-
try:
20-
Table(name)
21-
return True
22-
except IPTCError:
23-
pass
18+
def is_table6_available(name):
2419
try:
2520
Table6(name)
2621
return True
@@ -258,7 +253,7 @@ def save(self, name):
258253
return self._save(name, self.entry.ipv6)
259254

260255
def _get_tables(self):
261-
return [Table6(t) for t in Table6.ALL if is_table_available(t)]
256+
return [Table6(t) for t in Table6.ALL if is_table6_available(t)]
262257
tables = property(_get_tables)
263258
"""This is the list of tables for our protocol."""
264259

iptc/test/test_iptc.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
is_table_available = iptc.is_table_available
8+
is_table6_available = iptc.is_table6_available
89

910

1011
class TestTable6(unittest.TestCase):
@@ -16,20 +17,20 @@ def tearDown(self):
1617

1718
def test_table6(self):
1819
filt = None
19-
if is_table_available(iptc.Table6.FILTER):
20+
if is_table6_available(iptc.Table6.FILTER):
2021
filt = iptc.Table6("filter")
2122
self.assertEquals(id(filt), id(iptc.Table6(iptc.Table6.FILTER)))
2223
security = None
23-
if is_table_available(iptc.Table6.SECURITY):
24+
if is_table6_available(iptc.Table6.SECURITY):
2425
security = iptc.Table6("security")
2526
self.assertEquals(id(security),
2627
id(iptc.Table6(iptc.Table6.SECURITY)))
2728
mangle = None
28-
if is_table_available(iptc.Table6.MANGLE):
29+
if is_table6_available(iptc.Table6.MANGLE):
2930
mangle = iptc.Table6("mangle")
3031
self.assertEquals(id(mangle), id(iptc.Table6(iptc.Table6.MANGLE)))
3132
raw = None
32-
if is_table_available(iptc.Table6.RAW):
33+
if is_table6_available(iptc.Table6.RAW):
3334
raw = iptc.Table6("raw")
3435
self.assertEquals(id(raw), id(iptc.Table6(iptc.Table6.RAW)))
3536
if filt and security:
@@ -456,19 +457,19 @@ def test_rule_standard_target(self):
456457
self.chain.delete_rule(rule)
457458

458459
def test_rule_iterate(self):
459-
if is_table_available(iptc.Table6.FILTER):
460+
if is_table6_available(iptc.Table6.FILTER):
460461
for r in (rule for chain in iptc.Table6(iptc.Table6.FILTER).chains
461462
for rule in chain.rules if rule):
462463
pass
463-
if is_table_available(iptc.Table6.RAW):
464+
if is_table6_available(iptc.Table6.RAW):
464465
for r in (rule for chain in iptc.Table6(iptc.Table6.RAW).chains
465466
for rule in chain.rules if rule):
466467
pass
467-
if is_table_available(iptc.Table6.MANGLE):
468+
if is_table6_available(iptc.Table6.MANGLE):
468469
for r in (rule for chain in iptc.Table6(iptc.Table6.MANGLE).chains
469470
for rule in chain.rules if rule):
470471
pass
471-
if is_table_available(iptc.Table6.SECURITY):
472+
if is_table6_available(iptc.Table6.SECURITY):
472473
for r in (rule for chain in
473474
iptc.Table6(iptc.Table6.SECURITY).chains
474475
for rule in chain.rules if rule):

0 commit comments

Comments
 (0)