diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-12-18 19:32:03 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-12-18 19:32:03 +0000 |
commit | b5908484b1f66a4164dc62c2a9c7b81887ea37cf (patch) | |
tree | 2a186328f6f9608131aee4668a24f0199de32145 /lib/sqlalchemy/sql/operators.py | |
parent | fee8fe33912b6cada7f536805aac8aac8d5b798e (diff) | |
download | sqlalchemy-b5908484b1f66a4164dc62c2a9c7b81887ea37cf.tar.gz |
a little pre-lunch decrufting and cleanup
Diffstat (limited to 'lib/sqlalchemy/sql/operators.py')
-rw-r--r-- | lib/sqlalchemy/sql/operators.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py index 4ee5f4a18..19e0c484c 100644 --- a/lib/sqlalchemy/sql/operators.py +++ b/lib/sqlalchemy/sql/operators.py @@ -6,6 +6,8 @@ from operator import and_, or_, inv, add, mul, sub, div, mod, truediv, \ lt, le, ne, gt, ge, eq +from sqlalchemy.util import Set + def from_(): raise NotImplementedError() @@ -68,3 +70,47 @@ def desc_op(a): def asc_op(a): return a.asc() + +_commutative = Set([eq, ne, add, mul]) +def is_commutative(op): + return op in _commutative + +_smallest = object() +_largest = object() + +_PRECEDENCE = { + from_:15, + mul:7, + div:7, + mod:7, + add:6, + sub:6, + concat_op:6, + ilike_op:5, + notilike_op:5, + like_op:5, + notlike_op:5, + in_op:5, + notin_op:5, + is_:5, + isnot:5, + eq:5, + ne:5, + gt:5, + lt:5, + ge:5, + le:5, + between_op:5, + distinct_op:5, + inv:5, + and_:3, + or_:2, + comma_op:-1, + as_:-1, + exists:0, + _smallest: -1000, + _largest: 1000 +} + +def is_precedent(operator, against): + return _PRECEDENCE.get(operator, _PRECEDENCE[_smallest]) <= _PRECEDENCE.get(against, _PRECEDENCE[_largest]) |