Code Duplication    Length = 16-18 lines in 2 locations

opcua/common/xmlimporter.py 2 locations

@@ 219-236 (lines=18) @@
216
        node = self._get_node(obj)
217
        attrs = ua.ReferenceTypeAttributes()
218
        if obj.desc:
219
            attrs.Description = ua.LocalizedText(obj.desc)
220
        attrs.DisplayName = ua.LocalizedText(obj.displayname)
221
        if obj. inversename:
222
            attrs.InverseName = ua.LocalizedText(obj.inversename)
223
        if obj.abstract:
224
            attrs.IsAbstract = obj.abstract
225
        if obj.symmetric:
226
            attrs.Symmetric = obj.symmetric
227
        node.NodeAttributes = attrs
228
        res = self.server.add_nodes([node])
229
        self._add_refs(obj)
230
        return res[0].AddedNodeId
231
232
    def add_datatype(self, obj):
233
        node = self._get_node(obj)
234
        attrs = ua.DataTypeAttributes()
235
        if obj.desc:
236
            attrs.Description = ua.LocalizedText(obj.desc)
237
        attrs.DisplayName = ua.LocalizedText(obj.displayname)
238
        if obj.abstract:
239
            attrs.IsAbstract = obj.abstract
@@ 238-253 (lines=16) @@
235
        if obj.desc:
236
            attrs.Description = ua.LocalizedText(obj.desc)
237
        attrs.DisplayName = ua.LocalizedText(obj.displayname)
238
        if obj.abstract:
239
            attrs.IsAbstract = obj.abstract
240
        node.NodeAttributes = attrs
241
        res = self.server.add_nodes([node])
242
        self._add_refs(obj)
243
        return res[0].AddedNodeId
244
245
    def _add_refs(self, obj):
246
        if not obj.refs:
247
            return
248
        refs = []
249
        for data in obj.refs:
250
            ref = ua.AddReferencesItem()
251
            ref.IsForward = True
252
            ref.ReferenceTypeId = self.to_nodeid(data.reftype)
253
            ref.SourceNodeId = ua.NodeId.from_string(obj.nodeid)
254
            ref.TargetNodeClass = ua.NodeClass.DataType
255
            ref.TargetNodeId = ua.NodeId.from_string(data.target)
256
            refs.append(ref)