Skip to content

Commit 7bdd451

Browse files
committed
moved dict to static class variable
1 parent b7c071a commit 7bdd451

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

iptc/ip4tc.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,16 @@
4040
xtables(NFPROTO_IPV4)
4141

4242

43-
exist_table_names = dict() # Dictionary to check faster if table is available
44-
4543
def is_table_available(name):
46-
global exist_table_names
4744
try:
48-
if name in exist_table_names:
49-
return exist_table_names[name]
45+
if name in Table.existing_table_names:
46+
return Table.existing_table_names[name]
5047
Table(name)
51-
exist_table_names[name] = True
48+
Table.existing_table_names[name] = True
5249
return True
5350
except IPTCError:
5451
pass
55-
exist_table_names[name] = False
52+
Table.existing_table_names[name] = False
5653
return False
5754

5855

@@ -1586,6 +1583,8 @@ class Table(object):
15861583
"""This is the constant for all tables."""
15871584

15881585
_cache = dict()
1586+
existing_table_names = dict()
1587+
"""Dictionary to check faster if a table is available."""
15891588

15901589
def __new__(cls, name, autocommit=None):
15911590
obj = Table._cache.get(name, None)

iptc/ip6tc.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,16 @@
1717
_IFNAMSIZ = 16
1818

1919

20-
exist_table6_names = dict() # Dictionary to check faster if table is available
21-
2220
def is_table6_available(name):
23-
global exist_table6_names
2421
try:
25-
if name in exist_table6_names:
26-
return exist_table6_names[name]
22+
if name in Table6.existing_table_names:
23+
return Table6.existing_table_names[name]
2724
Table6(name)
28-
exist_table6_names[name] = True
25+
Table6.existing_table_names[name] = True
2926
return True
3027
except IPTCError:
3128
pass
32-
exist_table6_names[name] = False
29+
Table6.existing_table_names[name] = False
3330
return False
3431

3532

@@ -586,6 +583,8 @@ class Table6(Table):
586583
"""This is the constant for all tables."""
587584

588585
_cache = dict()
586+
existing_table_names = dict()
587+
"""Dictionary to check faster if a table is available."""
589588

590589
def __new__(cls, name, autocommit=None):
591590
obj = Table6._cache.get(name, None)

0 commit comments

Comments
 (0)