Issue #14168: Check for presence of _attrs before accessing it.

This commit is contained in:
Martin v. Löwis 2012-03-05 07:01:49 +01:00
parent f1c42599ba
commit 67245a6ed4
3 changed files with 18 additions and 3 deletions

View File

@ -362,11 +362,17 @@ class MinidomTest(unittest.TestCase):
def testGetAttrList(self):
pass
def testGetAttrValues(self): pass
def testGetAttrValues(self):
pass
def testGetAttrLength(self): pass
def testGetAttrLength(self):
pass
def testGetAttribute(self): pass
def testGetAttribute(self):
dom = Document()
child = dom.appendChild(
dom.createElementNS("http://www.python.org", "python:abc"))
self.assertEqual(child.getAttribute('missing'), '')
def testGetAttributeNS(self):
dom = Document()
@ -378,6 +384,9 @@ class MinidomTest(unittest.TestCase):
'http://www.python.org')
self.assertEqual(child.getAttributeNS("http://www.w3.org", "other"),
'')
child2 = child.appendChild(dom.createElement('abc'))
self.assertEqual(child2.getAttributeNS("http://www.python.org", "missing"),
'')
def testGetAttributeNode(self): pass

View File

@ -723,12 +723,16 @@ class Element(Node):
Node.unlink(self)
def getAttribute(self, attname):
if self._attrs is None:
return ""
try:
return self._attrs[attname].value
except KeyError:
return ""
def getAttributeNS(self, namespaceURI, localName):
if self._attrsNS is None:
return ""
try:
return self._attrsNS[(namespaceURI, localName)].value
except KeyError:

View File

@ -511,6 +511,8 @@ Core and Builtins
Library
-------
- Issue #14168: Check for presence of _attrs before accessing it.
- Issue #14195: An issue that caused weakref.WeakSet instances to incorrectly
return True for a WeakSet instance 'a' in both 'a < a' and 'a > a' has been
fixed.