X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfatables%2Fxmlextension.py;h=813cd6d3bb8cf88609a89e8b025b6f9ceab59a79;hb=e57b7150dee76d42fc15f9477a3045e5171c8878;hp=b4b52cd7778d1aa3666a9c65c41e1b714effdb33;hpb=aab206b1b50c439c1697c2bbcfd9e540a6c416cd;p=sfa.git diff --git a/sfatables/xmlextension.py b/sfatables/xmlextension.py index b4b52cd7..813cd6d3 100644 --- a/sfatables/xmlextension.py +++ b/sfatables/xmlextension.py @@ -1,30 +1,46 @@ +# Matches and targets are specified using XML files. +# They provide the following information: +# - The context required by the match +# - The processor that actually implements the match or target +# - The parameters that the processor needs to evaluate the context + import libxml2 +from sfatables.globals import * class Xmlextension: - context = "" - processor = "" - operand = "VALUE" - arguments = [] + def __init__(self, file_path): + self.context = "" + self.processor = "" + self.operand = "VALUE" + self.arguments = [] + self.terminal = 0 - def __init__(filename): - self.xmldoc = libxml2.parseFile(filename) - # TODO: Check xmldoc against a schema + self.xmldoc = libxml2.parseFile(file_path) - p = self.xmldoc.XPathNewContext() + # TODO: Check xmldoc against a schema + p = self.xmldoc.xpathNewContext() # # # context = p.xpathEval('//context/@select') - self.context = context[0].value + self.context = context[0].content + + processor = p.xpathEval('//processor/@filename') + self.context = processor[0].content - processor = p.xpathEval('//processor@name') - self.context = processor[0].value + name = p.xpathEval('//rule/argument/name') + help = p.xpathEval('//rule/argument/help') + target = p.xpathEval('//rule/argument/operand') - params = p.xpathEval('//rule/argument/@param') - self.arguments = [node.value for node in params] + context = p.xpathEval('//attributes/attribute[@terminal="yes"]') + self.terminal = (context != []) + self.arguments = map(lambda (name,help,target):{'name':name.content,'help':help.content,'target':target.content}, zip(name,help,target)) + + p.xpathFreeContext() + self.xmldoc.freeDoc() return