[XML-SIG] Specializing DOM exceptions

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Fri, 24 Nov 2000 22:22:39 +0100

I'd like to propose an enhancement to the DOM exception classes,
namely that different codes are mapped to different subclasses:

class IndexSizeErr(DOMException):
      code = INDEX_SIZE_ERR

class DomstringSizeErr(DOMException):

class HierarchyRequestErr(DOMException):

class WrongDocument(DOMException):


That will simplify raising the exceptions, and catching a specific one
if desired. It will still provide the backwards-compatibility of
accessing .code of the exception (which should *not* be removed, even
after a while, IMO).

Also, I'd like to make DOMException, the code constants, and the
derived classes part of the official Python API, so all DOM
implementations use the same set of exceptions.

I'd like to re-arrange the internationalization in this code:
It shouldn't take a %i parameter, since the traceback will read

IndexSizeErr: DOM Error Code 1: Index error accessing NodeList or NamedNodeMap

Instead, it should read

IndexSizeErr: Indexfehler beim Zugriff auf NodeList oder NamedNodeMap

I'd like to use gettext if available, so that somebody may actually
consider translating the messages - or drop the idea of translating
the __str__ representation of a DOM exception.

What do you think?