Code Duplication    Length = 16-19 lines in 3 locations

opcua/common/xmlimporter.py 3 locations

@@ 295-312 (lines=18) @@
292
            attrs.IsAbstract = obj.abstract
293
        if obj.dimensions:
294
            attrs.ArrayDimensions = obj.dimensions
295
        node.NodeAttributes = attrs
296
        res = self.server.add_nodes([node])
297
        self._add_refs(obj)
298
        return res[0].AddedNodeId
299
300
    def add_method(self, obj):
301
        node = self._get_node(obj)
302
        attrs = ua.MethodAttributes()
303
        if obj.desc:
304
            attrs.Description = ua.LocalizedText(obj.desc)
305
        attrs.DisplayName = ua.LocalizedText(obj.displayname)
306
        if obj.accesslevel:
307
            attrs.AccessLevel = obj.accesslevel
308
        if obj.useraccesslevel:
309
            attrs.UserAccessLevel = obj.useraccesslevel
310
        if obj.minsample:
311
            attrs.MinimumSamplingInterval = obj.minsample
312
        if obj.dimensions:
313
            attrs.ArrayDimensions = obj.dimensions
314
        node.NodeAttributes = attrs
315
        res = self.server.add_nodes([node])
@@ 314-329 (lines=16) @@
311
            attrs.MinimumSamplingInterval = obj.minsample
312
        if obj.dimensions:
313
            attrs.ArrayDimensions = obj.dimensions
314
        node.NodeAttributes = attrs
315
        res = self.server.add_nodes([node])
316
        self._add_refs(obj)
317
        return res[0].AddedNodeId
318
319
    def add_reference_type(self, obj):
320
        node = self._get_node(obj)
321
        attrs = ua.ReferenceTypeAttributes()
322
        if obj.desc:
323
            attrs.Description = ua.LocalizedText(obj.desc)
324
        attrs.DisplayName = ua.LocalizedText(obj.displayname)
325
        if obj. inversename:
326
            attrs.InverseName = ua.LocalizedText(obj.inversename)
327
        if obj.abstract:
328
            attrs.IsAbstract = obj.abstract
329
        if obj.symmetric:
330
            attrs.Symmetric = obj.symmetric
331
        node.NodeAttributes = attrs
332
        res = self.server.add_nodes([node])
@@ 275-293 (lines=19) @@
272
            return ua.Variant(extobj, getattr(ua.VariantType, obj.valuetype))
273
        elif obj.valuetype == 'DateTime':
274
            return ua.Variant(dateutil.parser.parse(obj.value), getattr(ua.VariantType, obj.valuetype))
275
        elif obj.valuetype == 'Guid':
276
            return ua.Variant(uuid.UUID(obj.value), getattr(ua.VariantType, obj.valuetype))
277
        else:
278
            return ua.Variant(obj.value, getattr(ua.VariantType, obj.valuetype))
279
280
    def add_variable_type(self, obj):
281
        node = self._get_node(obj)
282
        attrs = ua.VariableTypeAttributes()
283
        if obj.desc:
284
            attrs.Description = ua.LocalizedText(obj.desc)
285
        attrs.DisplayName = ua.LocalizedText(obj.displayname)
286
        attrs.DataType = self.to_nodeid(obj.datatype)
287
        if obj.value and len(obj.value) == 1:
288
            attrs.Value = obj.value[0]
289
        if obj.rank:
290
            attrs.ValueRank = obj.rank
291
        if obj.abstract:
292
            attrs.IsAbstract = obj.abstract
293
        if obj.dimensions:
294
            attrs.ArrayDimensions = obj.dimensions
295
        node.NodeAttributes = attrs
296
        res = self.server.add_nodes([node])