This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author spolematt
Recipients spolematt
Date 2011-09-14.23:11:47
SpamBayes Score 1.1201556e-10
Marked as misclassified No
Message-id <1316041908.49.0.966708119681.issue12984@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2011-09-14 23:11:48spolemattsetrecipients: + spolematt
2011-09-14 23:11:48spolemattsetmessageid: <1316041908.49.0.966708119681.issue12984@psf.upfronthosting.co.za>
2011-09-14 23:11:47spolemattlinkissue12984 messages
2011-09-14 23:11:47spolemattcreate