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 808225b

Browse files
authored
Merge pull request #36 from Hepheir/Hepheir/issue35
Create module `w3.python.typing` close #36
2 parents c899ee7 + f826178 commit 808225b

File tree

7 files changed

+269
-30
lines changed

7 files changed

+269
-30
lines changed
File renamed without changes.

‎w3/python/core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Module that contains classes of interfaces and ect."""
22

3+
from w3.python.core.DOMString import DOMString
34
from w3.python.core.fundamental_interface import DOMException
45
from w3.python.core.fundamental_interface import DOMImplementation
56
from w3.python.core.fundamental_interface import Node
67
from w3.python.core.fundamental_interface import NodeType
78
from w3.python.core.fundamental_interface import NodeList
8-
from w3.python.core.type import DOMString

‎w3/python/core/fundamental_interface/DOMImplementation.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from __future__ import absolute_import
2-
3-
from w3.python.core.type.DOMString import DOMString
1+
from w3.python.typing import _DOMString
42

53

64
class DOMImplementation:
@@ -12,8 +10,8 @@ class DOMImplementation:
1210

1311
# TODO
1412
def has_feature(self,
15-
feature: DOMString,
16-
version: DOMString) -> bool:
13+
feature: _DOMString,
14+
version: _DOMString) -> bool:
1715
"""<NOT IMPLEMENTED>
1816
Test if the DOM implementation implements a specific feature.
1917

‎w3/python/core/fundamental_interface/Node.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from __future__ import annotations
22

33
import enum
4-
from typing import Dict, Iterable, Optional
4+
from typing import Iterable, Optional
55

66
from w3.python.core.fundamental_interface.DOMException import DOMException
77
from w3.python.core.fundamental_interface.NodeList import NodeList
8-
from w3.python.core.type.DOMString import DOMString
8+
9+
from w3.python.typing import _AnyNode, _Attr, _Document, _DOMString, _NamedNodeMap
910

1011

1112
class NodeType(enum.IntEnum):
@@ -63,9 +64,9 @@ class Node:
6364

6465
def __init__(self,
6566
node_type: NodeType,
66-
node_name: DOMString,
67+
node_name: _DOMString,
6768
owner_document: Optional[_Document],
68-
node_value: Optional[DOMString] = None,
69+
node_value: Optional[_DOMString] = None,
6970
child_nodes: Optional[Iterable[_AnyNode]] = None,
7071
attributes: Optional[Iterable[_AnyNode]] = None,
7172
read_only: bool = False) -> None:
@@ -82,25 +83,25 @@ def __init__(self,
8283
self._read_only = bool(read_only)
8384
# Attributes
8485
self._node_type: NodeType
85-
self._node_name: DOMString
86-
self._node_value: DOMString
86+
self._node_name: _DOMString
87+
self._node_value: _DOMString
8788
self._parent_node: Optional[_AnyNode]
8889
self._child_nodes: NodeList
8990
self._attributes: _NamedNodeMap
9091
self._owner_document: Optional[_Document]
9192
self._read_only: bool
9293

9394
@property
94-
def node_name(self) -> DOMString:
95+
def node_name(self) -> _DOMString:
9596
"""Read only; The name of this node, depending on its type."""
9697
return self._node_name
9798

98-
def _set_node_name(self, name: DOMString) -> None:
99+
def _set_node_name(self, name: _DOMString) -> None:
99100
"""Indirect accessor to set the 'node_name' property."""
100-
self._node_name = DOMString(name)
101+
self._node_name = _DOMString(name)
101102

102103
@property
103-
def node_value(self) -> DOMString:
104+
def node_value(self) -> _DOMString:
104105
"""The value of this node, depending on its type.
105106
106107
Raises:
@@ -111,10 +112,10 @@ def node_value(self) -> DOMString:
111112
return self._node_value
112113

113114
@node_value.setter
114-
def node_value(self, value: DOMString) -> None:
115+
def node_value(self, value: _DOMString) -> None:
115116
self._set_node_value(value)
116117

117-
def _set_node_value(self, value: DOMString) -> None:
118+
def _set_node_value(self, value: _DOMString) -> None:
118119
"""Indirect accessor to set the 'node_value' property.
119120
120121
Raises:
@@ -123,7 +124,7 @@ def _set_node_value(self, value: DOMString) -> None:
123124
"""
124125
if self._read_only:
125126
raise DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)
126-
self._node_value = DOMString(value)
127+
self._node_value = _DOMString(value)
127128

128129
@property
129130
def node_type(self) -> NodeType:
@@ -233,7 +234,7 @@ def attributes(self) -> _NamedNodeMap:
233234
return self._attributes
234235

235236
def _init_attributes(self,
236-
attributes: Optional[Iterable[_AnyNode]] = None) -> None:
237+
attributes: Optional[Iterable[_Attr]] = None) -> None:
237238
self._attributes: _NamedNodeMap = {} # TODO: Replace with real NamedNodeMap #19
238239
if attributes is None:
239240
return
@@ -476,8 +477,3 @@ def copy_recursive(node_iterable: Iterable[_AnyNode]):
476477
read_only=self._read_only
477478
)
478479
return node
479-
480-
481-
_AnyNode = Node
482-
_NamedNodeMap = Dict[str, _AnyNode] # TODO: Implement NamedNodeMap (#19)
483-
_Document = Node # TODO: Implement Document (#20)

‎w3/python/core/fundamental_interface/NodeList.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from typing import Any, Optional
1+
from typing import Optional
22

3+
from w3.python.typing import _AnyNode
34

4-
_AnyNode = Any
55

66
class NodeList(list):
77
"""Interface NodeList

‎w3/python/core/type/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎w3/python/typing/__init__.py

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
"""Module for typing purpose only.
2+
Do not import below classes for actual usage.
3+
"""
4+
5+
from __future__ import annotations
6+
7+
from typing import Iterable, Optional, Union
8+
9+
10+
_DOMString = str
11+
12+
13+
class _ExceptionCode(int):
14+
INDEX_SIZE_ERR = 1
15+
DOMSTRING_SIZE_ERR = 2
16+
HIERARCHY_REQUEST_ERR = 3
17+
WRONG_DOCUMENT_ERR = 4
18+
INVALID_CHARACTER_ERR = 5
19+
NO_DATA_ALLOWED_ERR = 6
20+
NO_MODIFICATION_ALLOWED_ERR = 7
21+
NOT_FOUND_ERR = 8
22+
NOT_SUPPORTED_ERR = 9
23+
INUSE_ATTRIBUTE_ERR = 10
24+
25+
26+
class _DOMException(Exception):
27+
code: int
28+
29+
30+
class _DOMImplementation:
31+
def hasFeature(self,
32+
feature: _DOMString,
33+
version: _DOMString) -> bool: pass
34+
35+
36+
class _NodeType(int):
37+
ELEMENT_NODE = 1
38+
ATTRIBUTE_NODE = 2
39+
TEXT_NODE = 3
40+
CDATA_SECTION_NODE = 4
41+
ENTITY_REFERENCE_NODE = 5
42+
ENTITY_NODE = 6
43+
PROCESSING_INSTRUCTION_NODE = 7
44+
COMMENT_NODE = 8
45+
DOCUMENT_NODE = 9
46+
DOCUMENT_TYPE_NODE = 10
47+
DOCUMENT_FRAGMENT_NODE = 11
48+
NOTATION_NODE = 12
49+
50+
51+
class _Node:
52+
def __init__(self: _Node,
53+
node_type: _NodeType,
54+
node_name: _DOMString,
55+
owner_document: Optional[_Document],
56+
node_value: Optional[_DOMString] = None,
57+
child_nodes: Optional[Iterable[_AnyNode]] = None,
58+
attributes: Optional[Iterable[_AnyNode]] = None,
59+
read_only: bool = False) -> None: pass
60+
node_value: _DOMString
61+
@property
62+
def node_name(self) -> _DOMString: pass
63+
@property
64+
def node_type(self) -> _NodeType: pass
65+
@property
66+
def parent_node(self) -> Optional[_AnyNode]: pass
67+
@property
68+
def child_nodes(self) -> _NodeList: pass
69+
@property
70+
def first_child(self) -> Optional[_AnyNode]: pass
71+
@property
72+
def last_child(self) -> Optional[_AnyNode]: pass
73+
@property
74+
def previous_sibling(self) -> Optional[_AnyNode]: pass
75+
@property
76+
def next_sibling(self) -> Optional[_AnyNode]: pass
77+
@property
78+
def attributes(self) -> _NamedNodeMap: pass
79+
@property
80+
def owner_document(self) -> Optional[_Document]: pass
81+
82+
def insert_before(self,
83+
new_child: _AnyNode,
84+
ref_child: Optional[_AnyNode] = None) -> _AnyNode: pass
85+
86+
def replace_child(self,
87+
new_child: _AnyNode,
88+
old_child: _AnyNode) -> _AnyNode: pass
89+
def remove_child(self,
90+
old_child: _AnyNode) -> _AnyNode: pass
91+
92+
def append_child(self, new_child: _AnyNode) -> _AnyNode: pass
93+
def has_child_nodes(self) -> bool: pass
94+
def clone_node(self, deep: bool = False) -> _AnyNode: pass
95+
96+
97+
class _NodeList:
98+
@property
99+
def length(self) -> int: pass
100+
def item(self, index: int) -> _Node: pass
101+
102+
103+
class _NamedNodeMap:
104+
def getNamedItem(self, name: _DOMString) -> _Node: pass
105+
def setNamedItem(self, arg: _Node) -> _Node: pass
106+
def removeNamedItem(self, name: _DOMString) -> _Node: pass
107+
def item(self, index: int) -> _Node: pass
108+
@property
109+
def length(self) -> int: pass
110+
111+
112+
class _DocumentFragment(_Node):
113+
pass
114+
115+
116+
class _Document(_Node):
117+
@property
118+
def doctype(self) -> _DocumentType: pass
119+
@property
120+
def implementation(self) -> _DOMImplementation: pass
121+
@property
122+
def documentElement(self) -> _Element: pass
123+
def createElement(self, tagName: _DOMString) -> _Element: pass
124+
def createDocumentFragment(self) -> _DocumentFragment: pass
125+
def createTextNode(self, data: _DOMString) -> _Text: pass
126+
def createComment(self, data: _DOMString) -> _Comment: pass
127+
def createCDATASection(self, data: _DOMString) -> _CDATASection: pass
128+
129+
def createProcessingInstruction(self,
130+
target: _DOMString,
131+
data: _DOMString) -> _ProcessingInstruction: pass
132+
133+
def createAttribute(self, name: _DOMString) -> _Attr: pass
134+
def createEntityReference(self, name: _DOMString) -> _EntityReference: pass
135+
def getElementsByTagName(self, tagname: _DOMString) -> _NodeList: pass
136+
137+
138+
class _CharacterData(_Node):
139+
data: _DOMString
140+
@property
141+
def length(self) -> int: pass
142+
143+
def substringData(self,
144+
offset: int,
145+
count: int) -> _DOMString: pass
146+
147+
def appendData(self,
148+
arg: _DOMString) -> None: pass
149+
150+
def insertData(self,
151+
offset: int,
152+
arg: _DOMString) -> None: pass
153+
154+
def deleteData(self,
155+
offset: int,
156+
count: int) -> None: pass
157+
158+
def replaceData(self,
159+
offset: int,
160+
count: int,
161+
arg: _DOMString) -> None: pass
162+
163+
164+
class _Attr(_Node):
165+
value: _DOMString
166+
@property
167+
def name(self) -> _DOMString: pass
168+
@property
169+
def specified(self) -> bool: pass
170+
171+
172+
class _Element(_Node):
173+
@property
174+
def tagName(self) -> _DOMString: pass
175+
def getAttribute(self, name: _DOMString) -> _DOMString: pass
176+
177+
def setAttribute(self,
178+
name: _DOMString,
179+
value: _DOMString) -> None: pass
180+
181+
def removeAttribute(self, name: _DOMString) -> None: pass
182+
def getAttributeNode(self, name: _DOMString) -> _Attr: pass
183+
def setAttributeNode(self, newAttr: _Attr) -> _Attr: pass
184+
def removeAttributeNode(self, oldAttr: _Attr) -> _Attr: pass
185+
def getElementsByTagName(self, name: _DOMString) -> _NodeList: pass
186+
def normalize(self) -> None: pass
187+
188+
189+
class _Text(_CharacterData):
190+
def splitText(self, offset: int) -> _Text: pass
191+
192+
193+
class _Comment(_CharacterData):
194+
pass
195+
196+
197+
class _CDATASection(_Text):
198+
pass
199+
200+
201+
class _DocumentType(_Node):
202+
@property
203+
def name(self) -> _DOMString: pass
204+
@property
205+
def entities(self) -> _NamedNodeMap: pass
206+
@property
207+
def notations(self) -> _NamedNodeMap: pass
208+
209+
210+
class _Notation(_Node):
211+
@property
212+
def publicId(self) -> _DOMString: pass
213+
@property
214+
def systemId(self) -> _DOMString: pass
215+
216+
217+
class _Entity(_Node):
218+
@property
219+
def publicId(self) -> _DOMString: pass
220+
@property
221+
def systemId(self) -> _DOMString: pass
222+
@property
223+
def notationName(self) -> _DOMString: pass
224+
225+
226+
class _EntityReference(_Node):
227+
pass
228+
229+
230+
class _ProcessingInstruction(_Node):
231+
data: _DOMString
232+
@property
233+
def target(self) -> _DOMString: pass
234+
235+
236+
_AnyNode = Union[_Node,
237+
_Document,
238+
_DocumentFragment,
239+
_DocumentType,
240+
_EntityReference,
241+
_Element,
242+
_Attr,
243+
_ProcessingInstruction,
244+
_Comment,
245+
_Text,
246+
_CDATASection,
247+
_Entity,
248+
_Notation]

0 commit comments

Comments
(0)

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