Skip to content
4 changes: 3 additions & 1 deletion w3/python/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
"""Module that contains classes of interfaces and ect.
"""
"""

from w3.python.core.fundamental_interface import DOMException
36 changes: 36 additions & 0 deletions w3/python/core/fundamental_interface/DOMException.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import enum


class ExceptionCode(enum.IntEnum):
"""Definition group `ExceptionCode`
An integer indicating the type of error generated.
"""
INDEX_SIZE_ERR = 1
DOMSTRING_SIZE_ERR = 2
HIERARCHY_REQUEST_ERR = 3
WRONG_DOCUMENT_ERR = 4
INVALID_CHARACTER_ERR = 5
NO_DATA_ALLOWED_ERR = 6
NO_MODIFICATION_ALLOWED_ERR = 7
NOT_FOUND_ERR = 8
NOT_SUPPORTED_ERR = 9
INUSE_ATTRIBUTE_ERR = 10


class DOMException(Exception):
"""Exception DOMException

DOM operations only raise exceptions in "exceptional" circumstances, i.e., when an operation is impossible to perform (either for logical reasons, because data is lost, or because the implementation has become unstable). In general, DOM methods return specific error values in ordinary processing situation, such as out-of-bound errors when using `NodeList`.
Implementations may raise other exceptions under other circumstances. For example, implementations may raise an implementation-dependent exception if a null argument is passed.
Some languages and object systems do not support the concept of exceptions. For such systems, error conditions may be indicated using native error reporting mechanisms. For some bindings, for example, methods may return error codes similar to those listed in the corresponding method descriptions.
"""
INDEX_SIZE_ERR = ExceptionCode.INDEX_SIZE_ERR
DOMSTRING_SIZE_ERR = ExceptionCode.DOMSTRING_SIZE_ERR
HIERARCHY_REQUEST_ERR = ExceptionCode.HIERARCHY_REQUEST_ERR
WRONG_DOCUMENT_ERR = ExceptionCode.WRONG_DOCUMENT_ERR
INVALID_CHARACTER_ERR = ExceptionCode.INVALID_CHARACTER_ERR
NO_DATA_ALLOWED_ERR = ExceptionCode.NO_DATA_ALLOWED_ERR
NO_MODIFICATION_ALLOWED_ERR = ExceptionCode.NO_MODIFICATION_ALLOWED_ERR
NOT_FOUND_ERR = ExceptionCode.NOT_FOUND_ERR
NOT_SUPPORTED_ERR = ExceptionCode.NOT_SUPPORTED_ERR
INUSE_ATTRIBUTE_ERR = ExceptionCode.INUSE_ATTRIBUTE_ERR
18 changes: 18 additions & 0 deletions w3/python/core/fundamental_interface/DOMException_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import unittest

from w3.python.core.fundamental_interface.DOMException import DOMException


class Test_DOMException(unittest.TestCase):
def test_raise_INDEX_SIZE_ERR(self):
try:
raise DOMException(DOMException.INDEX_SIZE_ERR)
except DOMException as e:
code = e.args[0]
self.assertEqual(code, DOMException.INDEX_SIZE_ERR)
else:
self.fail()


if __name__ == '__main__':
unittest.main()
8 changes: 8 additions & 0 deletions w3/python/core/fundamental_interface/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""Fundamental Interfaces

The interfaces within this section are considered fundamental, and must be fully implemented by all conforming implementations of the DOM, including all HTML DOM implementations.
"""

from __future__ import absolute_import

from w3.python.core.fundamental_interface.DOMException import DOMException
3 changes: 3 additions & 0 deletions w3/python/dom.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
"""API Module of DOM - Level 1
"""

# Bring in subpackages.
from w3.python.core import DOMException