Skip to content

Commit 961a83f

Browse files
committed
Add Document
1 parent ba71cb9 commit 961a83f

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

w3/python/core/interface.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
from __future__ import annotations
2+
3+
from typing import Callable
4+
15
from w3.python.core.type import DOMString
26
from w3.python.core.fundamental_interface.Node import Node
37
from w3.python.core.fundamental_interface.Node import NodeType
4-
from w3.python.typing import _Document
8+
from w3.python.typing import *
59

610

711
class DOMImplementation:
@@ -53,10 +57,41 @@ class DocumentFragment(Node):
5357
"""
5458

5559
def __init__(self,
56-
owner_document: _Document,
60+
owner_document: Document,
5761
read_only: bool = False) -> None:
5862
super().__init__(owner_document=owner_document,
5963
node_type=NodeType.DOCUMENT_FRAGMENT_NODE,
6064
node_name='#document-fragment',
6165
node_value=None,
6266
read_only=read_only)
67+
68+
69+
class Document(Node):
70+
"""Interface Document
71+
72+
The `Document` interface represents the entire HTML or XML document.
73+
Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
74+
75+
Since elements, text nodes, comments, processing instructions, etc. cannot exist outside the context of a `Document`, the `Document` interface also contains the factory methods needed to create these objects.
76+
The `Node` objects created have a `ownerDocument`` attribute which associates them with the `Document` within whose context they were created.
77+
"""
78+
79+
doctype: _DocumentType
80+
implementation: DOMImplementation
81+
documentElement: _Element
82+
createElement: Callable[[Document, DOMString], _Element]
83+
createDocumentFragment: Callable[[Document], _DocumentFragment]
84+
createTextNode: Callable[[Document, DOMString], _Text]
85+
createComment: Callable[[Document, DOMString], _Comment]
86+
createCDATASection: Callable[[Document, DOMString], _CDATASection]
87+
createProcessingInstruction: Callable[[Document, DOMString, DOMString], _ProcessingInstruction]
88+
createAttribute: Callable[[Document, DOMString], _Attr]
89+
createEntityReference: Callable[[Document, DOMString], _EntityReference]
90+
getElementsByTagName: Callable[[Document, DOMString], _NodeList]
91+
92+
def __init__(self, read_only: bool = False) -> None:
93+
super().__init__(owner_document=None,
94+
node_type=NodeType.DOCUMENT_NODE,
95+
node_name='#document',
96+
node_value=None,
97+
read_only=read_only)

0 commit comments

Comments
 (0)