X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfatables%2Fruntime.py;h=f9263fb1261cb5b621505ac95770b00d45c3066b;hb=e1935395cc54882f3828b747959c414759227610;hp=05e692a66cc970ef58e09246df95e3c7995323a3;hpb=0d45168e3193ee97adccbf261cffacb28a63fcf7;p=sfa.git diff --git a/sfatables/runtime.py b/sfatables/runtime.py index 05e692a6..f9263fb1 100644 --- a/sfatables/runtime.py +++ b/sfatables/runtime.py @@ -50,12 +50,14 @@ class SFATablesRules: childNode = self.create_xml_node(k, context_dict[k]) node.addChild(childNode) else: - node.addContent(context_dict[k]) + childNode = libxml2.newNode(k) + childNode.addContent(context_dict[k]) + node.addChild(childNode) return node 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: @@ -67,17 +69,21 @@ class SFATablesRules: 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: + (matched,intermediate_rspec) = rule.apply_interpreted(intermediate_rspec) + if (rule.terminal and matched): + 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():