X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2Frspec.py;h=ffc816c3fdb8d0b5c42c5ec53ff283652b6b85a8;hb=bfcea75fd4f7d91b186f4f0e479db0e6f0a231ae;hp=26ba6735dc92437416078ffd6ab62ed3456da4fc;hpb=7aa8ddb89a0df17f068983a24dbd3a03fda15ec3;p=sfa.git diff --git a/sfa/util/rspec.py b/sfa/util/rspec.py index 26ba6735..ffc816c3 100644 --- a/sfa/util/rspec.py +++ b/sfa/util/rspec.py @@ -1,12 +1,13 @@ -### $Id$ -### $URL$ - import sys import pprint import os +from StringIO import StringIO +from types import StringTypes, ListType import httplib from xml.dom import minidom -from types import StringTypes, ListType +from lxml import etree + +from sfa.util.sfalogging import sfa_logger class RSpec: @@ -173,11 +174,19 @@ class RSpec: return self.rootNode.toprettyxml() + def __removeWhitespaceNodes(self, parent): + for child in list(parent.childNodes): + if child.nodeType == minidom.Node.TEXT_NODE and child.data.strip() == '': + parent.removeChild(child) + else: + self.__removeWhitespaceNodes(child) + def parseFile(self, filename): """ read a local xml file and store it as a dom object. """ dom = minidom.parse(filename) + self.__removeWhitespaceNodes(dom) self.rootNode = dom.childNodes[0] @@ -185,8 +194,8 @@ class RSpec: """ read an xml string and store it as a dom object. """ - xml = xml.replace('\n', '').replace('\t', '').strip() dom = minidom.parseString(xml) + self.__removeWhitespaceNodes(dom) self.rootNode = dom.childNodes[0] @@ -209,11 +218,13 @@ class RSpec: def _parseXSD(self, xsdURI): """ - Download XSD from URL, or if file, read local xsd file and set schemaDict + Download XSD from URL, or if file, read local xsd file and set + schemaDict. + + Since the schema definiton is a global namespace shared by and + agreed upon by others, this should probably be a URL. Check + for URL, download xsd, parse, or if local file, use that. """ - # Since the schema definiton is a global namespace shared by and agreed upon by - # others, this should probably be a URL. Check for URL, download xsd, parse, or - # if local file, use local file. schemaDom = None if xsdURI.startswith("http"): try: @@ -221,15 +232,14 @@ class RSpec: except Exception, e: # logging.debug("%s: web file not found" % xsdURI) # logging.debug("Using local file %s" % self.xsd") - print e - print "Can't find %s on the web. Continuing." % xsdURI + sfa_logger().log_exc("rspec.parseXSD: can't find %s on the web. Continuing." % xsdURI) if not schemaDom: if os.path.exists(xsdURI): # logging.debug("using local copy.") - print "Using local %s" % xsdURI + sfa_logger().debug("rspec.parseXSD: Using local %s" % xsdURI) schemaDom = minidom.parse(xsdURI) else: - raise Exception("Can't find xsd locally") + raise Exception("rspec.parseXSD: can't find xsd locally") self.schemaDict = self.toDict(schemaDom.childNodes[0])