<s> """<STR_LIT>""" <EOL> from . . import util <EOL> from operator import ( <EOL> and_ , or_ , inv , add , mul , sub , mod , truediv , lt , le , ne , gt , ge , eq , neg , <EOL> getitem , lshift , rshift <EOL> ) <EOL> if util . py2k : <EOL> from operator import div <EOL> else : <EOL> div = truediv <EOL> class Operators ( object ) : <EOL> """<STR_LIT>""" <EOL> def __and__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( and_ , other ) <EOL> def __or__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( or_ , other ) <EOL> def __invert__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( inv ) <EOL> def op ( self , opstring , precedence = <NUM_LIT:0> , is_comparison = False ) : <EOL> """<STR_LIT>""" <EOL> operator = custom_op ( opstring , precedence , is_comparison ) <EOL> def against ( other ) : <EOL> return operator ( self , other ) <EOL> return against <EOL> def operate ( self , op , * other , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( str ( op ) ) <EOL> def reverse_operate ( self , op , other , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( str ( op ) ) <EOL> class custom_op ( object ) : <EOL> """<STR_LIT>""" <EOL> __name__ = '<STR_LIT>' <EOL> def __init__ ( self , opstring , precedence = <NUM_LIT:0> , is_comparison = False ) : <EOL> self . opstring = opstring <EOL> self . precedence = precedence <EOL> self . is_comparison = is_comparison <EOL> def __eq__ ( self , other ) : <EOL> return isinstance ( other , custom_op ) and other . opstring == self . opstring <EOL> def __hash__ ( self ) : <EOL> return id ( self ) <EOL> def __call__ ( self , left , right , ** kw ) : <EOL> return left . operate ( self , right , ** kw ) <EOL> class ColumnOperators ( Operators ) : <EOL> """<STR_LIT>""" <EOL> timetuple = None <EOL> """<STR_LIT>""" <EOL> def __lt__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( lt , other ) <EOL> def __le__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( le , other ) <EOL> __hash__ = Operators . __hash__ <EOL> def __eq__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( eq , other ) <EOL> def __ne__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( ne , other ) <EOL> def __gt__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( gt , other ) <EOL> def __ge__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( ge , other ) <EOL> def __neg__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( neg ) <EOL> def __getitem__ ( self , index ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( getitem , index ) <EOL> def __lshift__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( lshift , other ) <EOL> def __rshift__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( rshift , other ) <EOL> def concat ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( concat_op , other ) <EOL> def like ( self , other , escape = None ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( like_op , other , escape = escape ) <EOL> def ilike ( self , other , escape = None ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( ilike_op , other , escape = escape ) <EOL> def in_ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( in_op , other ) <EOL> def notin_ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( notin_op , other ) <EOL> def notlike ( self , other , escape = None ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( notlike_op , other , escape = escape ) <EOL> def notilike ( self , other , escape = None ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( notilike_op , other , escape = escape ) <EOL> def is_ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( is_ , other ) <EOL> def isnot ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( isnot , other ) <EOL> def startswith ( self , other , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( startswith_op , other , ** kwargs ) <EOL> def endswith ( self , other , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( endswith_op , other , ** kwargs ) <EOL> def contains ( self , other , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( contains_op , other , ** kwargs ) <EOL> def match ( self , other , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( match_op , other , ** kwargs ) <EOL> def desc ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( desc_op ) <EOL> def asc ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( asc_op ) <EOL> def nullsfirst ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( nullsfirst_op ) <EOL> def nullslast ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( nullslast_op ) <EOL> def collate ( self , collation ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( collate , collation ) <EOL> def __radd__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . reverse_operate ( add , other ) <EOL> def __rsub__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . reverse_operate ( sub , other ) <EOL> def __rmul__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . reverse_operate ( mul , other ) <EOL> def __rdiv__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . reverse_operate ( div , other ) <EOL> def between ( self , cleft , cright , symmetric = False ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( between_op , cleft , cright , symmetric = symmetric ) <EOL> def distinct ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( distinct_op ) <EOL> def __add__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( add , other ) <EOL> def __sub__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( sub , other ) <EOL> def __mul__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( mul , other ) <EOL> def __div__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( div , other ) <EOL> def __mod__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( mod , other ) <EOL> def __truediv__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( truediv , other ) <EOL> def __rtruediv__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . reverse_operate ( truediv , other ) <EOL> def from_ ( ) : <EOL> raise NotImplementedError ( ) <EOL> def as_ ( ) : <EOL> raise NotImplementedError ( ) <EOL> def exists ( ) : <EOL> raise NotImplementedError ( ) <EOL> def istrue ( a ) : <EOL> raise NotImplementedError ( ) <EOL> def isfalse ( a ) : <EOL> raise NotImplementedError ( ) <EOL> def is_ ( a , b ) : <EOL> return a . is_ ( b ) <EOL> def isnot ( a , b ) : <EOL> return a . isnot ( b ) <EOL> def collate ( a , b ) : <EOL> return a . collate ( b ) <EOL> def op ( a , opstring , b ) : <EOL> return a . op ( opstring ) ( b ) <EOL> def like_op ( a , b , escape = None ) : <EOL> return a . like ( b , escape = escape ) <EOL> def notlike_op ( a , b , escape = None ) : <EOL> return a . notlike ( b , escape = escape ) <EOL> def ilike_op ( a , b , escape = None ) : <EOL> return a . ilike ( b , escape = escape ) <EOL> def notilike_op ( a , b , escape = None ) : <EOL> return a . notilike ( b , escape = escape ) <EOL> def between_op ( a , b , c , symmetric = False ) : <EOL> return a . between ( b , c , symmetric = symmetric ) <EOL> def notbetween_op ( a , b , c , symmetric = False ) : <EOL> return a . notbetween ( b , c , symmetric = symmetric ) <EOL> def in_op ( a , b ) : <EOL> return a . in_ ( b ) <EOL> def notin_op ( a , b ) : <EOL> return a . notin_ ( b ) <EOL> def distinct_op ( a ) : <EOL> return a . distinct ( ) <EOL> def startswith_op ( a , b , escape = None ) : <EOL> return a . startswith ( b , escape = escape ) <EOL> def notstartswith_op ( a , b , escape = None ) : <EOL> return ~ a . startswith ( b , escape = escape ) <EOL> def endswith_op ( a , b , escape = None ) : <EOL> return a . endswith ( b , escape = escape ) <EOL> def notendswith_op ( a , b , escape = None ) : <EOL> return ~ a . endswith ( b , escape = escape ) <EOL> def contains_op ( a , b , escape = None ) : <EOL> return a . contains ( b , escape = escape ) <EOL> def notcontains_op ( a , b , escape = None ) : <EOL> return ~ a . contains ( b , escape = escape ) <EOL> def match_op ( a , b , ** kw ) : <EOL> return a . match ( b , ** kw ) <EOL> def comma_op ( a , b ) : <EOL> raise NotImplementedError ( ) <EOL> def concat_op ( a , b ) : <EOL> return a . concat ( b ) <EOL> def desc_op ( a ) : <EOL> return a . desc ( ) <EOL> def asc_op ( a ) : <EOL> return a . asc ( ) <EOL> def nullsfirst_op ( a ) : <EOL> return a . nullsfirst ( ) <EOL> def nullslast_op ( a ) : <EOL> return a . nullslast ( ) <EOL> _commutative = set ( [ eq , ne , add , mul ] ) <EOL> _comparison = set ( [ eq , ne , lt , gt , ge , le , between_op , like_op ] ) <EOL> def is_comparison ( op ) : <EOL> return op in _comparison or isinstance ( op , custom_op ) and op . is_comparison <EOL> def is_commutative ( op ) : <EOL> return op in _commutative <EOL> def is_ordering_modifier ( op ) : <EOL> return op in ( asc_op , desc_op , <EOL> nullsfirst_op , nullslast_op ) <EOL> _associative = _commutative . union ( [ concat_op , and_ , or_ ] ) <EOL> _natural_self_precedent = _associative . union ( [ getitem ] ) <EOL> """<STR_LIT>""" <EOL> _asbool = util . symbol ( '<STR_LIT>' , canonical = - <NUM_LIT:10> ) <EOL> _smallest = util . symbol ( '<STR_LIT>' , canonical = - <NUM_LIT:100> ) <EOL> _largest = util . symbol ( '<STR_LIT>' , canonical = <NUM_LIT:100> ) <EOL> _PRECEDENCE = { <EOL> from_ : <NUM_LIT:15> , <EOL> getitem : <NUM_LIT:15> , <EOL> mul : <NUM_LIT:8> , <EOL> truediv : <NUM_LIT:8> , <EOL> div : <NUM_LIT:8> , <EOL> mod : <NUM_LIT:8> , <EOL> neg : <NUM_LIT:8> , <EOL> add : <NUM_LIT:7> , <EOL> sub : <NUM_LIT:7> , <EOL> concat_op : <NUM_LIT:6> , <EOL> match_op : <NUM_LIT:6> , <EOL> ilike_op : <NUM_LIT:6> , <EOL> notilike_op : <NUM_LIT:6> , <EOL> like_op : <NUM_LIT:6> , <EOL> notlike_op : <NUM_LIT:6> , <EOL> in_op : <NUM_LIT:6> , <EOL> notin_op : <NUM_LIT:6> , <EOL> is_ : <NUM_LIT:6> , <EOL> isnot : <NUM_LIT:6> , <EOL> eq : <NUM_LIT:5> , <EOL> ne : <NUM_LIT:5> , <EOL> gt : <NUM_LIT:5> , <EOL> lt : <NUM_LIT:5> , <EOL> ge : <NUM_LIT:5> , <EOL> le : <NUM_LIT:5> , <EOL> between_op : <NUM_LIT:5> , <EOL> notbetween_op : <NUM_LIT:5> , <EOL> distinct_op : <NUM_LIT:5> , <EOL> inv : <NUM_LIT:5> , <EOL> istrue : <NUM_LIT:5> , <EOL> isfalse : <NUM_LIT:5> , <EOL> and_ : <NUM_LIT:3> , <EOL> or_ : <NUM_LIT:2> , <EOL> comma_op : - <NUM_LIT:1> , <EOL> desc_op : <NUM_LIT:3> , <EOL> asc_op : <NUM_LIT:3> , <EOL> collate : <NUM_LIT:4> , <EOL> as_ : - <NUM_LIT:1> , <EOL> exists : <NUM_LIT:0> , <EOL> _asbool : - <NUM_LIT:10> , <EOL> _smallest : _smallest , <EOL> _largest : _largest <EOL> } <EOL> def is_precedent ( operator , against ) : <EOL> if operator is against and operator in _natural_self_precedent : <EOL> return False <EOL> else : <EOL> return ( _PRECEDENCE . get ( operator , <EOL> getattr ( operator , '<STR_LIT>' , _smallest ) ) <= <EOL> _PRECEDENCE . get ( against , <EOL> getattr ( against , '<STR_LIT>' , _largest ) ) ) </s>
