improve Attached

- allow a default value
- make copy method work properly
This commit is contained in:
l_samenv 2022-11-30 14:11:05 +01:00
parent d845fedc03
commit 9887ba0721

View File

@ -35,7 +35,7 @@ from secop.errors import BadValueError, CommunicationFailedError, ConfigError, \
from secop.lib import formatException, mkthread, UniqueObject, generalConfig
from secop.lib.enum import Enum
from secop.params import Accessible, Command, Parameter
from secop.properties import HasProperties, Property
from secop.properties import HasProperties, Property, UNSET
from secop.logging import RemoteLogHandler, HasComlog
generalConfig.set_default('disable_value_range_check', False) # check for problematic value range by default
@ -879,9 +879,10 @@ class Attached(Property):
assign a module name to this property in the cfg file,
and the server will create an attribute with this module
"""
def __init__(self, basecls=Module, description='attached module', mandatory=True):
def __init__(self, basecls=Module, description='attached module', mandatory=True,
default=UNSET):
self.basecls = basecls
super().__init__(description, StringType(), mandatory=mandatory)
super().__init__(description, StringType(), mandatory=mandatory, value=default)
def __get__(self, obj, owner):
if obj is None:
@ -891,3 +892,6 @@ class Attached(Property):
return super().__get__(obj, owner)
# return the module (called after startup)
return obj.attachedModules.get(self.name) # return None if not given
def copy(self):
return Attached(self.basecls, self.description, self.mandatory, self.value)