New submission from Matthew Newcomb <spolem...@gmail.com>:

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

----------
components: XML
files: show_bug.py
messages: 144060
nosy: spolematt
priority: normal
severity: normal
status: open
title: XML NamedNodeMap ( attribName in NamedNodeMap fails )
type: crash
versions: Python 2.7
Added file: http://bugs.python.org/file23157/show_bug.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue12984>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to