Clean up ElementTree usage

Use lxml in favor of ElementTree to
make things more consistent.

Fixes LP: #953449

Change-Id: I7f48528d7df47fe7207ca88bce196dea7535df0e
Signed-off-by: Chuck Short <chuck.short@canonical.com>
This commit is contained in:
Chuck Short
2012-04-30 13:52:37 -04:00
parent 83b0b7bae9
commit b5820bef15
4 changed files with 30 additions and 35 deletions

View File

@@ -14,12 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from xml.etree import ElementTree
try:
ParseError = ElementTree.ParseError
except AttributeError:
from xml.parsers import expat
ParseError = expat.ExpatError
from lxml import etree
import uuid
@@ -141,7 +136,7 @@ class NWFilter(object):
self._parse_xml(xml)
def _parse_xml(self, xml):
tree = ElementTree.fromstring(xml)
tree = etree.fromstring(xml)
root = tree.find('.')
self._name = root.get('name')
@@ -163,8 +158,8 @@ class Domain(object):
def _parse_definition(self, xml):
try:
tree = ElementTree.fromstring(xml)
except ParseError:
tree = etree.fromstring(xml)
except etree.ParseError:
raise libvirtError(VIR_ERR_XML_DETAIL, VIR_FROM_DOMAIN,
"Invalid XML.")
@@ -301,13 +296,13 @@ class Domain(object):
123456789L]
def attachDevice(self, xml):
disk_info = _parse_disk_info(ElementTree.fromstring(xml))
disk_info = _parse_disk_info(etree.fromstring(xml))
disk_info['_attached'] = True
self._def['devices']['disks'] += [disk_info]
return True
def detachDevice(self, xml):
disk_info = _parse_disk_info(ElementTree.fromstring(xml))
disk_info = _parse_disk_info(etree.fromstring(xml))
disk_info['_attached'] = True
return disk_info in self._def['devices']['disks']
@@ -404,7 +399,7 @@ class Domain(object):
self._state = VIR_DOMAIN_RUNNING
def snapshotCreateXML(self, xml, flags):
tree = ElementTree.fromstring(xml)
tree = etree.fromstring(xml)
name = tree.find('./name').text
snapshot = DomainSnapshot(name, self)
self._snapshots[name] = snapshot
@@ -741,7 +736,7 @@ class Connection(object):
</capabilities>'''
def compareCPU(self, xml, flags):
tree = ElementTree.fromstring(xml)
tree = etree.fromstring(xml)
arch_node = tree.find('./arch')
if arch_node is not None: