]> git.lizzy.rs Git - nhentai.git/blob - nhentai/utils.py
implemented Py2 & Py3 compatible Singleton
[nhentai.git] / nhentai / utils.py
1 # coding: utf-8
2 class _Singleton(type):
3     """ A metaclass that creates a Singleton base class when called. """
4     _instances = {}
5     def __call__(cls, *args, **kwargs):
6         if cls not in cls._instances:
7             cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
8         return cls._instances[cls]
9
10 class Singleton(_Singleton('SingletonMeta', (object,), {})): pass