[XML-SIG] Specializing DOM exceptions

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Thu, 7 Dec 2000 17:20:32 +0100


> The DOM documentation does not mention a Python IndexSizeErr exception.
> That's part of the Python binding so you can only find out about it in
> the Python documentation.

No, but it does mention DOMException with an INDEX_SIZE_ERR code. Such
an exception is represented in Python by an IndexSizeErr object (which
is indeed a DOMException instance with a .code field of
INDEX_SIZE_ERR).  So Python's IndexSizeErr and DOM's INDEX_SIZE_ERR
are really one and the same - it's just that IDL cannot express
exception specialization.

> > (*) In DOM, childNodes does not have a []-operator; only a method
> > item(). Interestingly enough, that method is specified to return null
> > in case of an out-of-range index, not to raise INDEX_SIZE_ERR.
> 
> That's part of the Python binding also:
> 
> >>> from xml.dom.minidom import parse
> >>> d = parse("c:\\temp\\test.xml")
> <xml.dom.minidom.Document instance at 0083C15C>
> >>> d.childNodes[0]
> <DOM Element: abc at 8452044>
> 
> I don't think returning null would be very Pythonic.

Indeed. The childNodes collection behaves like a Python sequence - so
you'd expect sequence exceptions for the sequence operations. It is
also a DOM NodeList implementation, and I'd expect DOM exceptions for
DOM operations. I would not, however, expect standard Python
exceptions coming out of DOM operations, or DOM exceptions coming out
of Python sequence operations.

Again, if you think otherwise, just propose a specification (or is

class IndexSizeErr(DOMException, IndexError):
  code = INDEX_SIZE_ERR

really all that you are proposing?) I won't object to adding specific
text or code, even if I don't see a value in such an addition.

Regards,
Martin