forked from p15670423/monkey
Island, Common: Move singleton to code_utils.py in common
Singleton is a common pattern, potentially usable in the Agent so it belongs in common
This commit is contained in:
parent
fdf8198e7f
commit
65eb9b171b
|
@ -10,3 +10,12 @@ class abstractstatic(staticmethod):
|
|||
function.__isabstractmethod__ = True
|
||||
|
||||
__isabstractmethod__ = True
|
||||
|
||||
|
||||
class Singleton(type):
|
||||
_instances = {}
|
||||
|
||||
def __call__(cls, *args, **kwargs):
|
||||
if cls not in cls._instances:
|
||||
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
|
||||
return cls._instances[cls]
|
||||
|
|
|
@ -1,17 +1,10 @@
|
|||
import logging
|
||||
|
||||
from common.utils.code_utils import Singleton
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Singleton(type):
|
||||
_instances = {}
|
||||
|
||||
def __call__(cls, *args, **kwargs):
|
||||
if cls not in cls._instances:
|
||||
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
|
||||
return cls._instances[cls]
|
||||
|
||||
|
||||
class ReportExporterManager(object, metaclass=Singleton):
|
||||
def __init__(self):
|
||||
self._exporters_set = set()
|
||||
|
|
Loading…
Reference in New Issue