Code Duplication    Length = 19-20 lines in 2 locations

opcua/common/xmlimporter.py 2 locations

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