Skip to content

Commit

Permalink
Add __parent__ and __children__ magic keys for validator and formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Oct 23, 2015
1 parent b7ed583 commit e52920b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions rebulk/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ def _match_parent(self, match, yield_parent):
:rtype:
"""
if yield_parent or self.format_all:
match.formatter = self.formatters.get(match.name, self._default_formatter)
match.formatter = self.formatters.get(match.name,
self.formatters.get('__parent__', self._default_formatter))
if yield_parent or self.validate_all:
validator = self.validators.get(match.name, self._default_validator)
validator = self.validators.get(match.name, self.validators.get('__parent__', self._default_validator))
if not validator(match):
return False
return True
Expand All @@ -128,9 +129,10 @@ def _match_child(self, child, yield_children):
:rtype:
"""
if yield_children or self.format_all:
child.formatter = self.formatters.get(child.name, self._default_formatter)
child.formatter = self.formatters.get(child.name,
self.formatters.get('__children__', self._default_formatter))
if yield_children or self.validate_all:
validator = self.validators.get(child.name, self._default_validator)
validator = self.validators.get(child.name, self.validators.get('__children__', self._default_validator))
if not validator(child):
return False
return True
Expand Down

0 comments on commit e52920b

Please sign in to comment.