diff options
| author | Scott Bahling <sbahling@suse.com> | 2020-02-06 22:16:02 +0100 |
|---|---|---|
| committer | Scott Bahling <sbahling@suse.com> | 2020-02-06 22:35:43 +0100 |
| commit | cd12f43cd2c98826bb0ea092ef590a91e5842886 (patch) | |
| tree | fc13c2f90a9e3190ab172b1556dc1eb3caa124b4 /obsapi/helpers.py | |
| parent | c86fdd52a30ca1833149d46b7fee9135a74e4598 (diff) | |
| download | obsapi-cd12f43cd2c98826bb0ea092ef590a91e5842886.tar.gz obsapi-cd12f43cd2c98826bb0ea092ef590a91e5842886.tar.xz obsapi-cd12f43cd2c98826bb0ea092ef590a91e5842886.zip | |
Handle passing bytes to the FileInfo class
Move class to own file and enhance tests
Diffstat (limited to 'obsapi/helpers.py')
| -rw-r--r-- | obsapi/helpers.py | 23 |
1 files changed, 23 insertions, 0 deletions
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 |
