diff options
author | Akira Yoshiyama <akirayoshiyama@gmail.com> | 2015-12-02 11:55:05 +0900 |
---|---|---|
committer | Akira Yoshiyama <akirayoshiyama@gmail.com> | 2015-12-13 21:39:15 +0900 |
commit | c9c5aab2c21b3df450ed38b6384b6868151f2d2f (patch) | |
tree | 598b3f9ad51e1a907ef5e0fbe3b73742a8891967 /oslo_policy/_parser.py | |
parent | c76b9af3fd46660612f8ceb711d3e1231de83878 (diff) | |
download | oslo-policy-c9c5aab2c21b3df450ed38b6384b6868151f2d2f.tar.gz |
Fixes combined "and" and "or" rule handling
The text parser handles rules like below:
- A or B or C [or D...]
- A and B and C [and D...]
But it doesn't ones below:
- A or B and C
- A and B or C
So, this patch fixes them with:
- for "A and B or C": adds @reducer('and_expr', 'or', 'check') to
_make_or_expr().
- for "A or B and C": adds _mix_or_and_expr() method. It pops the last
check (B) from OrCheck rule list [A, B] and append AndCheck with
rule list [B, C] to the Or Check rule list. So, finally we will get
"OrCheck[A, AndCheck[B, C]]".
Change-Id: Iaaee4864356411374ee7e7c5c0c05b98889e0f4e
Closes-Bug: #1523030
Diffstat (limited to 'oslo_policy/_parser.py')
-rw-r--r-- | oslo_policy/_parser.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/oslo_policy/_parser.py b/oslo_policy/_parser.py index 29be1b4..2225c2d 100644 --- a/oslo_policy/_parser.py +++ b/oslo_policy/_parser.py @@ -159,6 +159,18 @@ class ParseState(object): return [('and_expr', _checks.AndCheck([check1, check2]))] + @reducer('or_expr', 'and', 'check') + def _mix_or_and_expr(self, or_expr, _and, check): + """Modify the case 'A or B and C'""" + + or_expr, check1 = or_expr.pop_check() + if isinstance(check1, _checks.AndCheck): + and_expr = check1 + and_expr.add_check(check) + else: + and_expr = _checks.AndCheck([check1, check]) + return [('or_expr', or_expr.add_check(and_expr))] + @reducer('and_expr', 'and', 'check') def _extend_and_expr(self, and_expr, _and, check): """Extend an 'and_expr' by adding one more check.""" @@ -166,6 +178,7 @@ class ParseState(object): return [('and_expr', and_expr.add_check(check))] @reducer('check', 'or', 'check') + @reducer('and_expr', 'or', 'check') def _make_or_expr(self, check1, _or, check2): """Create an 'or_expr'. |