Skip to content

Commit

Permalink
Make Table6 a true singleton.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldx committed Apr 13, 2013
1 parent e167818 commit 8def4a9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions iptc/ip6tc.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,16 +576,19 @@ class Table6(Table):

_cache = weakref.WeakValueDictionary()

def __new__(cls, name, autocommit=True):
def __new__(cls, name, autocommit=None):
obj = Table6._cache.get(name, None)
if not obj:
obj = object.__new__(cls)
if autocommit is None:
autocommit = True
obj._init(name, autocommit)
Table6._cache[name] = obj
else:
elif autocommit is not None:
obj.autocommit = autocommit
return obj

def __init__(self, name, autocommit=True):
def _init(self, name, autocommit):
"""
Here *name* is the name of the table to instantiate, if it has already
been instantiated the existing cached object is returned.
Expand Down

0 comments on commit 8def4a9

Please sign in to comment.