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 test_safe_parse_xml(self):

        normal_body = ('<?xml version="1.0" ?>'
                       '<foo><bar><v1>hey</v1><v2>there</v2></bar></foo>')

        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)
        # Some versions of minidom inject extra newlines so we ignore them
        result = str(dom.toxml()).replace('\n', '')
        self.assertEqual(normal_body, result)

        self.assertRaises(ValueError,
                          utils.safe_minidom_parse_string,
                          killer_body())
Exemple #3
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 #4
0
    def test_safe_parse_xml(self):

        normal_body = ('<?xml version="1.0" ?>'
                       '<foo><bar><v1>hey</v1><v2>there</v2></bar></foo>')

        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)
        # Some versions of minidom inject extra newlines so we ignore them
        result = str(dom.toxml()).replace('\n', '')
        self.assertEqual(normal_body, result)

        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)
Exemple #7
0
 def update(self, datastring):
     dom = utils.safe_minidom_parse_string(datastring)
     metadata_item = self.extract_metadata(dom)
     return {'body': {'meta': metadata_item}}
Exemple #8
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 #9
0
 def deserialize(self, text):
     dom = utils.safe_minidom_parse_string(text)
     metadata_item = self.extract_metadata(dom)
     return {'body': {'meta': metadata_item}}
Exemple #10
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 #11
0
 def update(self, datastring):
     dom = utils.safe_minidom_parse_string(datastring)
     metadata_item = self.extract_metadata(dom)
     return {'body': {'meta': metadata_item}}
Exemple #12
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 #13
0
 def deserialize(self, text):
     dom = utils.safe_minidom_parse_string(text)
     metadata_item = self.extract_metadata(dom)
     return {'body': {'meta': metadata_item}}
Exemple #14
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}}