to access attributes of attributes. Integer parts in paths are
looked up as integers.
"""
- if attribute is None:
- attribute = []
- elif isinstance(attribute, string_types):
- attribute = [int(x) if x.isdigit() else x for x in attribute.split('.')]
- else:
- attribute = [attribute]
+ attribute = _prepare_attribute_parts(attribute)
def attrgetter(item):
for part in attribute:
Examples of attribute: "attr1,attr2", "attr1.inner1.0,attr2.inner2.0", etc.
"""
- def _prepare_attribute_parts(attr):
- if attr is None:
- return []
- elif isinstance(attribute, string_types):
- return [int(x) if x.isdigit() else x for x in attr.split('.')]
- else:
- return [attr]
-
attribute_parts = attribute.split(',') if isinstance(attribute, string_types) else [attribute]
attribute = [_prepare_attribute_parts(attribute_part) for attribute_part in attribute_parts]
return attrgetter
+def _prepare_attribute_parts(attr):
+ if attr is None:
+ return []
+ elif isinstance(attr, string_types):
+ return [int(x) if x.isdigit() else x for x in attr.split('.')]
+ else:
+ return [attr]
+
+
def do_forceescape(value):
"""Enforce HTML escaping. This will probably double escape variables."""
if hasattr(value, '__html__'):