Browse Source

Minimal changes to document Singleton and class definitions it wraps

v0.6
Dmitri Bogomolov 3 years ago
parent
commit
c63ed02153
Signed by untrusted user: g1itch GPG Key ID: 720A756F18DEED13
  1. 6
      src/bmconfigparser.py
  2. 15
      src/singleton.py

6
src/bmconfigparser.py

@ -43,8 +43,10 @@ BMConfigDefaults = {
@Singleton
class BMConfigParser(ConfigParser.SafeConfigParser):
"""Singleton class inherited from ConfigParser.SafeConfigParser
with additional methods specific to bitmessage config."""
"""
Singleton class inherited from :class:`ConfigParser.SafeConfigParser`
with additional methods specific to bitmessage config.
"""
_temp = {}

15
src/singleton.py

@ -1,6 +1,21 @@
"""
Singleton decorator definition
"""
from functools import wraps
def Singleton(cls):
"""
Decorator implementing the singleton pattern:
it restricts the instantiation of a class to one "single" instance.
"""
instances = {}
# https://github.com/sphinx-doc/sphinx/issues/3783
@wraps(cls)
def getinstance():
"""Find an instance or save newly created one"""
if cls not in instances:
instances[cls] = cls()
return instances[cls]

Loading…
Cancel
Save