Some cleanups. (0.25.1)
This commit is contained in:
parent
1b11cfdadc
commit
c1241ccf43
2 changed files with 0 additions and 62 deletions
|
|
@ -1,14 +0,0 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2013-2023 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE.
|
||||
"""
|
||||
|
||||
# This class can maybe be used for a general data model for Linspector data processing. currently
|
||||
# the is no use for it and no place known where it could be used with sense.
|
||||
class Model:
|
||||
|
||||
def __init__(self, configuration, environment, log):
|
||||
self._configuration = configuration
|
||||
self._environment = environment
|
||||
self._log = log
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2013-2023 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE.
|
||||
"""
|
||||
|
||||
# see http://stackoverflow.com/questions/42558/python-and-the-singleton-pattern
|
||||
|
||||
|
||||
class Singleton:
|
||||
"""
|
||||
A non-thread-safe helper class to ease implementing singletons.
|
||||
This should be used as a decorator -- not a metaclass -- to the
|
||||
class that should be a singleton.
|
||||
|
||||
The decorated class can define one `__init__` function that
|
||||
takes only the `self` argument. Other than that, there are
|
||||
no restrictions that apply to the decorated class.
|
||||
|
||||
To get the singleton instance, use the `Instance` method. Trying
|
||||
to use `_call_` will result in a `TypeError` being raised.
|
||||
|
||||
Limitations: The decorated class cannot be inherited from.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, decorated):
|
||||
self._decorated = decorated
|
||||
self._instance = None
|
||||
|
||||
def instance(self):
|
||||
"""
|
||||
Returns the singleton instance. Upon its first call, it creates a
|
||||
new instance of the decorated class and calls its `__init__` method.
|
||||
On all subsequent calls, the already created instance is returned.
|
||||
|
||||
"""
|
||||
try:
|
||||
return self._instance
|
||||
except AttributeError:
|
||||
self._instance = self._decorated()
|
||||
return self._instance
|
||||
|
||||
def _call_(self):
|
||||
raise TypeError('Singletons must be accessed through `Instance()`.')
|
||||
|
||||
def _instancecheck_(self, inst):
|
||||
return isinstance(inst, self._decorated)
|
||||
Loading…
Add table
Add a link
Reference in a new issue