Live and learn. Some properties in this code were being instantiated as class propert...
authorSapan Bhatia <sapanb@cs.princeton.edu>
Sun, 25 Oct 2009 00:13:27 +0000 (00:13 +0000)
committerSapan Bhatia <sapanb@cs.princeton.edu>
Sun, 25 Oct 2009 00:13:27 +0000 (00:13 +0000)
properties.

sfatables/commands/List.py
sfatables/runtime.py
sfatables/xmlrule.py

index fcb1413..86d52a2 100644 (file)
@@ -7,13 +7,14 @@ from sfatables.pretty import Pretty
 from sfatables.command import Command
 
 class List(Command):
-    options = [('-L','--list')]
-    help = 'List a chain'
-    key='list_rule'
-    matches = False
-    targets = False
-
+    
     def __init__(self):
+        self.options = [('-L','--list')]
+        self.help = 'List a chain'
+        self.key='list_rule'
+        self.matches = False
+        self.targets = False
+
         return
 
     def get_info(self, type, xmlextension_path):
index b155809..e2b5787 100644 (file)
@@ -13,21 +13,24 @@ from sfatables.xmlrule import *
 
 class SFATablesRules:
     def __init__(self, chain_name):
+        self.active_context = None
         self.contexts = None # placeholder for rspec_manger
         self.sorted_rule_list = []
         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.append(XMLRule(chain_name, rule_number))
+            self.sorted_rule_list = self.sorted_rule_list + [XMLRule(chain_name, rule_number)]
         return
 
 
     def set_context(self, request_context):
+        self.active_context = request_context
         return
 
     def apply(self, rspec):
         doc = libxml2.parseDoc(rspec)
         intermediate_rspec = doc
+
         for rule in self.sorted_rule_list:
             intermediate_rspec  = rule.apply_interpreted(intermediate_rspec)
             if (rule.terminal):
@@ -38,10 +41,13 @@ class SFATablesRules:
 
 def main():
     incoming = SFATablesRules('INCOMING')
-    outgoing = SFATablesRules('OUTGOING')
 
+    outgoing = SFATablesRules('OUTGOING')
     print "%d rules loaded for INCOMING chain"%len(incoming.sorted_rule_list)
+    print incoming.sorted_rule_list[0].processors
+
     print "%d rules loaded for OUTGOING chain"%len(outgoing.sorted_rule_list)
+    print outgoing.sorted_rule_list[0].processors
 
     rspec = open(sys.argv[1]).read()
     newrspec = incoming.apply(rspec)
index 5eb5891..58a8d4c 100644 (file)
@@ -3,16 +3,7 @@ import libxslt
 from sfatables.globals import *
 
 class XMLRule:
-    rule_number = None
-    chain = None
-    xmldoc = None
-    terminal = 0
-    final_processor = '__sfatables_wrap_up__.xsl'
-
-    arguments = {'match':None,'target':None}
-    processors = {'match':None,'target':None}
-    context = {'match':None,'target':None}
-
+    
     def apply_processor(self, type, doc, output_xpath_filter=None):
         processor = self.processors[type]
 
@@ -116,6 +107,16 @@ class XMLRule:
         return rspec
 
     def __init__(self, chain=None, rule_number=None):
+        self.rule_number = None
+        self.chain = None
+        self.xmldoc = None
+        self.terminal = 0
+        self.final_processor = '__sfatables_wrap_up__.xsl'
+
+        self.arguments = {'match':None,'target':None}
+        self.processors = {'match':None,'target':None}
+        self.context = {'match':None,'target':None}
+
         if (chain and rule_number):
             self.load_xml_extension('match', chain, rule_number)
             self.load_xml_extension('target',chain, rule_number)