From: Stefan Behnel Date: Fri, 18 Sep 2009 06:25:16 +0000 (+0200) Subject: support attribute value selection in TreePath X-Git-Tag: 0.12.alpha0~191 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=42ea77b5898ea52a71b45e9d8c12c569bf6267a3;p=cython.git support attribute value selection in TreePath --- diff --git a/Cython/Compiler/Tests/TestTreePath.py b/Cython/Compiler/Tests/TestTreePath.py index 64815409..296aff6a 100644 --- a/Cython/Compiler/Tests/TestTreePath.py +++ b/Cython/Compiler/Tests/TestTreePath.py @@ -24,6 +24,11 @@ class TestTreePath(TransformTest): self.assertEquals(1, len(find_all(t, "//ReturnStatNode"))) self.assertEquals(1, len(find_all(t, "//DefNode//ReturnStatNode"))) + def test_node_path_attribute(self): + t = self._build_tree() + self.assertEquals(2, len(find_all(t, "//NameNode/@name"))) + self.assertEquals(['fun', 'decorator'], find_all(t, "//NameNode/@name")) + def test_node_path_child(self): t = self._build_tree() self.assertEquals(1, len(find_all(t, "//DefNode/ReturnStatNode/NameNode"))) diff --git a/Cython/Compiler/TreePath.py b/Cython/Compiler/TreePath.py index 74aaeba7..81c0a574 100644 --- a/Cython/Compiler/TreePath.py +++ b/Cython/Compiler/TreePath.py @@ -136,10 +136,14 @@ def handle_attribute(next, token): if token[0]: raise ValueError("Expected attribute name") name = token[1] - token = next() value = None - if token[0] == '=': - value = parse_path_value(next) + try: + token = next() + except StopIteration: + pass + else: + if token[0] == '=': + value = parse_path_value(next) if value is None: def select(result): for node in result: