Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
    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())
Beispiel #4
0
    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())
Beispiel #5
0
    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)
Beispiel #6
0
    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)}}
Beispiel #8
0
    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)}}
Beispiel #9
0
 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}}
Beispiel #10
0
    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)
Beispiel #11
0
    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}}
Beispiel #12
0
 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 = {}
        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)
Beispiel #14
0
    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)
Beispiel #15
0
 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}}
Beispiel #16
0
 def update(self, datastring):
     dom = utils.safe_minidom_parse_string(datastring)
     metadata_item = self.extract_metadata(dom)
     return {'body': {'meta': metadata_item}}
Beispiel #17
0
 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}}
Beispiel #18
0
 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}}
Beispiel #19
0
 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}}
Beispiel #20
0
 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}}
Beispiel #21
0
 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}}
Beispiel #22
0
 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}}
Beispiel #23
0
 def deserialize(self, text):
     dom = utils.safe_minidom_parse_string(text)
     metadata_item = self.extract_metadata(dom)
     return {'body': {'meta': metadata_item}}
Beispiel #24
0
 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}}
Beispiel #25
0
 def deserialize(self, text):
     dom = utils.safe_minidom_parse_string(text)
     metadata_item = self.extract_metadata(dom)
     return {'body': {'meta': metadata_item}}
Beispiel #26
0
 def update(self, datastring):
     dom = utils.safe_minidom_parse_string(datastring)
     metadata_item = self.extract_metadata(dom)
     return {'body': {'meta': metadata_item}}