From 9887ba072174cc012dab3944d588915d428d9be7 Mon Sep 17 00:00:00 2001 From: l_samenv Date: Wed, 30 Nov 2022 14:11:05 +0100 Subject: [PATCH] improve Attached - allow a default value - make copy method work properly --- secop/modules.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/secop/modules.py b/secop/modules.py index 78f5b13..d75c3b2 100644 --- a/secop/modules.py +++ b/secop/modules.py @@ -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)