Code Duplication    Length = 16-18 lines in 2 locations

opcua/common/xmlimporter.py 2 locations

@@ 219-236 (lines=18) @@
216
        node.NodeAttributes = attrs
217
        res = self.server.add_nodes([node])
218
        self._add_refs(obj)
219
        return res[0].AddedNodeId
220
221
    def _make_ext_obj(sefl, obj):
222
        ext = getattr(ua, obj.objname)()
223
        for name, val in obj.body:
224
            if type(val) is str:
225
                raise Exception("Error val should a dict", name, val)
226
            else:
227
                for attname, v in val:
228
                    # tow possible values:
229
                    # either we get value directly
230
                    # or a dict if it s an object or a list
231
                    if type(v) is str:
232
                        setattr(ext, attname, to_python(v, ext, attname))
233
                    else:
234
                        # so we habve either an object or a list...
235
                        obj2 = getattr(ext, attname)
236
                        if isinstance(obj2, ua.NodeId):
237
                            for attname2, v2 in v:
238
                                if attname2 == "Identifier":
239
                                    obj2 = ua.NodeId.from_string(v2)
@@ 238-253 (lines=16) @@
235
                        obj2 = getattr(ext, attname)
236
                        if isinstance(obj2, ua.NodeId):
237
                            for attname2, v2 in v:
238
                                if attname2 == "Identifier":
239
                                    obj2 = ua.NodeId.from_string(v2)
240
                                    setattr(ext, attname, obj2)
241
                                    break
242
                        elif not isinstance(obj2, ua.NodeId) and not hasattr(obj2, "ua_types"):
243
                            # we probably have a list
244
                            my_list = []
245
                            for vtype, v2 in v:
246
                                my_list.append(ua_type_to_python(v2, vtype))
247
                            setattr(ext, attname, my_list)
248
                        else:
249
                            for attname2, v2 in v:
250
                                setattr(obj2, attname2, to_python(v2, obj2, attname2))
251
                            setattr(ext, attname, obj2)
252
        return ext
253
254
    def _add_variable_value(self, obj):
255
        """
256
        Returns the value for a Variable based on the objects valuetype.