Exemple #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
Exemple #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
Exemple #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())
Exemple #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())
Exemple #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)
Exemple #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)}}
Exemple #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)}}
Exemple #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}}
Exemple #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)
Exemple #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}}
Exemple #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)
Exemple #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)
Exemple #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}}
Exemple #16
0
 def update(self, datastring):
     dom = utils.safe_minidom_parse_string(datastring)
     metadata_item = self.extract_metadata(dom)
     return {'body': {'meta': metadata_item}}
Exemple #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}}
Exemple #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}}
Exemple #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}}
Exemple #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}}
Exemple #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}}
Exemple #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}}
Exemple #23
0
 def deserialize(self, text):
     dom = utils.safe_minidom_parse_string(text)
     metadata_item = self.extract_metadata(dom)
     return {'body': {'meta': metadata_item}}
Exemple #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}}
Exemple #25
0
 def deserialize(self, text):
     dom = utils.safe_minidom_parse_string(text)
     metadata_item = self.extract_metadata(dom)
     return {'body': {'meta': metadata_item}}
Exemple #26
0
 def update(self, datastring):
     dom = utils.safe_minidom_parse_string(datastring)
     metadata_item = self.extract_metadata(dom)
     return {'body': {'meta': metadata_item}}