Skip to content

Implement of Node's properties (#16) #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 47 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
3c0e730
Implement `DOMString`
hepheir May 26, 2021
cc0beb3
Implement `DOMException`
hepheir May 26, 2021
8367ba7
Implement properties of interface Node (#3)
hepheir May 27, 2021
f87d4d2
Implement interface NodeList (#6)
hepheir May 27, 2021
ee746b1
Remove `python.*` module.
hepheir May 31, 2021
54c5d09
Add .pylintrc
hepheir May 31, 2021
1ade380
Design the basic structure of the module
hepheir May 31, 2021
547801e
Create `DOMString` and `AnyNode` types
hepheir May 31, 2021
3199b5d
Implement of Interface DOMException (#11)
hepheir May 31, 2021
ea77456
Implement of interface DOMImplementation (#12)
hepheir May 31, 2021
55118b0
Add some details for "w3/__init__.py"
hepheir May 31, 2021
ec81151
Create Node.py
hepheir May 31, 2021
b9e72f9
Create definition group `NodeType`
hepheir May 31, 2021
f56d30b
Create interface `Node`
hepheir May 31, 2021
c908e5e
Change the type of `DOMString` from `TypeVar` into `str`
hepheir May 31, 2021
b8221c3
Create read-only attribute `node_name`
hepheir Jun 1, 2021
5a056b3
Create accessor attribute `_read_only` and method `_check_modifiable()`
hepheir Jun 1, 2021
b960da7
Create attribute `node_value`
hepheir Jun 1, 2021
8e7cc52
Create readonly attribute `node_type`
hepheir Jun 1, 2021
1720ff3
Create unittest for `w3.python.core.fundamental_interface.Node`
hepheir Jun 1, 2021
71a8109
Fix AttributeError: 'Node' object has no attribute '_read_only'
hepheir Jun 1, 2021
af22904
Deprecate direct access to protected attribute
hepheir Jun 1, 2021
c70a536
Add more 'wrong node type' cases
hepheir Jun 1, 2021
2949130
Create test for `node_value`
hepheir Jun 1, 2021
3c9748f
Fix `DOMException` while initiation of `Node`
hepheir Jun 1, 2021
a5d91f3
Create "w3/python/__init__.py"
hepheir Jun 1, 2021
6c92e17
Add typing hint for `_node_type`
hepheir Jun 2, 2021
c6a040f
Create `_AnyNode` for typing
hepheir Jun 2, 2021
8a6f0ab
Create readonly attribute `parent_node`
hepheir Jun 2, 2021
7ae58d7
Fix TypeError (`_AnyNode`): A single constraint is not allowed
hepheir Jun 2, 2021
a897024
Create unittest for `Node.parent_node`
hepheir Jun 2, 2021
26bd792
Unimport unused var `TypeVar`
hepheir Jun 2, 2021
641ba8f
Implement of interface NodeList (#14)
hepheir Jun 2, 2021
9c924ec
Fix Circular import issue in `NodeList` (#15)
hepheir Jun 2, 2021
4a1e321
Create readonly attribute `child_nodes`
hepheir Jun 2, 2021
fc6fe0a
Bind `Node` and `NodeList` to `w3.python.dom`
hepheir Jun 2, 2021
dd0a41a
Relocate `dom` and `parser` direct under the `w3`
hepheir Jun 2, 2021
77cb7ca
Update import paths of all unittests
hepheir Jun 2, 2021
65e2872
Create readonly attributes `first_child`, `last_child`
hepheir Jun 2, 2021
3859665
Add unittests to test `NodeList`'s `list`-like behaviors
hepheir Jun 2, 2021
cb87f92
Squashed commit of the following:
hepheir Jun 2, 2021
4d554cd
Add missing decorater; `property`
hepheir Jun 2, 2021
e7e7f94
Create readonly attributes `previous_sibling`, `next_sibling`
hepheir Jun 2, 2021
6edfd99
Create readonly attribute `attributes` #16
hepheir Jun 3, 2021
9c18ce3
Create readonly attribute `owner_document` (#16)
hepheir Jun 3, 2021
32c2801
Apply autopep8 & minor comment changes
hepheir Jun 3, 2021
b590a07
Fix doc-strings.
hepheir Jun 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .pylintrc
Binary file not shown.
Empty file removed python/__init__.py
Empty file.
2 changes: 0 additions & 2 deletions python/dom/NotImplemented/Attr.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/dom/NotImplemented/CDATASection.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/dom/NotImplemented/CharacterData.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/dom/NotImplemented/Comment.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/dom/NotImplemented/DOMException.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/dom/NotImplemented/DOMImplementation.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/dom/NotImplemented/DOMString.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/dom/NotImplemented/Document.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/dom/NotImplemented/DocumentFragment.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/dom/NotImplemented/DocumentType.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/dom/NotImplemented/Element.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/dom/NotImplemented/Entity.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/dom/NotImplemented/EntityReference.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/dom/NotImplemented/NamedNodeMap.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/dom/NotImplemented/Node.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/dom/NotImplemented/NodeList.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/dom/NotImplemented/Notation.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/dom/NotImplemented/ProcessingInstruction.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/dom/NotImplemented/Text.py

This file was deleted.

21 changes: 0 additions & 21 deletions python/dom/NotImplemented/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion python/dom/__init__.py

This file was deleted.

23 changes: 0 additions & 23 deletions python/dom/type_checking.py

This file was deleted.

Empty file removed python/parser/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions w3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""A Python HTML Parser
This is a personal project owned by Hepheir.

https://github.com/Hepheir/Python-HTML-Parser/
"""

from w3 import dom
from w3 import parser


__version__ = '0.0.0'

__author__ = '[email protected]'
9 changes: 9 additions & 0 deletions w3/dom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""API Module of DOM - Level 1"""


# Bring in subpackages.
from w3.python.core import DOMException
from w3.python.core import DOMImplementation
from w3.python.core import Node
from w3.python.core import NodeType
from w3.python.core import NodeList
1 change: 1 addition & 0 deletions w3/parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""A Parser module for building Document Object Model Structure parsed from text/html."""
6 changes: 6 additions & 0 deletions w3/python/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Imports core names of w3.

Interfaces are implemented under "./core/"
"""

from w3.python import core
7 changes: 7 additions & 0 deletions w3/python/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Module that contains classes of interfaces and ect."""

from w3.python.core.fundamental_interface import DOMException
from w3.python.core.fundamental_interface import DOMImplementation
from w3.python.core.fundamental_interface import Node
from w3.python.core.fundamental_interface import NodeType
from w3.python.core.fundamental_interface import NodeList
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.dom 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()
29 changes: 29 additions & 0 deletions w3/python/core/fundamental_interface/DOMImplementation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from __future__ import absolute_import

from w3.python.core.type import DOMString


class DOMImplementation:
"""Interface DOMImplementation

The `DOMImplementation` interface provides a number of methods for performing operations that are independent of any particular instance of the document object model.
The DOM Level 1 does not specify a way of creating a document instance, and hence document creation is an operation specific to an implementation. Future Levels of the DOM specification are expected to provide methods for creating documents directly.
"""

# TODO
def has_feature(self,
feature: DOMString,
version: DOMString) -> bool:
"""<NOT IMPLEMENTED>
Test if the DOM implementation implements a specific feature.

Args:
feature: The package name of the feature to test. In Level 1, the legal values are "HTML" and "XML" (case-insensitive).
version: This is the version number of the package name to test. In Level 1, this is the string "1.0". If the version is not specified, supporting any version of the feature will cause the method to return true.

Returns:
`True` if the feature is implemented in the specified version, `False` otherwise.

This method raises no exceptions.
"""
raise NotImplementedError
Loading