Code Duplication    Length = 12-13 lines in 3 locations

opcua/common/xmlimporter.py 3 locations

@@ 313-325 (lines=13) @@
310
        if obj.desc:
311
            attrs.Description = ua.LocalizedText(obj.desc)
312
        attrs.DisplayName = ua.LocalizedText(obj.displayname)
313
        if obj.abstract:
314
            attrs.IsAbstract = obj.abstract
315
        node.NodeAttributes = attrs
316
        res = self.server.iserver.isession.add_nodes([node])
317
        self._add_refs(obj)
318
        res[0].StatusCode.check()
319
        return res[0].AddedNodeId
320
321
    def _add_refs(self, obj):
322
        if not obj.refs:
323
            return
324
        refs = []
325
        for data in obj.refs:
326
            ref = ua.AddReferencesItem()
327
            ref.IsForward = True
328
            ref.ReferenceTypeId = self.to_nodeid(data.reftype)
@@ 159-170 (lines=12) @@
156
        node = self._get_node(obj)
157
        attrs = ua.ObjectTypeAttributes()
158
        if obj.desc:
159
            attrs.Description = ua.LocalizedText(obj.desc)
160
        attrs.DisplayName = ua.LocalizedText(obj.displayname)
161
        attrs.IsAbstract = obj.abstract
162
        node.NodeAttributes = attrs
163
        res = self.server.iserver.isession.add_nodes([node])
164
        self._add_refs(obj)
165
        res[0].StatusCode.check()
166
        return res[0].AddedNodeId
167
168
    def add_variable(self, obj):
169
        node = self._get_node(obj)
170
        attrs = ua.VariableAttributes()
171
        if obj.desc:
172
            attrs.Description = ua.LocalizedText(obj.desc)
173
        attrs.DisplayName = ua.LocalizedText(obj.displayname)
@@ 146-157 (lines=12) @@
143
        node = self._get_node(obj)
144
        attrs = ua.ObjectAttributes()
145
        if obj.desc:
146
            attrs.Description = ua.LocalizedText(obj.desc)
147
        attrs.DisplayName = ua.LocalizedText(obj.displayname)
148
        attrs.EventNotifier = obj.eventnotifier
149
        node.NodeAttributes = attrs
150
        res = self.server.iserver.isession.add_nodes([node])
151
        self._add_refs(obj)
152
        res[0].StatusCode.check()
153
        return res[0].AddedNodeId
154
155
    def add_object_type(self, obj):
156
        node = self._get_node(obj)
157
        attrs = ua.ObjectTypeAttributes()
158
        if obj.desc:
159
            attrs.Description = ua.LocalizedText(obj.desc)
160
        attrs.DisplayName = ua.LocalizedText(obj.displayname)