Code Duplication    Length = 16-19 lines in 3 locations

opcua/common/xmlimporter.py 3 locations

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