From cd12f43cd2c98826bb0ea092ef590a91e5842886 Mon Sep 17 00:00:00 2001 From: Scott Bahling Date: Thu, 6 Feb 2020 22:16:02 +0100 Subject: Handle passing bytes to the FileInfo class Move class to own file and enhance tests --- obsapi/helpers.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 obsapi/helpers.py (limited to 'obsapi/helpers.py') diff --git a/obsapi/helpers.py b/obsapi/helpers.py new file mode 100644 index 0000000..6912035 --- /dev/null +++ b/obsapi/helpers.py @@ -0,0 +1,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 -- cgit v1.2.3