python - Jython and the xml.sax parser - strange error -
i getting started python/jython , sax parser (xml.sax
). wrote simple content handler test.
from __future__ import with_statement xml.sax import make_parser, handler xml.sax.handler import contenthandler class countinghandler(contenthandler): def __init__(self): self.counter = 0 def startelement(self, name, attrs): self.counter += 1 def main(argv=sys.argv): parser = make_parser() h = countinghandler() parser.setcontenthandler(h) open(argv[1], "r") input: parser.parse(input)
when run on documents (not all), error:
traceback (most recent call last): file "src/sciencenetworks/xmltools.py", line 93, in <module> sys.exit(main()) file "src/sciencenetworks/xmltools.py", line 88, in main parser.parse(input) file "/amd.home/home/staudt/workspace/jython/lib/xml/sax/drivers2/drv_javasax.py", line 141, in parse self._parser.parse(jyinputsourcewrapper(source)) file "/amd.home/home/staudt/workspace/jython/lib/xml/sax/drivers2/drv_javasax.py", line 90, in resolveentity return jyinputsourcewrapper(self._resolver.resolveentity(pubid, sysid)) file "/amd.home/home/staudt/workspace/jython/lib/xml/sax/drivers2/drv_javasax.py", line 75, in __init__ if source.getbytestream(): attributeerror: 'unicode' object has no attribute 'getbytestream'
when source code of drv_javasax.py
, seems input not recognized file object, is.
ideas on how fix this?
i think it's bug: http://bugs.jython.com/issue1488. fixed in jython 2.5.2-b1: http://www.jython.org/latest.html
Comments
Post a Comment