Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit beb65f0

Browse files
committed
Update interface.py
Add below interfaces (but only with typing hints, not implemented) * NodeList * NamedNodeMap * Node * Attr * Element * CharacterData * Comment * Text * CDATASection * DocumentType * Notation * Entity * EntityReference * ProcessingInstruction
1 parent 961a83f commit beb65f0

File tree

1 file changed

+141
-16
lines changed

1 file changed

+141
-16
lines changed

‎w3/python/core/interface.py

Lines changed: 141 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from __future__ import annotations
22

3+
from ctypes import c_ushort, c_ulong
34
from typing import Callable
45

56
from w3.python.core.type import DOMString
6-
from w3.python.core.fundamental_interface.Node import Node
7-
from w3.python.core.fundamental_interface.Node import NodeType
8-
from w3.python.typing import *
97

108

119
class DOMImplementation:
@@ -34,6 +32,66 @@ def has_feature(self,
3432
raise NotImplementedError
3533

3634

35+
class NodeList:
36+
item: Callable[[c_ulong], Node]
37+
length: c_ulong
38+
39+
40+
class NamedNodeMap:
41+
getNamedItem: Callable[[DOMString], Node]
42+
setNamedItem: Callable[[Node], Node]
43+
removeNamedItem: Callable[[DOMString], Node]
44+
item: Callable[[c_ulong], Node]
45+
length: c_ulong
46+
47+
48+
class Node:
49+
"""Interface `Node`
50+
51+
The `Node` interface is the primary datatype for the entire Document Object Model.
52+
It represents a single node in the document tree.
53+
While all objects implementing the `Node` interface expose methods for dealing with children, not all objects implementing the `Node` interface may have children.
54+
For example, `Text` nodes may not have children, and adding children to such nodes results in a `DOMException` being raised.
55+
56+
The attributes `node_name`, `node_value` and attributes are included as a mechanism to get at node information without casting down to the specific derived interface.
57+
In cases where there is no obvious mapping of these attributes for a specific `node_type` (e.g., `node_value` for an Element or `attributes` for a Comment), this returns `None`.
58+
Note that the specialized interfaces may contain additional and more convenient mechanisms to get and set the relevant information.
59+
"""
60+
61+
# Definition group `NodeType`
62+
# An integer indicating which type of node this is.
63+
ELEMENT_NODE: c_ushort = c_ushort(1)
64+
ATTRIBUTE_NODE: c_ushort = c_ushort(2)
65+
TEXT_NODE: c_ushort = c_ushort(3)
66+
CDATA_SECTION_NODE: c_ushort = c_ushort(4)
67+
ENTITY_REFERENCE_NODE: c_ushort = c_ushort(5)
68+
ENTITY_NODE: c_ushort = c_ushort(6)
69+
PROCESSING_INSTRUCTION_NODE: c_ushort = c_ushort(7)
70+
COMMENT_NODE: c_ushort = c_ushort(8)
71+
DOCUMENT_NODE: c_ushort = c_ushort(9)
72+
DOCUMENT_TYPE_NODE: c_ushort = c_ushort(10)
73+
DOCUMENT_FRAGMENT_NODE: c_ushort = c_ushort(11)
74+
NOTATION_NODE: c_ushort = c_ushort(12)
75+
76+
nodeName: DOMString
77+
nodeValue: DOMString
78+
nodeType: c_ushort
79+
parentNode: Node
80+
childNodes: NodeList
81+
firstChild: Node
82+
lastChild: Node
83+
previousSibling: Node
84+
nextSibling: Node
85+
attributes: NamedNodeMap
86+
ownerDocument: Document
87+
insertBefore: Callable[[Node, Node], Node]
88+
replaceChild: Callable[[Node, Node], Node]
89+
removeChild: Callable[[Node], Node]
90+
appendChild: Callable[[Node], Node]
91+
hasChildNodes: Callable[[], bool]
92+
cloneNodes: Callable[[bool], Node]
93+
94+
3795
class DocumentFragment(Node):
3896
"""Interface `DocumentFragment`
3997
@@ -60,12 +118,78 @@ def __init__(self,
60118
owner_document: Document,
61119
read_only: bool = False) -> None:
62120
super().__init__(owner_document=owner_document,
63-
node_type=NodeType.DOCUMENT_FRAGMENT_NODE,
121+
node_type=Node.DOCUMENT_FRAGMENT_NODE,
64122
node_name='#document-fragment',
65123
node_value=None,
66124
read_only=read_only)
67125

68126

127+
class Attr(Node):
128+
name: DOMString
129+
specified: bool
130+
value: DOMString
131+
132+
133+
class Element(Node):
134+
tagName: DOMString
135+
getAttribute: Callable[[DOMString], DOMString]
136+
setAttribute: Callable[[DOMString, DOMString], None]
137+
removeAttribute: Callable[[DOMString], None]
138+
getAttributeNode: Callable[[DOMString], Attr]
139+
setAttributeNode: Callable[[Attr], Attr]
140+
removeAttributeNode: Callable[[Attr], Attr]
141+
getElementsByTagName: Callable[[DOMString], NodeList]
142+
normalize: Callable[[], None]
143+
144+
145+
class CharacterData(Node):
146+
data: DOMString
147+
length: c_ulong
148+
substringData: Callable[[c_ulong, c_ulong], DOMString]
149+
appendData: Callable[[DOMString], None]
150+
insertData: Callable[[c_ulong, DOMString], None]
151+
deleteData: Callable[[c_ulong, c_ulong], None]
152+
replaceData: Callable[[c_ulong, c_ulong, DOMString], None]
153+
154+
155+
class Comment(CharacterData):
156+
pass
157+
158+
159+
class Text(CharacterData):
160+
splitText: Callable[[c_ulong], Text]
161+
162+
163+
class CDATASection(Text):
164+
pass
165+
166+
167+
class DocumentType(Node):
168+
name: DOMString
169+
entities: NamedNodeMap
170+
notations: NamedNodeMap
171+
172+
173+
class Notation(Node):
174+
publicId: DOMString
175+
systemId: DOMString
176+
177+
178+
class Entity(Node):
179+
publicId: DOMString
180+
systemId: DOMString
181+
notationName: DOMString
182+
183+
184+
class EntityReference(Node):
185+
pass
186+
187+
188+
class ProcessingInstruction(Node):
189+
target: DOMString
190+
data: DOMString
191+
192+
69193
class Document(Node):
70194
"""Interface Document
71195
@@ -76,22 +200,23 @@ class Document(Node):
76200
The `Node` objects created have a `ownerDocument`` attribute which associates them with the `Document` within whose context they were created.
77201
"""
78202

79-
doctype: _DocumentType
203+
doctype: DocumentType
80204
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]
205+
documentElement: Element
206+
createElement: Callable[[Document, DOMString], Element]
207+
createDocumentFragment: Callable[[Document], DocumentFragment]
208+
createTextNode: Callable[[Document, DOMString], Text]
209+
createComment: Callable[[Document, DOMString], Comment]
210+
createCDATASection: Callable[[Document, DOMString], CDATASection]
211+
createProcessingInstruction: Callable[[
212+
Document, DOMString, DOMString], ProcessingInstruction]
213+
createAttribute: Callable[[Document, DOMString], Attr]
214+
createEntityReference: Callable[[Document, DOMString], EntityReference]
215+
getElementsByTagName: Callable[[Document, DOMString], NodeList]
91216

92217
def __init__(self, read_only: bool = False) -> None:
93218
super().__init__(owner_document=None,
94-
node_type=NodeType.DOCUMENT_NODE,
219+
node_type=Node.DOCUMENT_NODE,
95220
node_name='#document',
96221
node_value=None,
97222
read_only=read_only)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /