summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-04-11 17:45:33 -0700
committerZac Medico <zmedico@gentoo.org>2010-04-11 17:45:33 -0700
commita609a474169cd38664131db0ce8e4663adc8ff7e (patch)
treeb5e352c626dec752f97d85fccb2bd7c9f09a671a
parentab02fdd64eb215464325dfade55aad115d687a7f (diff)
downloadportage-a609a474169cd38664131db0ce8e4663adc8ff7e.tar.gz
portage-a609a474169cd38664131db0ce8e4663adc8ff7e.tar.bz2
portage-a609a474169cd38664131db0ce8e4663adc8ff7e.zip
Port parse_metadata_use() code from minidom to ElementTree.
-rw-r--r--pym/repoman/utilities.py49
1 files changed, 17 insertions, 32 deletions
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):