[XML-SIG] expatreader bug

Daniel "eikeon" Krech eikeon@eikeon.com
08 Dec 2002 18:41:40 -0500


--=-VGae5KDpI5MYaymV5z8f
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

SF is currently down and I have been meaning to report what I think is a
small bug in expatreader. I have needed to add the following to some of
my code:

# Workaround for bug in expatreader.py. Needed when
# expatreader is trying to guess a prefix.
#parser.start_namespace_decl("xml",
"http://www.w3.org/XML/1998/namespace")

Attached is a test case for the issue. Let me know if I need to submit
the bug/patch elsewhere or if someone can take it from here?

--eikeon, http://eikeon.com/





--=-VGae5KDpI5MYaymV5z8f
Content-Disposition: attachment; filename=expatreader_test.py
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-python; name=expatreader_test.py; charset=UTF-8

from xml.sax import make_parser
from xml.sax.saxutils import handler, XMLGenerator
from xml.sax.xmlreader import InputSource
from xml.sax.handler import ErrorHandler

from StringIO import StringIO

sio =3D StringIO("""<ex:prop1 xml:space=3D"default">blah</ex:prop1>""")
# As seen in:
# http://www.w3.org/2000/10/rdf-tests/rdfcore/unrecognised-xml-attributes/t=
est001.rdf

source =3D InputSource()
source.setByteStream(sio)

parser =3D make_parser()

# Workaround for bug in expatreader.py. Needed when
# expatreader is trying to guess a prefix.
#parser.start_namespace_decl("xml", "http://www.w3.org/XML/1998/namespace")

parser.setFeature(handler.feature_namespaces, 1)
parser.setContentHandler(XMLGenerator())
parser.setErrorHandler(ErrorHandler())
parser.parse(source)

       =20
# Results of running test against:
#  [eikeon@panther rdflib]$ python2.2 -V
#  Python 2.2.2
#
# [eikeon@panther rdflib]$ python2.2 expatreader_test.py
# <?xml version=3D"1.0" encoding=3D"iso-8859-1"?>
# Traceback (most recent call last):
#   File "expatreader_test.py", line 22, in ?
#     parser.parse(source)
#   File "/usr/local/lib/python2.2/xml/sax/expatreader.py", line 91, in par=
se
#     xmlreader.IncrementalParser.parse(self, source)
#   File "/usr/local/lib/python2.2/xml/sax/xmlreader.py", line 123, in pars=
e
#     self.feed(buffer)
#   File "/usr/local/lib/python2.2/xml/sax/expatreader.py", line 144, in fe=
ed
#     self._parser.Parse(data, isFinal)
#   File "/usr/local/lib/python2.2/xml/sax/expatreader.py", line 246, in st=
art_element_ns
#     prefix =3D self._ns_stack[-1][apair[0]][-1]
# IndexError: list index out of range
# [eikeon@panther rdflib]$


--=-VGae5KDpI5MYaymV5z8f--