Skip to content
Snippets Groups Projects
Verified Commit 056d15af authored by Timm Fitschen's avatar Timm Fitschen
Browse files

CLEANUP

parent e49316b4
Branches
No related tags found
No related merge requests found
...@@ -609,59 +609,48 @@ class Entity(object): ...@@ -609,59 +609,48 @@ class Entity(object):
Parameters Parameters
---------- ----------
properties : str or tuple of str *properties : str or tuple of str
A list of property names, e.g. `"height", "width"` or a list of A list of property names, e.g. `"height", "width"` or a list of
tuples of properties, e.g. `("window", "height"), ("window", tuples of properties, e.g. `("window", "height"), ("window",
"width")`. "width")`.
Raises
------
TypeError :
If the properties parameter contains anything else than str or
tuple of str elements.
Returns Returns
------- -------
row : tuple row : tuple
A row-like representation of the entities properties. A row-like representation of the entity's properties.
""" """
selectors = properties properties = properties
row = tuple() row = tuple()
for sel in selectors: for selector in properties:
val = None val = None
if isinstance(sel, str): if isinstance(selector, (tuple, list)) and len(selector) > 0:
if hasattr(self, sel.lower()):
val = getattr(self, sel.lower())
else:
prop = self.get_property(sel)
if prop is not None:
val = prop.value
elif isinstance(sel, (tuple, list)) and len(sel) > 0:
val = None val = None
ref = self ref = self
# the while loop walks through the re # the while loop walks through the re
while len(sel) > 1 and isinstance(ref, Entity): while len(selector) > 1 and isinstance(ref, Entity):
prop = ref.get_property(sel[0]) prop = ref.get_property(selector[0])
if prop is not None and isinstance(prop.value, Entity): if prop is not None and isinstance(prop.value, Entity):
ref = prop.value ref = prop.value
else: else:
# non-entity value - # non-entity value -
ref = prop ref = prop
sel = sel[1:] selector = selector[1:]
if len(sel) == 1 and isinstance(ref, Entity): if len(selector) == 1 and isinstance(ref, Entity):
if (hasattr(sel[0], "lower") if (hasattr(selector[0], "lower")
and hasattr(ref, sel[0].lower())): and hasattr(ref, selector[0].lower())):
val = getattr(ref, sel[0].lower()) val = getattr(ref, selector[0].lower())
else: else:
prop = ref.get_property(sel[0]) prop = ref.get_property(selector[0])
if prop is not None: if prop is not None:
val = prop.value val = prop.value
else: else:
raise TypeError("The elements of the parameter `properties` " if hasattr(self, selector.lower()):
"must contain str or non-empty tuples of str." val = getattr(self, selector.lower())
" Was {}.".format(sel)) else:
prop = self.get_property(selector)
if prop is not None:
val = prop.value
if isinstance(val, Entity): if isinstance(val, Entity):
val = val.id if val.id is not None else val.name val = val.id if val.id is not None else val.name
row += (val,) row += (val,)
...@@ -3202,16 +3191,10 @@ class Container(list): ...@@ -3202,16 +3191,10 @@ class Container(list):
Parameters Parameters
---------- ----------
properties : list *properties : str or tuple of str
A list of property names, e.g. `["height", "width"]` or a list of A list of property names, e.g. `"height", "width"` or a list of
tuples of properties, e.g. `[("window", "height"), ("window", tuples of properties, e.g. `("window", "height"), ("window",
"width")]`. "width")`.
Raises
------
TypeError :
If the properties parameter contains anything else than str or
tuple of str elements.
Returns Returns
------- -------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment