[Jython-checkins] jython: JavaSAXParser was missing implementation for skippedEntity, fixed + test
darjus.loktevic
jython-checkins at python.org
Tue Oct 6 11:51:24 CEST 2015
https://hg.python.org/jython/rev/51c2e62391f8
changeset: 7740:51c2e62391f8
user: Darjus Loktevic <darjus at gmail.com>
date: Tue Oct 06 20:42:47 2015 +1100
summary:
JavaSAXParser was missing implementation for skippedEntity, fixed + test
files:
Lib/test/test_xml_sax_jy.py | 67 +++++++++++++++++
Lib/xml/sax/drivers2/drv_javasax.py | 4 +
2 files changed, 71 insertions(+), 0 deletions(-)
diff --git a/Lib/test/test_xml_sax_jy.py b/Lib/test/test_xml_sax_jy.py
new file mode 100644
--- /dev/null
+++ b/Lib/test/test_xml_sax_jy.py
@@ -0,0 +1,67 @@
+import unittest
+from test import test_support
+
+from StringIO import StringIO
+
+import xml.sax
+import xml.sax.handler
+
+
+class XmlHandler(xml.sax.ContentHandler):
+
+ def __init__(self, root_node, connection):
+ self.connection = connection
+ self.nodes = [('root', root_node)]
+ self.current_text = ''
+
+ def startElement(self, name, attrs):
+ self.current_text = ''
+ new_node = self.nodes[-1][1].startElement(name, attrs, self.connection)
+ if new_node is not None:
+ self.nodes.append((name, new_node))
+
+ def endElement(self, name):
+ self.nodes[-1][1].endElement(name, self.current_text, self.connection)
+ if self.nodes[-1][0] == name:
+ if hasattr(self.nodes[-1][1], 'endNode'):
+ self.nodes[-1][1].endNode(self.connection)
+ self.nodes.pop()
+ self.current_text = ''
+
+ def characters(self, content):
+ self.current_text += content
+
+
+class RootElement(object):
+ def __init__(self):
+ self.start_elements = []
+ self.end_elements = []
+ def startElement(self, name, attrs, connection):
+ self.start_elements.append([name, attrs, connection])
+
+ def endElement(self, name, value, connection):
+ self.end_elements.append([name, value, connection])
+
+
+class JavaSaxTestCase(unittest.TestCase):
+
+ def test_javasax_with_skipEntity(self):
+ content = '<!DOCTYPE Message [<!ENTITY xxe SYSTEM "http://aws.amazon.com/">]><Message>error:&xxe;</Message>'
+
+ root = RootElement()
+ handler = XmlHandler(root, root)
+ parser = xml.sax.make_parser()
+ parser.setContentHandler(handler)
+ parser.setFeature(xml.sax.handler.feature_external_ges, 0)
+ parser.parse(StringIO(content))
+
+ self.assertEqual('Message', root.start_elements[0][0])
+ self.assertItemsEqual([['Message', 'error:', root]], root.end_elements)
+
+
+def test_main():
+ test_support.run_unittest(JavaSaxTestCase)
+
+
+if __name__ == '__main__':
+ test_main()
diff --git a/Lib/xml/sax/drivers2/drv_javasax.py b/Lib/xml/sax/drivers2/drv_javasax.py
--- a/Lib/xml/sax/drivers2/drv_javasax.py
+++ b/Lib/xml/sax/drivers2/drv_javasax.py
@@ -237,6 +237,10 @@
def endEntity(self, name):
pass # TODO
+ def skippedEntity(self, name):
+ pass
+
+
def _fixTuple(nsTuple, frm, to):
if isinstance(nsTuple, tuple) and len(nsTuple) == 2:
nsUri, localName = nsTuple
--
Repository URL: https://hg.python.org/jython
More information about the Jython-checkins
mailing list