a little nicer wrt pep8
[sfa.git] / sfatables / xmlextension.py
index b4b52cd..dcc0419 100644 (file)
@@ -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
 
 class Xmlextension:
-    context = ""
-    processor = ""
-    operand = "VALUE"
-    arguments = []
+    def __init__(self, file_path):
 
-    def __init__(filename):
-        self.xmldoc = libxml2.parseFile(filename)
-        # TODO: Check xmldoc against a schema
+        self.context = ""
+        self.processor = ""
+        self.operand = "VALUE"
+        self.arguments = []
+        self.terminal = 0
 
-        p = self.xmldoc.XPathNewContext()
+        self.xmldoc = libxml2.parseFile(file_path)
+
+        # TODO: Check xmldoc against a schema
+        p = self.xmldoc.xpathNewContext()
 
         # <context select="..."/>
         # <rule><argument param="..."/></rule>
         # <processor name="..."/>
 
         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 = [{'name':name_help_target[0].content,'help':name_help_target[1].content,'target':name_help_target[2].content} for name_help_target in zip(name,help,target)]
+        
+        p.xpathFreeContext()
+        self.xmldoc.freeDoc()
 
         return