def action_peek_xml(body): """Determine action to invoke.""" dom = utils.safe_minidom_parse_string(body) action_node = dom.childNodes[0] return action_node.tagName
def test_safe_parse_xml(self): normal_body = (""" <?xml version="1.0" ?><foo> <bar> <v1>hey</v1> <v2>there</v2> </bar> </foo>""").strip() def killer_body(): return (("""<!DOCTYPE x [ <!ENTITY a "%(a)s"> <!ENTITY b "%(b)s"> <!ENTITY c "%(c)s">]> <foo> <bar> <v1>%(d)s</v1> </bar> </foo>""") % { 'a': 'A' * 10, 'b': '&a;' * 10, 'c': '&b;' * 10, 'd': '&c;' * 9999, }).strip() dom = utils.safe_minidom_parse_string(normal_body) self.assertEqual(normal_body, str(dom.toxml())) self.assertRaises(ValueError, utils.safe_minidom_parse_string, killer_body())
def _from_xml(self, datastring): plurals = set(self.metadata.get('plurals', {})) try: node = utils.safe_minidom_parse_string(datastring).childNodes[0] return {node.nodeName: self._from_xml_node(node, plurals)} except expat.ExpatError: msg = _("cannot understand XML") raise exception.MalformedRequestBody(reason=msg)
def default(self, string): """Deserialize an xml-formatted cell create request.""" try: node = utils.safe_minidom_parse_string(string) except expat.ExpatError: msg = _("cannot understand XML") raise exception.MalformedRequestBody(reason=msg) return {'body': {'cell': self._extract_cell(node)}}
def default(self, string): """Deserialize an xml-formatted security group create request.""" dom = utils.safe_minidom_parse_string(string) security_group = {} sg_node = self.find_first_child_named(dom, 'security_group') if sg_node is not None: if sg_node.hasAttribute('name'): security_group['name'] = sg_node.getAttribute('name') desc_node = self.find_first_child_named(sg_node, "description") if desc_node: security_group['description'] = self.extract_text(desc_node) return {'body': {'security_group': security_group}}
def default(self, string): try: node = utils.safe_minidom_parse_string(string) except expat.ExpatError: msg = _("cannot understand XML") raise exception.MalformedRequestBody(reason=msg) updates = {} for child in node.childNodes[0].childNodes: updates[child.tagName] = self.extract_text(child) return dict(body=updates)
def default(self, string): dom = utils.safe_minidom_parse_string(string) action_node = dom.childNodes[0] action_name = action_node.tagName action_data = {} attributes = ["force", "image_name", "container_format", "disk_format"] for attr in attributes: if action_node.hasAttribute(attr): action_data[attr] = action_node.getAttribute(attr) if 'force' in action_data and action_data['force'] == 'True': action_data['force'] = True return {'body': {action_name: action_data}}
def default(self, string): try: node = utils.safe_minidom_parse_string(string) except expat.ExpatError: msg = _("cannot understand XML") raise exception.MalformedRequestBody(reason=msg) updates = {} updates_node = self.find_first_child_named(node, 'updates') if updates_node is not None: maintenance = self.find_first_child_named(updates_node, 'maintenance_mode') if maintenance is not None: updates[maintenance.tagName] = self.extract_text(maintenance) status = self.find_first_child_named(updates_node, 'status') if status is not None: updates[status.tagName] = self.extract_text(status) return dict(body=updates)
def default(self, string): """Deserialize an xml-formatted volume create request.""" dom = utils.safe_minidom_parse_string(string) volume = self._extract_volume(dom) return {'body': {'volume': volume}}
def update(self, datastring): dom = utils.safe_minidom_parse_string(datastring) metadata_item = self.extract_metadata(dom) return {'body': {'meta': metadata_item}}
def _extract_metadata_container(self, datastring): dom = utils.safe_minidom_parse_string(datastring) metadata_node = self.find_first_child_named(dom, "metadata") metadata = self.extract_metadata(metadata_node) return {'body': {'metadata': metadata}}
def deserialize(self, text): dom = utils.safe_minidom_parse_string(text) metadata_node = self.find_first_child_named(dom, "metadata") metadata = self.extract_metadata(metadata_node) return {'body': {'metadata': metadata}}
def default(self, string): """Deserialize an xml-formatted volume create request.""" dom = utils.safe_minidom_parse_string(string) vol = self._extract_volume(dom) return {'body': {'volume': vol}}
def default(self, string): """Deserialize an xml-formatted security group create request.""" dom = utils.safe_minidom_parse_string(string) security_group_rule = self._extract_security_group_rule(dom) return {'body': {'security_group_rule': security_group_rule}}
def deserialize(self, text): dom = utils.safe_minidom_parse_string(text) metadata_item = self.extract_metadata(dom) return {'body': {'meta': metadata_item}}