Minimal changes to document Singleton and class definitions it wraps
This commit is contained in:
parent
86f0860cb2
commit
c63ed02153
|
@ -43,8 +43,10 @@ BMConfigDefaults = {
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class BMConfigParser(ConfigParser.SafeConfigParser):
|
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 = {}
|
_temp = {}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,21 @@
|
||||||
|
"""
|
||||||
|
Singleton decorator definition
|
||||||
|
"""
|
||||||
|
|
||||||
|
from functools import wraps
|
||||||
|
|
||||||
|
|
||||||
def Singleton(cls):
|
def Singleton(cls):
|
||||||
|
"""
|
||||||
|
Decorator implementing the singleton pattern:
|
||||||
|
it restricts the instantiation of a class to one "single" instance.
|
||||||
|
"""
|
||||||
instances = {}
|
instances = {}
|
||||||
|
|
||||||
|
# https://github.com/sphinx-doc/sphinx/issues/3783
|
||||||
|
@wraps(cls)
|
||||||
def getinstance():
|
def getinstance():
|
||||||
|
"""Find an instance or save newly created one"""
|
||||||
if cls not in instances:
|
if cls not in instances:
|
||||||
instances[cls] = cls()
|
instances[cls] = cls()
|
||||||
return instances[cls]
|
return instances[cls]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user