Code Duplication    Length = 16-18 lines in 2 locations

opcua/common/xmlimporter.py 2 locations

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