Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion python/dom/Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from python.dom.DOMException import DOMException
from python.dom.DOMString import DOMString
from python.dom.NotImplemented.NamedNodeMap import NamedNodeMap
from python.dom.NotImplemented.NodeList import NodeList
from python.dom.NodeList import NodeList
from python.dom.type_checking import AnyNode


Expand Down
34 changes: 34 additions & 0 deletions python/dom/NodeList.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from __future__ import absolute_import

from typing import Optional

from python.dom.type_checking import AnyNode


class NodeList(list):
"""Interface NodeList

The `NodeList` interface provides the abstraction of an ordered collection of nodes, without defining or constraining how this collection is implemented.

The items in the `NodeList` are accessible via an integral index, starting from 0.
"""

@property
def length(self) -> int:
"""The number of nodes in the list. The range of valid child node indices is 0 to `length`-1 inclusive.
"""
return len(self)

def item(self, index: int) -> Optional[AnyNode]:
"""Returns the indexth item in the collection. If index is greater than or equal to the number of nodes in the list, this returns `None`.

Args:
index: Index into the collection.

Returns:
The node at the `index`th position in the NodeList, or `None` if that is not a valid index.
"""
if 0 <= index < self.length:
return self[index]
else:
return None
2 changes: 0 additions & 2 deletions python/dom/NotImplemented/NodeList.py

This file was deleted.

1 change: 0 additions & 1 deletion python/dom/NotImplemented/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from python.dom.NotImplemented.Entity import Entity
from python.dom.NotImplemented.EntityReference import EntityReference
from python.dom.NotImplemented.NamedNodeMap import NamedNodeMap
from python.dom.NotImplemented.NodeList import NodeList
from python.dom.NotImplemented.Notation import Notation
from python.dom.NotImplemented.ProcessingInstruction import ProcessingInstruction
from python.dom.NotImplemented.Text import Text
1 change: 1 addition & 0 deletions python/dom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from python.dom.DOMException import DOMException
from python.dom.DOMString import DOMString
from python.dom.Node import Node
from python.dom.NodeList import NodeList
1 change: 1 addition & 0 deletions python/dom/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from python.dom.DOMException import DOMException
from python.dom.DOMString import DOMString
from python.dom.Node import Node
from python.dom.NodeList import NodeList

AnyNode = Union[
Node,
Expand Down