Skip to content
Myr

Refactor _prepare_attribute_parts() to use in both make_attrgetter() and make_multi_attrgetter()

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by mayur-srivastava · committed by mayur-srivastava · parent 8a39eca · Browse files · 1 file+10 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+10 added−14 removed

  • other:+10 added−14 removed

1 file+10 added−14 removed

modified:jinja2/filters.py+10 added-14 removed
63 unmodified lines
64 passed object with the rules of the environment. Dots are allowed65 to access attributes of attributes. Integer parts in paths are66 looked up as integers.67 """68 if attribute is None:69 attribute = []70 elif isinstance(attribute, string_types):71 attribute = [int(x) if x.isdigit() else x for x in attribute.split('.')]72 else:73 attribute = [attribute]68 attribute = _prepare_attribute_parts(attribute)6970 def attrgetter(item):71 for part in attribute:72 item = environment.getitem(item, part)
16 unmodified lines
89 attribute values.9091 Examples of attribute: "attr1,attr2", "attr1.inner1.0,attr2.inner2.0", etc.92 """98 def _prepare_attribute_parts(attr):99 if attr is None:100 return []101 elif isinstance(attribute, string_types):102 return [int(x) if x.isdigit() else x for x in attr.split('.')]103 else:104 return [attr]10593 attribute_parts = attribute.split(',') if isinstance(attribute, string_types) else [attribute]94 attribute = [_prepare_attribute_parts(attribute_part) for attribute_part in attribute_parts]9596 def attrgetter(item):
11 unmodified lines
108109 return attrgetter110111112def _prepare_attribute_parts(attr):113 if attr is None:114 return []115 elif isinstance(attr, string_types):116 return [int(x) if x.isdigit() else x for x in attr.split('.')]117 else:118 return [attr]119120121def do_forceescape(value):122 """Enforce HTML escaping. This will probably double escape variables."""123 if hasattr(value, '__html__'):124 value = value.__html__()
1122 unmodified lines