Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
6092931e
Commit
6092931e
authored
Dec 04, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test case for dotted attribute names, some cleanup
parent
20f13f93
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
7 deletions
+18
-7
Cython/Compiler/Tests/TestTreePath.py
Cython/Compiler/Tests/TestTreePath.py
+5
-0
Cython/Compiler/TreePath.py
Cython/Compiler/TreePath.py
+13
-7
No files found.
Cython/Compiler/Tests/TestTreePath.py
View file @
6092931e
...
@@ -36,6 +36,11 @@ class TestTreePath(TransformTest):
...
@@ -36,6 +36,11 @@ class TestTreePath(TransformTest):
self
.
assertEquals
(
2
,
len
(
find_all
(
t
,
"//NameNode/@name"
)))
self
.
assertEquals
(
2
,
len
(
find_all
(
t
,
"//NameNode/@name"
)))
self
.
assertEquals
([
'fun'
,
'decorator'
],
find_all
(
t
,
"//NameNode/@name"
))
self
.
assertEquals
([
'fun'
,
'decorator'
],
find_all
(
t
,
"//NameNode/@name"
))
def
test_node_path_attribute_dotted
(
self
):
t
=
self
.
_build_tree
()
self
.
assertEquals
(
1
,
len
(
find_all
(
t
,
"//ReturnStatNode/@value.name"
)))
self
.
assertEquals
([
'fun'
],
find_all
(
t
,
"//ReturnStatNode/@value.name"
))
def
test_node_path_child
(
self
):
def
test_node_path_child
(
self
):
t
=
self
.
_build_tree
()
t
=
self
.
_build_tree
()
self
.
assertEquals
(
1
,
len
(
find_all
(
t
,
"//DefNode/ReturnStatNode/NameNode"
)))
self
.
assertEquals
(
1
,
len
(
find_all
(
t
,
"//DefNode/ReturnStatNode/NameNode"
)))
...
...
Cython/Compiler/TreePath.py
View file @
6092931e
...
@@ -7,6 +7,7 @@ specific descendant or a node that holds an attribute.
...
@@ -7,6 +7,7 @@ specific descendant or a node that holds an attribute.
"""
"""
import
re
import
re
import
sys
path_tokenizer
=
re
.
compile
(
path_tokenizer
=
re
.
compile
(
"("
"("
...
@@ -144,14 +145,21 @@ def handle_attribute(next, token):
...
@@ -144,14 +145,21 @@ def handle_attribute(next, token):
else:
else:
if token[0] == '=':
if token[0] == '=':
value = parse_path_value(next)
value = parse_path_value(next)
name_path = name.split('.')
if sys.version_info >= (2,6) or (sys.version_info >= (2,4) and '.' not in name):
import operator
readattr = operator.attrgetter(name)
else:
name_path = name.split('.')
def readattr(node):
attr_value = node
for attr in name_path:
attr_value = getattr(attr_value, attr)
return attr_value
if value is None:
if value is None:
def select(result):
def select(result):
for node in result:
for node in result:
try:
try:
attr_value = node
attr_value = readattr(node)
for attr in name_path:
attr_value = getattr(attr_value, attr)
except AttributeError:
except AttributeError:
continue
continue
if attr_value is not None:
if attr_value is not None:
...
@@ -160,9 +168,7 @@ def handle_attribute(next, token):
...
@@ -160,9 +168,7 @@ def handle_attribute(next, token):
def select(result):
def select(result):
for node in result:
for node in result:
try:
try:
attr_value = node
attr_value = readattr(node)
for attr in name_path:
attr_value = getattr(attr_value, attr)
except AttributeError:
except AttributeError:
continue
continue
if attr_value == value:
if attr_value == value:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment