def outputRecordedData(self,stateEngine): output = self.myState outputFile = file('output.xml',"w") writer = MarkupWriter(outputFile,indent=u"yes") writer.startDocument() writer.startElement(u"Peach") dataModelIter = 0 for action in output: if action.type == 'input' or action.type == 'output': writer.startElement(u"DataModel", attributes={u"name": unicode("HotFuzzDataModel_"+str(dataModelIter))}) self.outputDataModelBlock(writer,action.template) writer.endElement(u"DataModel") dataModelIter = dataModelIter + 1 dataModelIter = 0 for action in output: writer.startElement(u"Action", attributes={u"name": unicode(action.name), u"type": unicode(action.type)}) if action.type == 'input' or action.type == 'output': writer.simpleElement(u"DataModel", attributes={u"ref": unicode("HotFuzzDataModel_"+str(dataModelIter))}) dataModelIter = dataModelIter + 1 writer.endElement(u"Action") writer.endElement(u"Peach") writer.endDocument()
class ParseTracer(object): def __init__(self): pass def start_action(self, instring, loc, expr): self.writer.startElement(u'attempt', attributes={ u'class': unicode(expr.__class__.__name__), u'loc': unicode(repr(loc)), u'expr': unicode(repr(expr)), u'lineno': unicode(lineno(loc, instring)), u'col': unicode(col(loc, instring)), }) def success_action(self, instring, tokensStart, loc, expr, tokens): self.writer.simpleElement(u'success') self.writer.endElement(u'attempt') def exception_action(self, instring, tokensStart, expr, err): self.writer.simpleElement(u'fail', attributes={u'err': unicode(repr(err))}) self.writer.endElement(u'attempt') def set_debug_actions(self, parser): parser.setDebugActions(self.start_action, self.success_action, self.exception_action) def parse(self, parser, input, stream): self.parser = parser apply_to_pyparser_tree(self.parser, self.set_debug_actions) self.writer = MarkupWriter(indent='yes', stream=stream) self.writer.startDocument() self.writer.startElement(u'trace') try: result = self.parser.parseString(input)[0] except ParseException, e: self.writer.simpleElement( u'fail', attributes={u'err': unicode(repr(e))}) #self.writer.endElement(u'attempt') self.writer.endElement(u'trace') self.writer.endDocument() raise self.writer.endElement(u'trace') self.writer.endDocument() return result
def Test(tester): tester.startGroup('MarkupWriter') tester.startTest('Basic MarkupWriter test') s = cStringIO.StringIO() writer = MarkupWriter(stream=s, indent=u"yes") writer.startDocument() writer.startElement(u'xsa') writer.startElement(u'vendor') #Element with simple text (#PCDATA) content writer.simpleElement(u'name', content=u'Centigrade systems') #Note writer.text(content) still works writer.simpleElement(u'email', content=u"*****@*****.**") writer.endElement(u'vendor') #Element with an attribute writer.startElement(u'product', attributes={u'id': u"100\u00B0"}) #Note writer.attribute(name, value, namespace=None) still works writer.simpleElement(u'name', content=u"100\u00B0 Server") #XML fragment writer.xmlFragment('<version>1.0</version><last-release>20030401</last-release>') #Empty element writer.simpleElement(u'changes') writer.endElement(u'product') writer.endElement(u'xsa') writer.endDocument() tester.compare(EXPECTED_1, s.getvalue()) tester.testDone() tester.groupDone() return
def Test(tester): tester.startGroup('MarkupWriter') tester.startTest('Basic MarkupWriter test') s = cStringIO.StringIO() writer = MarkupWriter(stream=s, indent=u"yes") writer.startDocument() writer.startElement(u'xsa') writer.startElement(u'vendor') #Element with simple text (#PCDATA) content writer.simpleElement(u'name', content=u'Centigrade systems') #Note writer.text(content) still works writer.simpleElement(u'email', content=u"*****@*****.**") writer.endElement(u'vendor') #Element with an attribute writer.startElement(u'product', attributes={u'id': u"100\u00B0"}) #Note writer.attribute(name, value, namespace=None) still works writer.simpleElement(u'name', content=u"100\u00B0 Server") #XML fragment writer.xmlFragment( '<version>1.0</version><last-release>20030401</last-release>') #Empty element writer.simpleElement(u'changes') writer.endElement(u'product') writer.endElement(u'xsa') writer.endDocument() tester.compare(EXPECTED_1, s.getvalue()) tester.testDone() tester.groupDone() return
class ParseTracer(object): def __init__(self): pass def start_action(self, instring, loc, expr): self.writer.startElement(u'attempt', attributes={ u'class': unicode(expr.__class__.__name__), u'loc': unicode(repr(loc)), u'expr': unicode(repr(expr)), u'lineno': unicode(lineno(loc, instring)), u'col': unicode(col(loc, instring)),}) def success_action(self, instring, tokensStart, loc, expr, tokens): self.writer.simpleElement(u'success') self.writer.endElement(u'attempt') def exception_action(self, instring, tokensStart, expr, err): self.writer.simpleElement(u'fail', attributes={ u'err': unicode(repr(err))}) self.writer.endElement(u'attempt') def set_debug_actions(self, parser): parser.setDebugActions( self.start_action, self.success_action, self.exception_action) def parse(self, parser, input, stream): self.parser = parser apply_to_pyparser_tree(self.parser, self.set_debug_actions) self.writer = MarkupWriter(indent='yes', stream=stream) self.writer.startDocument() self.writer.startElement(u'trace') try: result = self.parser.parseString(input)[0] except ParseException, e: self.writer.simpleElement(u'fail', attributes={ u'err': unicode(repr(e))}) #self.writer.endElement(u'attempt') self.writer.endElement(u'trace') self.writer.endDocument() raise self.writer.endElement(u'trace') self.writer.endDocument() return result
class ParseTracer(object): def __init__(self): pass def start_action(self, instring, loc, expr): self.writer.startElement( u"attempt", attributes={ u"class": unicode(expr.__class__.__name__), u"loc": unicode(repr(loc)), u"expr": unicode(repr(expr)), u"lineno": unicode(lineno(loc, instring)), u"col": unicode(col(loc, instring)), }, ) def success_action(self, instring, tokensStart, loc, expr, tokens): self.writer.simpleElement(u"success") self.writer.endElement(u"attempt") def exception_action(self, instring, tokensStart, expr, err): self.writer.simpleElement(u"fail", attributes={u"err": unicode(repr(err))}) self.writer.endElement(u"attempt") def set_debug_actions(self, parser): parser.setDebugActions(self.start_action, self.success_action, self.exception_action) def parse(self, parser, input, stream): self.parser = parser apply_to_pyparser_tree(self.parser, self.set_debug_actions) self.writer = MarkupWriter(indent="yes", stream=stream) self.writer.startDocument() self.writer.startElement(u"trace") try: result = self.parser.parseString(input)[0] except ParseException, e: self.writer.simpleElement(u"fail", attributes={u"err": unicode(repr(e))}) # self.writer.endElement(u'attempt') raise finally:
def __init__(self,hfile): sio = StringIO() writer = MarkupWriter(sio,indent=u'yes',omitXmlDeclaration=u'yes') writer.startDocument() writer.startElement(u'hitsfile') writer.simpleElement(u'filename',content=u(hfile.filename)) writer.startElement(u'hits') for hit in hfile.hits: writer.startElement(u'hit') writer.simpleElement(u'score',content=u(hit.score)) writer.startElement(u'coord') writer.simpleElement(u'x',content=u(hit.x)) writer.simpleElement(u'y',content=u(hit.y)) writer.simpleElement(u'z',content=u(hit.z)) writer.endElement(u'coord') writer.endElement(u'hit') writer.endElement(u'hits') writer.endElement(u'hitsfile') writer.endDocument() self.data = sio.getvalue()
def __init__(self, sfile): sio = StringIO() writer = MarkupWriter(sio, indent=u'yes', omitXmlDeclaration=u'yes') writer.startDocument() writer.startElement(u'sitefile') writer.simpleElement(u'filename', content=u(sfile.filename)) writer.simpleElement(u'name', content=u(sfile.name)) writer.simpleElement(u'radius', content=u(sfile.radius)) writer.startElement(u'sites') for site in sfile.sites: writer.startElement(u'site') writer.simpleElement(u'pdbid', content=u(site.pdbid)) writer.startElement(u'coord') writer.simpleElement(u'x', content=u(site.x)) writer.simpleElement(u'y', content=u(site.y)) writer.simpleElement(u'z', content=u(site.z)) writer.endElement(u'coord') writer.simpleElement(u'label', content=u(site.label)) writer.simpleElement(u'originalLabel', content=u(site.originalLabel)) writer.simpleElement(u'comment', content=u(site.comment)) writer.endElement(u'site') writer.endElement(u'sites') writer.endElement(u'sitefile') writer.endDocument() self.data = sio.getvalue()
def __init__(self,stfile): sio = StringIO() writer = MarkupWriter(sio,indent=u'yes',omitXmlDeclaration=u'yes') writer.startDocument() writer.startElement(u'statfile') writer.simpleElement(u'filename',content=u(stfile.filename)) writer.startElement(u'properties') for propertyIndex,record in enumerate(stfile.records): writer.startElement(u'property') writer.attribute(u'index',u(propertyIndex)) writer.simpleElement(u'name',content=u(record.property)) writer.simpleElement(u'volume',content=u(record.volume)) writer.simpleElement(u'pvalue',content=u(record.pvalue)) writer.simpleElement(u'tvalue',content=u(record.tvalue)) writer.simpleElement(u'dof',content=u(record.dof)) writer.simpleElement(u'mean',content=u(record.mean)) writer.simpleElement(u'stdev',content=u(record.stdev)) writer.simpleElement(u'sumOfRanks',content=u(record.sumOfRanks)) writer.simpleElement(u'numSmall',content=u(record.numSmall)) writer.simpleElement(u'numBig',content=u(record.numBig)) writer.endElement(u'property') writer.endElement(u'properties') writer.startElement(u'sites') for siteIndex in range(stfile.numSites): writer.startElement(u'site') writer.attribute(u'index',u(siteIndex)) writer.attribute(u'label',u'site') for propertyIndex,record in enumerate(stfile.records): writer.startElement(u'value') writer.attribute(u'index',u(propertyIndex)) writer.text(u(record.sites[siteIndex])) writer.endElement(u'value') writer.endElement(u'site') for nonSiteIndex in range(stfile.numNonSites): writer.startElement(u'site') writer.attribute(u'index',u(nonSiteIndex)) writer.attribute(u'label',u'nonsite') for propertyIndex,record in enumerate(stfile.records): writer.startElement(u'value') writer.attribute(u'index',u(propertyIndex)) writer.text(u(record.nonsites[nonSiteIndex])) writer.endElement(u'value') writer.endElement(u'site') writer.endElement(u'sites') writer.endElement(u'statfile') writer.endDocument() self.data = sio.getvalue()