+ if not os.path.exists(filepath):
+ raise Exception('Could not find final rule filter')
+
+ styledoc = libxml2.parseFile(filepath)
+ style = libxslt.parseStylesheetDoc(styledoc)
+ result = style.applyStylesheet(doc, None)
+ stylesheet_result = style.saveResultToString(result)
+ style.freeStylesheet()
+ doc.freeDoc()
+ result.freeDoc()
+
+ return stylesheet_result
+
+ def set_context(self, request_context):
+ self.active_context = request_context
+ return
+
+ def create_xml_node(self, name, context_dict):
+ node = libxml2.newNode(name)
+ for k in context_dict.keys():
+ if (type(context_dict[k])==dict):
+ childNode = self.create_xml_node(k, context_dict[k])
+ node.addChild(childNode)
+ else:
+ 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")
+ if (not context):
+ raise Exception('Request is not an rspec')
+ else:
+ # Add the request context
+ requestNode = self.create_xml_node('request-context',self.active_context)
+ context[0].addChild(requestNode)
+ p.xpathFreeContext()
+ return doc
+
+