[PATCH] lib/portage/xml/metadata.py: fix ungrouped-imports w/refactor

Aaron Bauman <[email protected]>
Newsgroups gmane.linux.gentoo.portage.devel
Message-ID <[email protected]>
* 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 <[email protected]>
---
 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.