Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d1b5ea

Browse files
committed
Add code to DOMException to ensure it cannot be instantiated directly,
since the API documentation will state specifically that the specializations must be used by the DOM implementations.
1 parent 64acf1d commit 5d1b5ea

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

Lib/xml/dom/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Node:
3838
DOCUMENT_FRAGMENT_NODE = 11
3939
NOTATION_NODE = 12
4040

41+
4142
#ExceptionCode
4243
INDEX_SIZE_ERR = 1
4344
DOMSTRING_SIZE_ERR = 2
@@ -55,11 +56,17 @@ class Node:
5556
NAMESPACE_ERR = 14
5657
INVALID_ACCESS_ERR = 15
5758

59+
5860
class DOMException(Exception):
5961
"""Abstract base class for DOM exceptions.
6062
Exceptions with specific codes are specializations of this class."""
6163

62-
pass
64+
def __init__(self, *args, **kw):
65+
if self.__class__ is DOMException:
66+
raise RuntimeError(
67+
"DOMException should not be instaniated directly")
68+
apply(Exception.__init__, args, kw)
69+
6370

6471
class IndexSizeErr(DOMException):
6572
code = INDEX_SIZE_ERR

0 commit comments

Comments
 (0)