Commit 43173842 authored by Stefan Behnel's avatar Stefan Behnel

support dotted attributes in TreePath

parent f75b953a
...@@ -144,11 +144,14 @@ def handle_attribute(next, token): ...@@ -144,11 +144,14 @@ 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 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 = getattr(node, name) attr_value = 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:
...@@ -157,11 +160,13 @@ def handle_attribute(next, token): ...@@ -157,11 +160,13 @@ def handle_attribute(next, token):
def select(result): def select(result):
for node in result: for node in result:
try: try:
attr_value = getattr(node, name) attr_value = 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:
yield value yield attr_value
return select return select
def parse_path_value(next): def parse_path_value(next):
......
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