diff --git a/w3/python/core/__init__.py b/w3/python/core/__init__.py index 8c19b16..4a270a5 100644 --- a/w3/python/core/__init__.py +++ b/w3/python/core/__init__.py @@ -1,2 +1,4 @@ """Module that contains classes of interfaces and ect. -""" \ No newline at end of file +""" + +from w3.python.core.fundamental_interface import DOMException diff --git a/w3/python/core/fundamental_interface/DOMException.py b/w3/python/core/fundamental_interface/DOMException.py new file mode 100644 index 0000000..cbc83c1 --- /dev/null +++ b/w3/python/core/fundamental_interface/DOMException.py @@ -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 diff --git a/w3/python/core/fundamental_interface/DOMException_test.py b/w3/python/core/fundamental_interface/DOMException_test.py new file mode 100644 index 0000000..99ad7c2 --- /dev/null +++ b/w3/python/core/fundamental_interface/DOMException_test.py @@ -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() diff --git a/w3/python/core/fundamental_interface/__init__.py b/w3/python/core/fundamental_interface/__init__.py new file mode 100644 index 0000000..d5bb492 --- /dev/null +++ b/w3/python/core/fundamental_interface/__init__.py @@ -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 diff --git a/w3/python/dom.py b/w3/python/dom.py index d49aa20..1d5ec41 100644 --- a/w3/python/dom.py +++ b/w3/python/dom.py @@ -1,2 +1,5 @@ """API Module of DOM - Level 1 """ + +# Bring in subpackages. +from w3.python.core import DOMException