From 3a97db6c45ead4330e2fa69a75a86dfb2ecc92dd Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 30 Sep 2014 14:03:19 +0200 Subject: [PATCH] Remove xmlutils module The xmlutils module is being removed from oslo-incubator as it's not useful anymore. Various fixes have been integrated into the base XML module provided by Python now. See http://lists.openstack.org/pipermail/openstack-dev/2014-September/047368.html for details. Change-Id: Iefa1a5a4d08a3cfc43b3c9764fc2d35c328a19e3 --- .../contrib/security_group_default_rules.py | 4 +- .../compute/contrib/security_groups.py | 4 +- nova/openstack/common/xmlutils.py | 72 ------------------- nova/virt/libvirt/driver.py | 6 +- nova/virt/xenapi/vm_utils.py | 4 +- openstack-common.conf | 1 - 6 files changed, 9 insertions(+), 82 deletions(-) delete mode 100644 nova/openstack/common/xmlutils.py diff --git a/nova/api/openstack/compute/contrib/security_group_default_rules.py b/nova/api/openstack/compute/contrib/security_group_default_rules.py index fa7336852752..e6feb8775508 100644 --- a/nova/api/openstack/compute/contrib/security_group_default_rules.py +++ b/nova/api/openstack/compute/contrib/security_group_default_rules.py @@ -11,6 +11,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +from xml.dom import minidom import webob from webob import exc @@ -23,7 +24,6 @@ from nova import exception from nova.i18n import _ from nova.network.security_group import openstack_driver from nova.openstack.common import log as logging -from nova.openstack.common import xmlutils LOG = logging.getLogger(__name__) @@ -71,7 +71,7 @@ class SecurityGroupDefaultRuleTemplate(xmlutil.TemplateBuilder): class SecurityGroupDefaultRulesXMLDeserializer(wsgi.MetadataXMLDeserializer): def default(self, string): - dom = xmlutils.safe_minidom_parse_string(string) + dom = minidom.parseString(string) security_group_rule = self._extract_security_group_default_rule(dom) return {'body': {'security_group_default_rule': security_group_rule}} diff --git a/nova/api/openstack/compute/contrib/security_groups.py b/nova/api/openstack/compute/contrib/security_groups.py index 102d2fad2bae..9d9776cb10ee 100644 --- a/nova/api/openstack/compute/contrib/security_groups.py +++ b/nova/api/openstack/compute/contrib/security_groups.py @@ -17,6 +17,7 @@ """The security groups extension.""" import contextlib +from xml.dom import minidom import webob from webob import exc @@ -33,7 +34,6 @@ from nova.network.security_group import neutron_driver from nova.network.security_group import openstack_driver from nova.openstack.common import jsonutils from nova.openstack.common import log as logging -from nova.openstack.common import xmlutils from nova.virt import netutils @@ -571,7 +571,7 @@ class SecurityGroupsOutputController(wsgi.Controller): servers[0][key] = req_obj['server'].get( key, [{'name': 'default'}]) except ValueError: - root = xmlutils.safe_minidom_parse_string(req.body) + root = minidom.parseString(req.body) sg_root = root.getElementsByTagName(key) groups = [] if sg_root: diff --git a/nova/openstack/common/xmlutils.py b/nova/openstack/common/xmlutils.py deleted file mode 100644 index 1231a5902c5c..000000000000 --- a/nova/openstack/common/xmlutils.py +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright 2013 IBM Corp. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from xml.dom import minidom -from xml.parsers import expat -from xml import sax -from xml.sax import expatreader - - -class ProtectedExpatParser(expatreader.ExpatParser): - """An expat parser which disables DTD's and entities by default.""" - - def __init__(self, forbid_dtd=True, forbid_entities=True, - *args, **kwargs): - # Python 2.x old style class - expatreader.ExpatParser.__init__(self, *args, **kwargs) - self.forbid_dtd = forbid_dtd - self.forbid_entities = forbid_entities - - def start_doctype_decl(self, name, sysid, pubid, has_internal_subset): - raise ValueError("Inline DTD forbidden") - - def entity_decl(self, entityName, is_parameter_entity, value, base, - systemId, publicId, notationName): - raise ValueError(" entity declaration forbidden") - - def unparsed_entity_decl(self, name, base, sysid, pubid, notation_name): - # expat 1.2 - raise ValueError(" unparsed entity forbidden") - - def external_entity_ref(self, context, base, systemId, publicId): - raise ValueError(" external entity forbidden") - - def notation_decl(self, name, base, sysid, pubid): - raise ValueError(" notation forbidden") - - def reset(self): - expatreader.ExpatParser.reset(self) - if self.forbid_dtd: - self._parser.StartDoctypeDeclHandler = self.start_doctype_decl - self._parser.EndDoctypeDeclHandler = None - if self.forbid_entities: - self._parser.EntityDeclHandler = self.entity_decl - self._parser.UnparsedEntityDeclHandler = self.unparsed_entity_decl - self._parser.ExternalEntityRefHandler = self.external_entity_ref - self._parser.NotationDeclHandler = self.notation_decl - try: - self._parser.SkippedEntityHandler = None - except AttributeError: - # some pyexpat versions do not support SkippedEntity - pass - - -def safe_minidom_parse_string(xml_string): - """Parse an XML string using minidom safely. - - """ - try: - return minidom.parseString(xml_string, parser=ProtectedExpatParser()) - except sax.SAXParseException: - raise expat.ExpatError() diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index a9cb691a0c7a..b6077ea09e2e 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -39,6 +39,7 @@ import tempfile import threading import time import uuid +from xml.dom import minidom import eventlet from eventlet import greenio @@ -79,7 +80,6 @@ from nova.openstack.common import loopingcall from nova.openstack.common import processutils from nova.openstack.common import timeutils from nova.openstack.common import units -from nova.openstack.common import xmlutils from nova.pci import pci_manager from nova.pci import pci_utils from nova.pci import pci_whitelist @@ -2719,7 +2719,7 @@ class LibvirtDriver(driver.ComputeDriver): def get_vnc_port_for_instance(instance_name): virt_dom = self._lookup_by_name(instance_name) xml = virt_dom.XMLDesc(0) - dom = xmlutils.safe_minidom_parse_string(xml) + dom = minidom.parseString(xml) for graphic in dom.getElementsByTagName('graphics'): if graphic.getAttribute('type') == 'vnc': @@ -2738,7 +2738,7 @@ class LibvirtDriver(driver.ComputeDriver): virt_dom = self._lookup_by_name(instance_name) xml = virt_dom.XMLDesc(0) # TODO(sleepsonthefloor): use etree instead of minidom - dom = xmlutils.safe_minidom_parse_string(xml) + dom = minidom.parseString(xml) for graphic in dom.getElementsByTagName('graphics'): if graphic.getAttribute('type') == 'spice': diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 8191b389c490..75dcdb36a526 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -24,6 +24,7 @@ import os import time import urllib import uuid +from xml.dom import minidom from xml.parsers import expat from eventlet import greenthread @@ -47,7 +48,6 @@ from nova.openstack.common import strutils from nova.openstack.common import timeutils from nova.openstack.common import units from nova.openstack.common import versionutils -from nova.openstack.common import xmlutils from nova import utils from nova.virt import configdrive from nova.virt import diagnostics @@ -1792,7 +1792,7 @@ def compile_diagnostics(vm_rec): vm_uuid = vm_rec["uuid"] xml = _get_rrd(_get_rrd_server(), vm_uuid) if xml: - rrd = xmlutils.safe_minidom_parse_string(xml) + rrd = minidom.parseString(xml) for i, node in enumerate(rrd.firstChild.childNodes): # Provide the last update of the information if node.localName == 'lastupdate': diff --git a/openstack-common.conf b/openstack-common.conf index b94de8f0a6f2..5186174ba29f 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -39,7 +39,6 @@ module=timeutils module=units module=uuidutils module=versionutils -module=xmlutils # The base module to hold the copy of openstack.common base=nova