__init__.py 426 字节
Newer Older
P
peng.xu 已提交
1 2 3 4 5 6 7 8 9 10 11
from functools import wraps


def singleton(cls):
    instances = {}
    @wraps(cls)
    def getinstance(*args, **kw):
        if cls not in instances:
            instances[cls] = cls(*args, **kw)
        return instances[cls]
    return getinstance
P
peng.xu 已提交
12 13 14 15 16 17 18


class dotdict(dict):
    """dot.notation access to dictionary attributes"""
    __getattr__ = dict.get
    __setattr__ = dict.__setitem__
    __delattr__ = dict.__delitem__