New submission from Mark Summerfield <[EMAIL PROTECTED]>: The tiny program at the end of this message runs under Python 2.5 & 30a3. Under 2 it gives the following output:
: python sax.py test.xml ('+', u'document') ('+', u'outer') ('+', u'inner') ('-', u'inner') ('-', u'outer') ('-', u'document') Done Under 3 it does not terminate: : python3 sax.py test.xml + document + outer + inner - inner - outer - document Traceback (most recent call last): File "sax.py", line 19, in <module> parser.parse(sys.argv[1]) File "/home/mark/opt/python30a3/lib/python3.0/xml/sax/expatreader.py", line 107, in parse xmlreader.IncrementalParser.parse(self, source) File "/home/mark/opt/python30a3/lib/python3.0/xml/sax/xmlreader.py", line 124, in parse buffer = file.read(self._bufsize) File "/home/mark/opt/python30a3/lib/python3.0/io.py", line 774, in read current = self.raw.read(to_read) KeyboardInterrupt The xml.sax.parser() function seems to work fine if you give it an open file object and close the file after the call. But the documentation says you can give it a filename, but if you do that the parser does not terminate in Python 3 although it works fine in Python 2. # sax.py import sys import xml.sax BUG = True class SaxHandler(xml.sax.handler.ContentHandler): def startElement(self, name, attributes): print("+", name) def endElement(self, name): print("-", name) handler = SaxHandler() parser = xml.sax.make_parser() parser.setContentHandler(handler) if BUG: parser.parse(sys.argv[1]) else: fh = open(sys.argv[1], encoding="utf8") parser.parse(fh) fh.close() print("Done") # end of sax.py Here is the test file: <?xml version="1.0" encoding="UTF-8"?> <document> <outer> <inner> </inner> </outer> </document> ---------- components: XML messages: 64625 nosy: mark severity: normal status: open title: xml.sax.parser() doesn't terminate when given a filename type: behavior versions: Python 3.0 __________________________________ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2501> __________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com