X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfatables%2Fruntime.py;h=b76ec0a8dda631b20081a977dd01e70cbfcb98e8;hb=73b163a7ea35209e0675a7c7cef367946928a96f;hp=8f5c323f7ce1d2cf9245820ee946cc0240e95e3e;hpb=805a8364a6ce7295edb2bad37bd26e12e3dbecac;p=sfa.git diff --git a/sfatables/runtime.py b/sfatables/runtime.py index 8f5c323f..b76ec0a8 100644 --- a/sfatables/runtime.py +++ b/sfatables/runtime.py @@ -55,7 +55,7 @@ class SFATablesRules: def add_request_context_to_rspec(self, doc): p = doc.xpathNewContext() - context = p.xpathEval("//rspec") + context = p.xpathEval("//RSpec") if (not context): raise Exception('Request is not an rspec') else: @@ -65,44 +65,23 @@ 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) + if (self.sorted_rule_list): + doc = libxml2.parseDoc(rspec) + doc = self.add_request_context_to_rspec(doc) - intermediate_rspec = doc + 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 + for rule in self.sorted_rule_list: + intermediate_rspec = rule.apply_interpreted(intermediate_rspec) + if (rule.terminal): + break + + final_rspec = self.wrap_up(intermediate_rspec) + else: + final_rspec = rspec - final_rspec = self.wrap_up(intermediate_rspec) return final_rspec def main():