Message144060
I was cleaning up some old code to make it pep8 compliant and came across this bug. Switching from 'has_key' to 'in' does not work with a xml.dom.minidom.NamedNodeMap. An easy solution appears to be to add a '__contains__' method to NamedNodeMap.
This is with:
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
[GCC 4.5.2] on linux2
I've tried it with 2.4.3 as well ( on some older machines ).
import xml.dom.minidom
def show_bug():
document = '<dom mbid="5">foobar_attributes</dom>'
dom = xml.dom.minidom.parseString(document)
attribs = dom.getElementsByTagName('dom')[0].attributes
if attribs.has_key('mbid'):
print "This works.. found 'mbid' attribute"
if 'mbid' in attribs:
print "Will never get here, the above will throw an exception"
>>> show_bug()
This works.. found 'mbid' attribute
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "show_bug.py", line 11, in show_bug
if 'mbid' in attribs:
File "/usr/lib/python2.7/xml/dom/minidom.py", line 524, in __getitem__
return self._attrs[attname_or_tuple]
KeyError: 0 |
|
Date |
User |
Action |
Args |
2011-09-14 23:11:48 | spolematt | set | recipients:
+ spolematt |
2011-09-14 23:11:48 | spolematt | set | messageid: <1316041908.49.0.966708119681.issue12984@psf.upfronthosting.co.za> |
2011-09-14 23:11:47 | spolematt | link | issue12984 messages |
2011-09-14 23:11:47 | spolematt | create | |
|