Minor changes in the test system; XmlUnmarshaller can unmarshall XML content from a string, file handler of file path; any Appy object now has a method 'getField(name)' that returns a given field (=Appy type); bugfix while counting number of tests found in a gen-application.

This commit is contained in:
Gaetan Delannay 2011-02-17 18:13:42 +01:00
parent 2c6392aa92
commit a8366379dd
5 changed files with 23 additions and 8 deletions

View file

@ -167,8 +167,15 @@ class XmlParser(ContentHandler, ErrorHandler):
# Put a question mark instead of raising an exception.
self.characters('?')
def parse(self, xmlContent, source='string'):
'''Parses the XML file or string p_xmlContent.'''
def parse(self, xml, source='string'):
'''Parses a XML stream.
* If p_source is "string", p_xml must be a string containing
valid XML content.
* If p_source is "file": p_xml can be:
- a string containing the path to the XML file on disk;
- a file instance opened for reading. Note that in this case, this
method will close it.
'''
try:
from cStringIO import StringIO
except ImportError:
@ -178,10 +185,13 @@ class XmlParser(ContentHandler, ErrorHandler):
self.parser.setFeature(feature_external_ges, False)
inputSource = InputSource()
if source == 'string':
inputSource.setByteStream(StringIO(xmlContent))
inputSource.setByteStream(StringIO(xml))
else:
inputSource.setByteStream(xmlContent)
if not isinstance(xml, file):
xml = file(xml)
inputSource.setByteStream(xml)
self.parser.parse(inputSource)
if isinstance(xml, file): xml.close()
return self.res
# ------------------------------------------------------------------------------