+ def apply_processor(self, type, doc, output_xpath_filter=None):
+ processor = self.processors[type]
+
+ # XXX TO CLEAN UP
+ filepath = os.path.join(sfatables_config, 'processors', processor)
+ # XXX
+
+ styledoc = libxml2.parseFile(filepath)
+ style = libxslt.parseStylesheetDoc(styledoc)
+ result = style.applyStylesheet(doc, None)
+ if (output_xpath_filter):
+ p = result.xpathNewContext()
+ xpath_result = p.xpathEval(output_xpath_filter)
+ if (xpath_result == []):
+ raise Exception("Could not apply processor %s."%processor)
+
+ stylesheet_result = xpath_result
+ p.xpathFreeContext()
+ else:
+ stylesheet_result = result #style.saveResultToString(result)
+
+ style.freeStylesheet()
+ #doc.freeDoc()
+ #result.freeDoc()
+
+ return stylesheet_result
+
+ def wrap_up(self, doc):
+ filepath = os.path.join(sfatables_config, 'processors', self.final_processor)
+
+ if not os.path.exists(filepath):
+ raise Exception('Could not find final rule filter')
+
+ styledoc = libxml2.parseFile(filepath)
+ style = libxslt.parseStylesheetDoc(styledoc)
+ result = style.applyStylesheet(doc, None)
+ stylesheet_result = result#style.saveResultToString(result)
+ style.freeStylesheet()
+ #doc.freeDoc()
+ #result.freeDoc()
+
+ return stylesheet_result
+
+ def match(self, rspec):
+ match_result = self.apply_processor('match',rspec,"//result/@verdict")
+ return (match_result[0].content=='True')