From e7448718ae319fab704d70a7f66431ceb4a1014e Mon Sep 17 00:00:00 2001 From: Hepheir Date: Mon, 31 May 2021 18:52:46 +0900 Subject: [PATCH 1/9] Create fundamental_interface.py --- w3/python/core/fundamental_interfaces/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 w3/python/core/fundamental_interfaces/__init__.py diff --git a/w3/python/core/fundamental_interfaces/__init__.py b/w3/python/core/fundamental_interfaces/__init__.py new file mode 100644 index 0000000..113bc9f --- /dev/null +++ b/w3/python/core/fundamental_interfaces/__init__.py @@ -0,0 +1,4 @@ +"""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 07bf18633e56a07d359cb7029bc5c816095b1082 Mon Sep 17 00:00:00 2001 From: Hepheir Date: Mon, 31 May 2021 18:53:51 +0900 Subject: [PATCH 2/9] Create DOMException.py --- w3/python/core/fundamental_interfaces/DOMException.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 w3/python/core/fundamental_interfaces/DOMException.py diff --git a/w3/python/core/fundamental_interfaces/DOMException.py b/w3/python/core/fundamental_interfaces/DOMException.py new file mode 100644 index 0000000..e69de29 From 9c5ab036411d16d41cfa28ea18bda28ade494734 Mon Sep 17 00:00:00 2001 From: Hepheir Date: Mon, 31 May 2021 18:54:15 +0900 Subject: [PATCH 3/9] Create definition group `ExceptionCode` --- .../core/fundamental_interfaces/DOMException.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/w3/python/core/fundamental_interfaces/DOMException.py b/w3/python/core/fundamental_interfaces/DOMException.py index e69de29..41df0ba 100644 --- a/w3/python/core/fundamental_interfaces/DOMException.py +++ b/w3/python/core/fundamental_interfaces/DOMException.py @@ -0,0 +1,17 @@ +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 From 30d6ce7b833e49facff61d9e28479e86562e2512 Mon Sep 17 00:00:00 2001 From: Hepheir Date: Mon, 31 May 2021 18:54:55 +0900 Subject: [PATCH 4/9] Create `DOMException` which inherits from `ExceptionCode` and `Exception` --- w3/python/core/fundamental_interfaces/DOMException.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/w3/python/core/fundamental_interfaces/DOMException.py b/w3/python/core/fundamental_interfaces/DOMException.py index 41df0ba..9e0ddf6 100644 --- a/w3/python/core/fundamental_interfaces/DOMException.py +++ b/w3/python/core/fundamental_interfaces/DOMException.py @@ -15,3 +15,13 @@ class ExceptionCode(enum.IntEnum): NOT_FOUND_ERR = 8 NOT_SUPPORTED_ERR = 9 INUSE_ATTRIBUTE_ERR = 10 + + +class DOMException(Exception, ExceptionCode): + """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. + """ + pass From 33f2fb0d8b2ecad8545fd2087b95590ee520d101 Mon Sep 17 00:00:00 2001 From: Hepheir Date: Mon, 31 May 2021 18:58:22 +0900 Subject: [PATCH 5/9] Bind `DOMException` to `w3.python.core.fundamental_interfaces` --- w3/python/core/fundamental_interfaces/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/w3/python/core/fundamental_interfaces/__init__.py b/w3/python/core/fundamental_interfaces/__init__.py index 113bc9f..8f44ae8 100644 --- a/w3/python/core/fundamental_interfaces/__init__.py +++ b/w3/python/core/fundamental_interfaces/__init__.py @@ -2,3 +2,7 @@ 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_interfaces.DOMException import DOMException From 131bc9286a44223b6d406f6583e0be94560ad0f3 Mon Sep 17 00:00:00 2001 From: Hepheir Date: Mon, 31 May 2021 19:16:58 +0900 Subject: [PATCH 6/9] Fix TypeError: "cannot extend enumerations" --- .../core/fundamental_interfaces/DOMException.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/w3/python/core/fundamental_interfaces/DOMException.py b/w3/python/core/fundamental_interfaces/DOMException.py index 9e0ddf6..cbc83c1 100644 --- a/w3/python/core/fundamental_interfaces/DOMException.py +++ b/w3/python/core/fundamental_interfaces/DOMException.py @@ -17,11 +17,20 @@ class ExceptionCode(enum.IntEnum): INUSE_ATTRIBUTE_ERR = 10 -class DOMException(Exception, ExceptionCode): +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. """ - pass + 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 From 3673227ee109462f033689f4551ba3a9e6ca996c Mon Sep 17 00:00:00 2001 From: Hepheir Date: Mon, 31 May 2021 19:18:04 +0900 Subject: [PATCH 7/9] Bind `DOMException` to `w3.python.dom` and `w3.python.core` --- w3/python/core/__init__.py | 4 +++- w3/python/dom.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/w3/python/core/__init__.py b/w3/python/core/__init__.py index 8c19b16..0f673ba 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_interfaces 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 From f2be988d15420a70ebbdafa4cca8d7f1978e46d3 Mon Sep 17 00:00:00 2001 From: Hepheir Date: Mon, 31 May 2021 19:27:21 +0900 Subject: [PATCH 8/9] Create unittest for `DOMException` --- .../DOMException_test.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 w3/python/core/fundamental_interfaces/DOMException_test.py diff --git a/w3/python/core/fundamental_interfaces/DOMException_test.py b/w3/python/core/fundamental_interfaces/DOMException_test.py new file mode 100644 index 0000000..62c5404 --- /dev/null +++ b/w3/python/core/fundamental_interfaces/DOMException_test.py @@ -0,0 +1,18 @@ +import unittest + +from w3.python.core.fundamental_interfaces.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() From 1fede8d7b8765fbed47172e535f8a7debbc7ceab Mon Sep 17 00:00:00 2001 From: Hepheir Date: Mon, 31 May 2021 19:30:15 +0900 Subject: [PATCH 9/9] Rename dir "fundamental_interfaces" -> "fundamental_interface' of "w3/python/core/" --- w3/python/core/__init__.py | 2 +- .../DOMException.py | 0 .../DOMException_test.py | 2 +- .../__init__.py | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename w3/python/core/{fundamental_interfaces => fundamental_interface}/DOMException.py (100%) rename w3/python/core/{fundamental_interfaces => fundamental_interface}/DOMException_test.py (83%) rename w3/python/core/{fundamental_interfaces => fundamental_interface}/__init__.py (76%) diff --git a/w3/python/core/__init__.py b/w3/python/core/__init__.py index 0f673ba..4a270a5 100644 --- a/w3/python/core/__init__.py +++ b/w3/python/core/__init__.py @@ -1,4 +1,4 @@ """Module that contains classes of interfaces and ect. """ -from w3.python.core.fundamental_interfaces import DOMException +from w3.python.core.fundamental_interface import DOMException diff --git a/w3/python/core/fundamental_interfaces/DOMException.py b/w3/python/core/fundamental_interface/DOMException.py similarity index 100% rename from w3/python/core/fundamental_interfaces/DOMException.py rename to w3/python/core/fundamental_interface/DOMException.py diff --git a/w3/python/core/fundamental_interfaces/DOMException_test.py b/w3/python/core/fundamental_interface/DOMException_test.py similarity index 83% rename from w3/python/core/fundamental_interfaces/DOMException_test.py rename to w3/python/core/fundamental_interface/DOMException_test.py index 62c5404..99ad7c2 100644 --- a/w3/python/core/fundamental_interfaces/DOMException_test.py +++ b/w3/python/core/fundamental_interface/DOMException_test.py @@ -1,6 +1,6 @@ import unittest -from w3.python.core.fundamental_interfaces.DOMException import DOMException +from w3.python.core.fundamental_interface.DOMException import DOMException class Test_DOMException(unittest.TestCase): diff --git a/w3/python/core/fundamental_interfaces/__init__.py b/w3/python/core/fundamental_interface/__init__.py similarity index 76% rename from w3/python/core/fundamental_interfaces/__init__.py rename to w3/python/core/fundamental_interface/__init__.py index 8f44ae8..d5bb492 100644 --- a/w3/python/core/fundamental_interfaces/__init__.py +++ b/w3/python/core/fundamental_interface/__init__.py @@ -5,4 +5,4 @@ from __future__ import absolute_import -from w3.python.core.fundamental_interfaces.DOMException import DOMException +from w3.python.core.fundamental_interface.DOMException import DOMException