Skip to content

Commit 4576bdf

Browse files
author
ldx
committed
Don't overwrite Table.autocommit.
When a new Table or Table6 is instantiated, don't reset its autocommit attribute. This commit also fixes Table to properly use a singleton. Fixes #23.
1 parent 51f4214 commit 4576bdf

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

iptc/ip4tc.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,16 +1284,19 @@ class Table(object):
12841284

12851285
_cache = weakref.WeakValueDictionary()
12861286

1287-
def __new__(cls, name, autocommit=True):
1287+
def __new__(cls, name, autocommit=None):
12881288
obj = Table._cache.get(name, None)
12891289
if not obj:
12901290
obj = object.__new__(cls)
1291+
if autocommit is None:
1292+
autocommit = True
1293+
obj._init(name, autocommit)
12911294
Table._cache[name] = obj
1292-
else:
1295+
elif autocommit is not None:
12931296
obj.autocommit = autocommit
12941297
return obj
12951298

1296-
def __init__(self, name, autocommit=True):
1299+
def _init(self, name, autocommit):
12971300
"""
12981301
*name* is the name of the table, if it already exists it is returned.
12991302
*autocommit* specifies that any iptables operation that changes a

0 commit comments

Comments
 (0)