Commit c4a9089a authored by di68kap's avatar di68kap

- neue prefx und postfix methoden

parent 1dde23fc
......@@ -426,6 +426,22 @@ class Node: # (collections.abc.Sized): Base class omitted for cython-compatibil
self._xml_attr = OrderedDict()
return self._xml_attr
def get_attr(self, attribute: str, default: str) -> str:
"""
Returns the value of 'attribute' if attribute exists. If not, the
default value is returned. This function has the same semantics
as `node.attr.get(attribute, default)`, but with the advantage then
other than `node.attr.get` it does not automatically create an
attribute dictionary on (first) access.
:param attribute: The attribute, the value of which shall be looked up
:param default: A default value that is returned, in case attribute
does not exist.
:return: str
"""
if self.has_attr():
return self.attr.get(attribute, default)
return default
def compare_attr(self, other: 'Node') -> bool:
"""
Returns True, if `self` and `other` have the same attributes with the
......
......@@ -273,8 +273,8 @@ class TestRootNode:
str(result)
class TestNodeFind():
"""Test the select_if-functions of class Node.
class TestNodeFind:
"""Test the item-access-functions of class Node.
"""
def test_find(self):
......@@ -297,6 +297,7 @@ class TestNodeFind():
tree = parse_sxpr('(a (b X) (X (c d)) (e (X F)))')
assert tree[0].equals(parse_sxpr('(b X)'))
assert tree[2].equals(parse_sxpr('(e (X F))'))
assert tree[-1].equals(parse_sxpr('(e (X F))'))
try:
node = tree[3]
assert False, "IndexError expected!"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment