X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfatables%2Fruntime.py;h=f9263fb1261cb5b621505ac95770b00d45c3066b;hb=a7a01a6a19f91fccb0bda1c60454ebe2cc848d2d;hp=e948d0510b5475d8bd7741938597a2e75e272de6;hpb=429e5214b5e839964e10d540bea97480fb6fcd74;p=sfa.git diff --git a/sfatables/runtime.py b/sfatables/runtime.py index e948d051..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,18 +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) - intermediate_rspec = XMLRule().wrap_up(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():