Commit 5f2c636c authored by Valentin Valls's avatar Valentin Valls
Browse files

Move inner class outside of the scope for readability

- Plus convention on class name
parent 08f7ab36
Pipeline #51760 passed with stages
in 107 minutes and 3 seconds
......@@ -13,6 +13,107 @@ from bliss.common import event
from bliss.common.utils import Null, autocomplete_property
class _ConfigGetter(property):
pass
class _Property(property):
def __init__(
self,
fget=None,
fset=None,
fdel=None,
doc=None,
must_be_in_config=False,
only_in_config=False,
default=Null,
priority=0,
set_marshalling=None,
set_unmarshalling=None,
):
try:
fget.__redefined__
except AttributeError:
if only_in_config:
def get(self):
self._initialize_with_setting()
return fget(self)
else:
def get(self):
self._initialize_with_setting()
if self._disabled_settings.get(fget.__name__):
return fget(self)
value = self._settings.get(fget.__name__)
if set_unmarshalling is not None:
value = set_unmarshalling(self, value)
return value if value is not None else fget(self)
get.__name__ = fget.__name__
get.__redefined__ = True
get.__default__ = default
get.__must_be_in_config__ = must_be_in_config or only_in_config
get.__only_in_config__ = only_in_config
get.__priority__ = priority
get.__set_marshalling__ = set_marshalling
get.__set_unmarshalling__ = set_unmarshalling
else:
must_be_in_config = fget.__must_be_in_config__
only_in_config = fget.__only_in_config__
default = fget.__default__
priority = fget.__priority__
set_marshalling = fget.__set_marshalling__
set_unmarshalling = fget.__set_unmarshalling__
get = fget
if fset is not None:
if only_in_config:
def set(self, value):
if not self._in_initialize_with_setting:
raise RuntimeError(f"parameter {fset.__name__} is read only.")
rvalue = fset(self, value)
self._event_channel.post(fset.__name__)
set.__name__ = fset.__name__
else:
fence = {"in_set": False}
def set(self, value):
if fence.get("in_set"):
return
try:
fence["in_set"] = True
self._initialize_with_setting()
if set_unmarshalling is not None:
value = set_unmarshalling(self, value)
rvalue = fset(self, value)
set_value = rvalue if rvalue is not None else value
if set_marshalling is not None:
set_value = set_marshalling(self, set_value)
try:
self._settings[fset.__name__] = set_value
except AttributeError:
self._initialize_with_setting(fset.__name__, set_value)
self._settings[fset.__name__] = set_value
self._event_channel.post(fset.__name__)
finally:
fence["in_set"] = False
set.__name__ = fset.__name__
else:
set = None
super().__init__(get, set, fdel, doc)
self.default = default
self.must_be_in_config = must_be_in_config
self.only_in_config = only_in_config
self.priority = priority
class BeaconObject:
"""
Object which handle shared properties from the configuration.
......@@ -29,106 +130,8 @@ class BeaconObject:
parameters will be done once per peer.
"""
class _config_getter(property):
pass
class _property(property):
def __init__(
self,
fget=None,
fset=None,
fdel=None,
doc=None,
must_be_in_config=False,
only_in_config=False,
default=Null,
priority=0,
set_marshalling=None,
set_unmarshalling=None,
):
try:
fget.__redefined__
except AttributeError:
if only_in_config:
def get(self):
self._initialize_with_setting()
return fget(self)
else:
def get(self):
self._initialize_with_setting()
if self._disabled_settings.get(fget.__name__):
return fget(self)
value = self._settings.get(fget.__name__)
if set_unmarshalling is not None:
value = set_unmarshalling(self, value)
return value if value is not None else fget(self)
get.__name__ = fget.__name__
get.__redefined__ = True
get.__default__ = default
get.__must_be_in_config__ = must_be_in_config or only_in_config
get.__only_in_config__ = only_in_config
get.__priority__ = priority
get.__set_marshalling__ = set_marshalling
get.__set_unmarshalling__ = set_unmarshalling
else:
must_be_in_config = fget.__must_be_in_config__
only_in_config = fget.__only_in_config__
default = fget.__default__
priority = fget.__priority__
set_marshalling = fget.__set_marshalling__
set_unmarshalling = fget.__set_unmarshalling__
get = fget
if fset is not None:
if only_in_config:
def set(self, value):
if not self._in_initialize_with_setting:
raise RuntimeError(
f"parameter {fset.__name__} is read only."
)
rvalue = fset(self, value)
self._event_channel.post(fset.__name__)
set.__name__ = fset.__name__
else:
fence = {"in_set": False}
def set(self, value):
if fence.get("in_set"):
return
try:
fence["in_set"] = True
self._initialize_with_setting()
if set_unmarshalling is not None:
value = set_unmarshalling(self, value)
rvalue = fset(self, value)
set_value = rvalue if rvalue is not None else value
if set_marshalling is not None:
set_value = set_marshalling(self, set_value)
try:
self._settings[fset.__name__] = set_value
except AttributeError:
self._initialize_with_setting(fset.__name__, set_value)
self._settings[fset.__name__] = set_value
self._event_channel.post(fset.__name__)
finally:
fence["in_set"] = False
set.__name__ = fset.__name__
else:
set = None
super().__init__(get, set, fdel, doc)
self.default = default
self.must_be_in_config = must_be_in_config
self.only_in_config = only_in_config
self.priority = priority
_config_getter = _ConfigGetter
_property = _Property
def __init__(
self,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment