From: Zac Medico Date: Mon, 12 Apr 2010 00:45:33 +0000 (-0700) Subject: Port parse_metadata_use() code from minidom to ElementTree. X-Git-Tag: v2.2_rc68~653 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a609a474169cd38664131db0ce8e4663adc8ff7e;p=portage.git Port parse_metadata_use() code from minidom to ElementTree. --- diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py index 719e910d7..bb4281c1f 100644 --- a/pym/repoman/utilities.py +++ b/pym/repoman/utilities.py @@ -23,16 +23,10 @@ import codecs import errno import logging import sys -try: - from subprocess import getstatusoutput as subprocess_getstatusoutput -except ImportError: - from commands import getstatusoutput as subprocess_getstatusoutput - -from xml.dom import minidom -from xml.dom import NotFoundErr from xml.parsers.expat import ExpatError import xml.etree.ElementTree as ET from portage import os +from portage import subprocess_getstatusoutput from portage import _encodings from portage import _unicode_decode from portage import _unicode_encode @@ -120,37 +114,28 @@ def parse_metadata_use(metadata_xml_content, uselist=None): returns a dict of the form a list of flags""" if uselist is None: uselist = [] - try: - metadatadom = minidom.parseString(metadata_xml_content) - except ExpatError as e: - raise exception.ParseError("metadata.xml: %s" % (e,)) try: + xml_tree = ET.fromstring(metadata_xml_content) + except (ExpatError, ) as e: + raise exception.ParseError("metadata.xml: " + str(e)) - try: - usetag = metadatadom.getElementsByTagName("use") - if not usetag: - return uselist - except NotFoundErr: - return uselist - - try: - flags = usetag[0].getElementsByTagName("flag") - except NotFoundErr: - raise exception.ParseError("metadata.xml: " + \ - "Malformed input: missing 'flag' tag(s)") - - for flag in flags: - pkg_flag = flag.getAttribute("name") - if not pkg_flag: - raise exception.ParseError("metadata.xml: " + \ - "Malformed input: missing 'name' attribute for 'flag' tag") - uselist.append(pkg_flag) + usetag = xml_tree.findall("use") + if not usetag: return uselist - finally: - metadatadom.unlink() + flags = usetag[0].findall("flag") + if not flags: + raise exception.ParseError("metadata.xml: " + \ + "Malformed input: missing 'flag' tag(s)") + for flag in flags: + pkg_flag = flag.get("name") + if pkg_flag is None: + raise exception.ParseError("metadata.xml: " + \ + "Malformed input: missing 'name' attribute for 'flag' tag") + uselist.append(pkg_flag) + return uselist class UnknownHerdsError(ValueError): def __init__(self, herd_names):