From 7f5d4eef337809e0e0e802ca8c0cc8f695dc0837 Mon Sep 17 00:00:00 2001 From: Sapan Bhatia Date: Sun, 25 Oct 2009 00:13:27 +0000 Subject: [PATCH] Live and learn. Some properties in this code were being instantiated as class properties, not object properties. --- sfatables/commands/List.py | 13 +++++++------ sfatables/runtime.py | 10 ++++++++-- sfatables/xmlrule.py | 21 +++++++++++---------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/sfatables/commands/List.py b/sfatables/commands/List.py index fcb14138..86d52a22 100644 --- a/sfatables/commands/List.py +++ b/sfatables/commands/List.py @@ -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): diff --git a/sfatables/runtime.py b/sfatables/runtime.py index b155809b..e2b57877 100644 --- a/sfatables/runtime.py +++ b/sfatables/runtime.py @@ -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) diff --git a/sfatables/xmlrule.py b/sfatables/xmlrule.py index 5eb58911..58a8d4cc 100644 --- a/sfatables/xmlrule.py +++ b/sfatables/xmlrule.py @@ -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) -- 2.43.0