From 99bdafdd0c3293d17e3f23508d2b7762804474e7 Mon Sep 17 00:00:00 2001 From: l_samenv Date: Tue, 8 Sep 2020 13:33:13 +0200 Subject: [PATCH] support name mangling for parameter/command names --- secop/client/__init__.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/secop/client/__init__.py b/secop/client/__init__.py index 27d53fd..fba9cb1 100644 --- a/secop/client/__init__.py +++ b/secop/client/__init__.py @@ -457,8 +457,7 @@ class SecopClient(ProxyClient): modules = data['modules'] self.modules = {} self.properties = {k: v for k, v in data.items() if k != 'modules'} - self.identifier = {} # map (module, parameter) -> identifier - self.internal = {} # map identifier -> (module, parameter) + self.identifier = defaultdict(dict) # dict of dict of for modname, moddescr in modules.items(): # separate accessibles into command and parameters parameters = {} @@ -469,8 +468,7 @@ class SecopClient(ProxyClient): datatype = get_datatype(aentry['datainfo'], iname) aentry = dict(aentry, datatype=datatype) ident = '%s:%s' % (modname, aname) - self.identifier[modname, iname] = ident - self.internal[ident] = modname, iname + self.identifier[modname][iname] = ident if datatype.IS_COMMAND: commands[iname] = aentry else: @@ -478,6 +476,11 @@ class SecopClient(ProxyClient): properties = {k: v for k, v in moddescr.items() if k != 'accessibles'} self.modules[modname] = dict(accessibles=accessibles, parameters=parameters, commands=commands, properties=properties) + self.fix_internal_names() + # invert self.identifier + self.internal = {ident: (modname, iname) + for modname, identdict in self.identifier.items() + for iname, ident in identdict.items()} if changed_modules is not None: done = done_main = self.callback(None, 'descriptiveDataChange', None, self) for mname in changed_modules: @@ -534,7 +537,7 @@ class SecopClient(ProxyClient): def readParameter(self, module, parameter): """forced read over connection""" try: - self.request(READREQUEST, self.identifier[module, parameter]) + self.request(READREQUEST, self.identifier[module][parameter]) except secop.errors.SECoPError: # error reply message is already stored as readerror in cache pass @@ -553,7 +556,7 @@ class SecopClient(ProxyClient): self.connect() # make sure we are connected datatype = self.modules[module]['parameters'][parameter]['datatype'] value = datatype.export_value(value) - self.request(WRITEREQUEST, self.identifier[module, parameter], value) + self.request(WRITEREQUEST, self.identifier[module][parameter], value) return self.cache[module, parameter] def execCommand(self, module, command, argument=None): @@ -565,7 +568,7 @@ class SecopClient(ProxyClient): if argument is not None: raise secop.errors.BadValueError('command has no argument') # pylint: disable=unsubscriptable-object - data, qualifiers = self.request(COMMANDREQUEST, self.identifier[module, command], argument)[2] + data, qualifiers = self.request(COMMANDREQUEST, self.identifier[module][command], argument)[2] datatype = self.modules[module]['commands'][command]['datatype'].result if datatype: data = datatype.import_value(data) @@ -587,3 +590,6 @@ class SecopClient(ProxyClient): if name.startswith('_') and name[1:] not in self.PREDEFINED_NAMES: return name[1:] return name + + def fix_internal_names(self): + """fix forbidden items"""