[pypy-issue] [issue933] AttributeError: 'pyexpat.XMLParserType' object has no attribute 'StartElementHandler'

Peter tracker at bugs.pypy.org
Mon Nov 21 15:33:10 CET 2011


New submission from Peter <p.j.a.cock at googlemail.com>:

I didn't report this earlier as our code was blocked by Issue 914, which is now
fixed in PyPy 1.7.

Expected behaviour to match C Python:


$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from xml.parsers import expat
>>> p = expat.ParserCreate(namespace_separator=" ")
>>> p.StartElementHandler
>>> p.StartElementHandler is None
True
>>> quit()

Actual behaviour of PyPy 1.6 (same as PyPy 1.7):

$ pypy1.6
Python 2.7.1 (dcae7aed462b, Aug 17 2011, 09:46:15)
[PyPy 1.6.0 with GCC 4.0.1] on darwin
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``Bureaucrats build academic
empires which churn out meaningless solutions to irrelevant problems.''
>>>> from xml.parsers import expat
>>>> p = expat.ParserCreate(namespace_separator=" ")
>>>> p.StartElementHandler is None
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'pyexpat.XMLParserType' object has no attribute
'StartElementHandler'
>>>> quit()

Actual behaviour of PyPy 1.6 (same as PyPy 1.6):


$ pypy1.7
Python 2.7.1 (7773f8fc4223, Nov 18 2011, 22:15:49)
[PyPy 1.7.0 with GCC 4.0.1] on darwin
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``"there are days on which you look
around and nothing should have ever worked" (fijal)''
>>>> from xml.parsers import expat
>>>> p = expat.ParserCreate(namespace_separator=" ")
>>>> p.StartElementHandler is None
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'pyexpat.XMLParserType' object has no attribute
'StartElementHandler'
>>>> quit()


See also: http://docs.python.org/library/pyexpat.html

Note the short example given there works fine under PyPy 1.6 and 1.7, namely:

import xml.parsers.expat
# 3 handler functions
def start_element(name, attrs):
    print 'Start element:', name, attrs
def end_element(name):
    print 'End element:', name
def char_data(data):
    print 'Character data:', repr(data)
p = xml.parsers.expat.ParserCreate()
p.StartElementHandler = start_element
p.EndElementHandler = end_element
p.CharacterDataHandler = char_data
p.Parse("""<?xml version="1.0"?>
<parent id="top"><child1 name="paul">Text goes here</child1>
<child2 name="fred">More text</child2>
</parent>""", 1)

It would appear that this is a simple initialisation issue (C Python creates the
attribute and sets it to None, PyPy does not).

----------
messages: 3451
nosy: peterjc, pypy-issue
priority: bug
release: 1.7
status: unread
title: AttributeError: 'pyexpat.XMLParserType' object has no attribute 'StartElementHandler'

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue933>
________________________________________


More information about the pypy-issue mailing list