Source code for exo_k.util.singleton

"""Just contains a singleton class. Pretty useful. Class taken from taurex 3. """


[docs] class Singleton(object): """ A singleton for your usage. When inheriting do not implement __init__ instead override :func:`init` """ def __new__(cls, *args, **kwds): it = cls.__dict__.get("__it__") if it is not None: return it cls.__it__ = it = object.__new__(cls) it.init(*args, **kwds) return it
[docs] def init(self, *args, **kwds): """ Override to act as an init """ raise NotImplementedError
[docs] @classmethod def reset_singleton(cls): """Reset the internal state of a singleton""" cls.__it__ = None