Continuation of bug fixes and integration-related fixes.
authorSapan Bhatia <sapanb@cs.princeton.edu>
Mon, 26 Oct 2009 14:35:09 +0000 (14:35 +0000)
committerSapan Bhatia <sapanb@cs.princeton.edu>
Mon, 26 Oct 2009 14:35:09 +0000 (14:35 +0000)
sfatables/runtime.py
sfatables/xmlrule.py

index 1aac773..8f5c323 100644 (file)
@@ -16,12 +16,28 @@ class SFATablesRules:
         self.active_context = {}
         self.contexts = None # placeholder for rspec_manger
         self.sorted_rule_list = []
+        self.final_processor = '__sfatables_wrap_up__.xsl'
         chain_dir_path = os.path.join(sfatables_config,chain_name)
         rule_list = List().get_rule_list(chain_dir_path)
         for rule_number in rule_list:
             self.sorted_rule_list = self.sorted_rule_list + [XMLRule(chain_name, rule_number)]
         return
 
+    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 = style.saveResultToString(result)
+        style.freeStylesheet()
+        doc.freeDoc()
+        result.freeDoc()
+
+        return stylesheet_result
 
     def set_context(self, request_context):
         self.active_context = request_context
@@ -79,11 +95,14 @@ class SFATablesRules:
         intermediate_rspec = doc
 
         for rule in self.sorted_rule_list:
+            import pdb
+            pdb.set_trace()
             intermediate_rspec  = rule.apply_interpreted(intermediate_rspec)
+            intermediate_rspec = XMLRule().wrap_up(intermediate_rspec) 
             if (rule.terminal):
                 break
 
-        final_rspec = XMLRule().wrap_up(intermediate_rspec) 
+        final_rspec = self.wrap_up(intermediate_rspec) 
         return final_rspec
 
 def main():
index a72a480..310c843 100644 (file)
@@ -35,20 +35,16 @@ class XMLRule:
         filepath = os.path.join(sfatables_config, 'processors', self.final_processor)
 
         if not os.path.exists(filepath):
-            # TODO: final_processor is not there yet
-            return doc#rspec
+            raise Exception('Could not find final rule filter')
 
         styledoc = libxml2.parseFile(filepath)
         style = libxslt.parseStylesheetDoc(styledoc)
-        #doc = libxml2.parseDoc(rspec)
         result = style.applyStylesheet(doc, None)
-        stylesheet_result = style.saveResultToString(result)
+        stylesheet_result = result#style.saveResultToString(result)
         style.freeStylesheet()
-        doc.freeDoc()
-        result.freeDoc()
+        #doc.freeDoc()
+        #result.freeDoc()
 
-        import pdb
-        pdb.set_trace()
         return stylesheet_result
 
     def match(self, rspec):
@@ -113,7 +109,7 @@ class XMLRule:
         self.chain = None
         self.xmldoc = None
         self.terminal = 0
-        self.final_processor = '__sfatables_wrap_up__.xsl'
+        self.final_processor = '__sfatables_rule_wrap_up__.xsl'
 
         self.arguments = {'match':None,'target':None}
         self.processors = {'match':None,'target':None}