Removed some debuggin print statements.
[sfa.git] / sfatables / xmlextension.py
1 # Matches and targets are specified using XML files.
2 # They provide the following information:
3 #   - The context required by the match
4 #   - The processor that actually implements the match or target
5 #   - The parameters that the processor needs to evaluate the context
6
7 import libxml2
8 from sfatables.globals import *
9
10 class Xmlextension:
11     def __init__(self, file_path):
12
13         self.context = ""
14         self.processor = ""
15         self.operand = "VALUE"
16         self.arguments = []
17         self.terminal = 0
18
19         self.xmldoc = libxml2.parseFile(file_path)
20
21         # TODO: Check xmldoc against a schema
22         p = self.xmldoc.xpathNewContext()
23
24         # <context select="..."/>
25         # <rule><argument param="..."/></rule>
26         # <processor name="..."/>
27
28         context = p.xpathEval('//context/@select')
29         self.context = context[0].content
30
31         processor = p.xpathEval('//processor/@filename')
32         self.context = processor[0].content
33
34         name = p.xpathEval('//rule/argument/name')
35         help = p.xpathEval('//rule/argument/help')
36         target = p.xpathEval('//rule/argument/operand')
37
38         context = p.xpathEval('//attributes/attribute[@terminal="yes"]')
39         self.terminal = (context != [])
40
41         self.arguments = map(lambda (name,help,target):{'name':name.content,'help':help.content,'target':target.content}, zip(name,help,target))
42         
43         p.xpathFreeContext()
44         self.xmldoc.freeDoc()
45
46         return
47