From: Aaron Bauman <bman@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Cc: Aaron Bauman <bman@gentoo.org>
Subject: [gentoo-portage-dev] [PATCH] lib/portage/xml/metadata.py: fix ungrouped-imports w/refactor
Date: Thu, 6 Aug 2020 19:28:13 -0400 [thread overview]
Message-ID: <20200806232813.1977027-1-bman@gentoo.org> (raw)
* This drops the import for cElementTree as it is deprecated. See:
https://docs.python.org/3/library/xml.etree.elementtree.html
* Drop the error checking as these modules are a part of stdlib.
* Additionally, the pyexpat issue was fixed in 3.2. See:
https://bugs.python.org/issue14988
Signed-off-by: Aaron Bauman <bman@gentoo.org>
---
lib/portage/xml/metadata.py | 29 ++++++++---------------------
1 file changed, 8 insertions(+), 21 deletions(-)
diff --git a/lib/portage/xml/metadata.py b/lib/portage/xml/metadata.py
index 646edb5b9..808ba2246 100644
--- a/lib/portage/xml/metadata.py
+++ b/lib/portage/xml/metadata.py
@@ -31,29 +31,16 @@
__all__ = ('MetaDataXML', 'parse_metadata_use')
-try:
- import xml.etree.cElementTree as etree
-except (SystemExit, KeyboardInterrupt):
- raise
-except (ImportError, SystemError, RuntimeError, Exception):
- # broken or missing xml support
- # https://bugs.python.org/issue14988
- import xml.etree.ElementTree as etree
-
-try:
- from xml.parsers.expat import ExpatError
-except (SystemExit, KeyboardInterrupt):
- raise
-except (ImportError, SystemError, RuntimeError, Exception):
- ExpatError = SyntaxError
-
import re
-import xml.etree.ElementTree
+import xml.etree.ElementTree as etree
+
+from xml.parsers.expat import ExpatError
+
from portage import _encodings, _unicode_encode
from portage.util import cmp_sort_key, unique_everseen
-class _MetadataTreeBuilder(xml.etree.ElementTree.TreeBuilder):
+class _MetadataTreeBuilder(etree.TreeBuilder):
"""
Implements doctype() as required to avoid deprecation warnings with
Python >=2.7.
@@ -198,8 +185,8 @@ class MetaDataXML:
try:
self._xml_tree = etree.parse(_unicode_encode(metadata_xml_path,
- encoding=_encodings['fs'], errors='strict'),
- parser=etree.XMLParser(target=_MetadataTreeBuilder()))
+ encoding = _encodings['fs'], errors='strict'),
+ parser = etree.XMLParser(target=_MetadataTreeBuilder()))
except ImportError:
pass
except ExpatError as e:
@@ -238,7 +225,7 @@ class MetaDataXML:
try:
self._herdstree = etree.parse(_unicode_encode(self._herds_path,
encoding=_encodings['fs'], errors='strict'),
- parser=etree.XMLParser(target=_MetadataTreeBuilder()))
+ parser = etree.XMLParser(target=_MetadataTreeBuilder()))
except (ImportError, IOError, SyntaxError):
return None
--
2.28.0
reply other threads:[~2020-08-06 23:28 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200806232813.1977027-1-bman@gentoo.org \
--to=bman@gentoo.org \
--cc=gentoo-portage-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox