Code Duplication    Length = 19-20 lines in 2 locations

opcua/common/xmlimporter.py 2 locations

@@ 255-274 (lines=20) @@
252
                if name == "Text":
253
                    ltext.Text = val.encode("utf-8")
254
                else:
255
                    self.logger.warning("While parsing localizedText value, unkown element: %s with val: %s", name, val)
256
            return ua.Variant(ltext, ua.VariantType.LocalizedText)
257
        elif obj.valuetype == 'NodeId':
258
            return ua.Variant(ua.NodeId.from_string(obj.value))
259
        else:
260
            return ua.Variant(obj.value, getattr(ua.VariantType, obj.valuetype))
261
262
    def add_variable_type(self, obj):
263
        node = self._get_node(obj)
264
        attrs = ua.VariableTypeAttributes()
265
        if obj.desc:
266
            attrs.Description = ua.LocalizedText(obj.desc)
267
        attrs.DisplayName = ua.LocalizedText(obj.displayname)
268
        attrs.DataType = self.to_nodeid(obj.datatype)
269
        if obj.value and len(obj.value) == 1:
270
            attrs.Value = obj.value[0]
271
        if obj.rank:
272
            attrs.ValueRank = obj.rank
273
        if obj.abstract:
274
            attrs.IsAbstract = obj.abstract
275
        if obj.dimensions:
276
            attrs.ArrayDimensions = obj.dimensions
277
        node.NodeAttributes = attrs
@@ 276-294 (lines=19) @@
273
        if obj.abstract:
274
            attrs.IsAbstract = obj.abstract
275
        if obj.dimensions:
276
            attrs.ArrayDimensions = obj.dimensions
277
        node.NodeAttributes = attrs
278
        res = self.server.iserver.isession.add_nodes([node])
279
        self._add_refs(obj)
280
        res[0].StatusCode.check()
281
        return res[0].AddedNodeId
282
283
    def add_method(self, obj):
284
        node = self._get_node(obj)
285
        attrs = ua.MethodAttributes()
286
        if obj.desc:
287
            attrs.Description = ua.LocalizedText(obj.desc)
288
        attrs.DisplayName = ua.LocalizedText(obj.displayname)
289
        if obj.accesslevel:
290
            attrs.AccessLevel = obj.accesslevel
291
        if obj.useraccesslevel:
292
            attrs.UserAccessLevel = obj.useraccesslevel
293
        if obj.minsample:
294
            attrs.MinimumSamplingInterval = obj.minsample
295
        if obj.dimensions:
296
            attrs.ArrayDimensions = obj.dimensions
297
        node.NodeAttributes = attrs