summaryrefslogtreecommitdiff
path: root/obsapi/helpers.py
blob: 6912035cb31748d1878968b83fd34f407057d015 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# -*- coding: utf-8 -*-
"""
    obsapi: helper module
    ~~~~~~~~~~~~~~~~~~~~~

    This module contains helper functions


    :copyright: Copyright (c) 2020 Scott Bahling, SUSE Linux GmbH
    :license: GPL-2.0, see COPYING for details
"""
from io import BytesIO
from lxml import etree


def xml2etree(xml):
    try:
        if not isinstance(xml, bytes):
            xml = xml.encode('utf-8')
        parser = etree.XMLParser(remove_blank_text=True)
        return etree.parse(BytesIO(xml), parser).xpath('.')[0]
    except Exception as e:
        raise e