From 429e5214b5e839964e10d540bea97480fb6fcd74 Mon Sep 17 00:00:00 2001 From: Sapan Bhatia Date: Mon, 26 Oct 2009 14:48:47 +0000 Subject: [PATCH] Set up different namespaces for match and target arguments. --- sfatables/runtime.py | 26 +------------------------- sfatables/xmlrule.py | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/sfatables/runtime.py b/sfatables/runtime.py index 8f5c323f..e948d051 100644 --- a/sfatables/runtime.py +++ b/sfatables/runtime.py @@ -65,29 +65,7 @@ class SFATablesRules: p.xpathFreeContext() return doc - def add_rule_context_to_rspec(self,arguments, doc): - p = doc.xpathNewContext() - context = p.xpathEval("//rspec") - if (not context): - raise Exception('Request is not an rspec') - else: - # Add the request context - ruleNode = libxml2.newNode('rule-context') - ac = self.active_context - for k in ac: - argumentNode = libxml2.newNode('argument') - nameNode = libxml2.newNode('name') - nameNode.addContent(k) - valueNode = libxml2.newNode('value') - valueNode.addContent(ac[k]) - argumentNode.addChild(nameNode) - argumentNode.addChild(valueNode) - ruleNode.addChild(argumentNode) - context[0].addChild(ruleNode) - p.xpathFreeContext() - - return doc - + def apply(self, rspec): doc = libxml2.parseDoc(rspec) doc = self.add_request_context_to_rspec(doc) @@ -95,8 +73,6 @@ 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): diff --git a/sfatables/xmlrule.py b/sfatables/xmlrule.py index 310c8439..d137e4e6 100644 --- a/sfatables/xmlrule.py +++ b/sfatables/xmlrule.py @@ -55,18 +55,36 @@ class XMLRule: target_result = self.apply_processor('target',rspec,None) return target_result + def add_rule_context_to_rspec(self, doc): + p = doc.xpathNewContext() + context = p.xpathEval("//rspec") + if (not context): + raise Exception('Request is not an rspec') + else: + # Add the request context + matchNode = libxml2.newNode('match-context') + matchNode.addChild(self.arguments['match']) + targetNode = libxml2.newNode('target-context') + targetNode.addChild(self.arguments['target']) + context[0].addChild(matchNode) + context[0].addChild(targetNode) + p.xpathFreeContext() + + return doc + def apply_interpreted(self, rspec): + self.add_rule_context_to_rspec(rspec) # Interpreted # # output = # if (match(match_args, rspec) # then target(target_args, rspec) # else rspec - + if (self.match(rspec)): - return self.target(rspec) + return self.wrap_up(self.target(rspec)) else: - return rspec + return self.wrap_up(rspec) def apply_compiled(rspec): -- 2.43.0