From 46d88522f413cd62c60b081b296634444564813e Mon Sep 17 00:00:00 2001 From: Sapan Bhatia Date: Tue, 22 Sep 2009 20:24:23 +0000 Subject: [PATCH] Fixed the test rspec to match the new values. --- sfatables/runtime.py | 5 ++--- sfatables/test.sfarspec | 4 ++-- sfatables/xmlrule.py | 27 ++++++++++++++++++++------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/sfatables/runtime.py b/sfatables/runtime.py index dc9e7cbf..0cfac142 100644 --- a/sfatables/runtime.py +++ b/sfatables/runtime.py @@ -29,7 +29,8 @@ class SFATablesRules: if (rule.terminal): break - return intermediate_rspec + final_rspec = XMLRule().wrap_up(intermediate_rspec) + return final_rspec def main(): incoming = SFATablesRules('INCOMING') @@ -37,8 +38,6 @@ def main(): rspec = open(sys.argv[1]).read() - - print "%d rules loaded for INCOMING chain\n"%len(incoming.sorted_rule_list) print "%d rules loaded for OUTGOING chain\n"%len(outgoing.sorted_rule_list) diff --git a/sfatables/test.sfarspec b/sfatables/test.sfarspec index c84a56df..0b8942fa 100644 --- a/sfatables/test.sfarspec +++ b/sfatables/test.sfarspec @@ -5,7 +5,7 @@ plc.princeton.sapanb - + hrn plc @@ -18,7 +18,7 @@ blacklist plc.tp - + diff --git a/sfatables/xmlrule.py b/sfatables/xmlrule.py index 92a06e24..70055dd9 100644 --- a/sfatables/xmlrule.py +++ b/sfatables/xmlrule.py @@ -7,6 +7,7 @@ class XMLRule: chain = None xmldoc = None terminal = 0 + final_processor = '__sfatables_wrap_up__.xsl' arguments = {'match':None,'target':None} processors = {'match':None,'target':None} @@ -37,6 +38,19 @@ class XMLRule: doc.freeDoc() result.freeDoc() + return stylesheet_result + + def wrap_up(self, rspec): + filepath = 'processors/' + self.final_processor + + styledoc = libxml2.parseFile(filepath) + style = libxslt.parseStylesheetDoc(styledoc) + doc = libxml2.parseDoc(rspec) + result = style.applyStylesheet(doc, None) + stylesheet_result = style.saveResultToString(result) + style.freeStylesheet() + doc.freeDoc() + result.freeDoc() return stylesheet_result @@ -97,13 +111,12 @@ class XMLRule: root_node.addChild(arguments[type]) return rspec - def __init__(self, chain, rule_number): - - self.load_xml_extension('match', chain, rule_number) - self.load_xml_extension('target',chain, rule_number) - self.rule_number = rule_number - self.chain = chain - + def __init__(self, chain=None, rule_number=None): + if (chain and rule_number): + self.load_xml_extension('match', chain, rule_number) + self.load_xml_extension('target',chain, rule_number) + self.rule_number = rule_number + self.chain = chain return def free(self): -- 2.43.0