<s> import datetime <EOL> from django . utils import tree <EOL> class ExpressionNode ( tree . Node ) : <EOL> """<STR_LIT>""" <EOL> ADD = '<STR_LIT:+>' <EOL> SUB = '<STR_LIT:->' <EOL> MUL = '<STR_LIT:*>' <EOL> DIV = '<STR_LIT:/>' <EOL> MOD = '<STR_LIT>' <EOL> BITAND = '<STR_LIT:&>' <EOL> BITOR = '<STR_LIT:|>' <EOL> def __init__ ( self , children = None , connector = None , negated = False ) : <EOL> if children is not None and len ( children ) > <NUM_LIT:1> and connector is None : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> super ( ExpressionNode , self ) . __init__ ( children , connector , negated ) <EOL> def _combine ( self , other , connector , reversed , node = None ) : <EOL> if isinstance ( other , datetime . timedelta ) : <EOL> return DateModifierNode ( [ self , other ] , connector ) <EOL> if reversed : <EOL> obj = ExpressionNode ( [ other ] , connector ) <EOL> obj . add ( node or self , connector ) <EOL> else : <EOL> obj = node or ExpressionNode ( [ self ] , connector ) <EOL> obj . add ( other , connector ) <EOL> return obj <EOL> def prepare ( self , evaluator , query , allow_joins ) : <EOL> return evaluator . prepare_node ( self , query , allow_joins ) <EOL> def evaluate ( self , evaluator , qn , connection ) : <EOL> return evaluator . evaluate_node ( self , qn , connection ) <EOL> def __add__ ( self , other ) : <EOL> return self . _combine ( other , self . ADD , False ) <EOL> def __sub__ ( self , other ) : <EOL> return self . _combine ( other , self . SUB , False ) <EOL> def __mul__ ( self , other ) : <EOL> return self . _combine ( other , self . MUL , False ) <EOL> def __truediv__ ( self , other ) : <EOL> return self . _combine ( other , self . DIV , False ) <EOL> def __div__ ( self , other ) : <EOL> return type ( self ) . __truediv__ ( self , other ) <EOL> def __mod__ ( self , other ) : <EOL> return self . _combine ( other , self . MOD , False ) <EOL> def __and__ ( self , other ) : <EOL> raise NotImplementedError ( <EOL> "<STR_LIT>" <EOL> ) <EOL> def bitand ( self , other ) : <EOL> return self . _combine ( other , self . BITAND , False ) <EOL> def __or__ ( self , other ) : <EOL> raise NotImplementedError ( <EOL> "<STR_LIT>" <EOL> ) <EOL> def bitor ( self , other ) : <EOL> return self . _combine ( other , self . BITOR , False ) <EOL> def __radd__ ( self , other ) : <EOL> return self . _combine ( other , self . ADD , True ) <EOL> def __rsub__ ( self , other ) : <EOL> return self . _combine ( other , self . SUB , True ) <EOL> def __rmul__ ( self , other ) : <EOL> return self . _combine ( other , self . MUL , True ) <EOL> def __rtruediv__ ( self , other ) : <EOL> return self . _combine ( other , self . DIV , True ) <EOL> def __rdiv__ ( self , other ) : <EOL> return type ( self ) . __rtruediv__ ( self , other ) <EOL> def __rmod__ ( self , other ) : <EOL> return self . _combine ( other , self . MOD , True ) <EOL> def __rand__ ( self , other ) : <EOL> raise NotImplementedError ( <EOL> "<STR_LIT>" <EOL> ) <EOL> def __ror__ ( self , other ) : <EOL> raise NotImplementedError ( <EOL> "<STR_LIT>" <EOL> ) <EOL> def prepare_database_save ( self , unused ) : <EOL> return self <EOL> class F ( ExpressionNode ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name ) : <EOL> super ( F , self ) . __init__ ( None , None , False ) <EOL> self . name = name <EOL> def __deepcopy__ ( self , memodict ) : <EOL> obj = super ( F , self ) . __deepcopy__ ( memodict ) <EOL> obj . name = self . name <EOL> return obj <EOL> def prepare ( self , evaluator , query , allow_joins ) : <EOL> return evaluator . prepare_leaf ( self , query , allow_joins ) <EOL> def evaluate ( self , evaluator , qn , connection ) : <EOL> return evaluator . evaluate_leaf ( self , qn , connection ) <EOL> class DateModifierNode ( ExpressionNode ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , children , connector , negated = False ) : <EOL> if len ( children ) != <NUM_LIT:2> : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> if not isinstance ( children [ <NUM_LIT:1> ] , datetime . timedelta ) : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> if connector not in ( self . ADD , self . SUB ) : <EOL> raise TypeError ( '<STR_LIT>' % connector ) <EOL> super ( DateModifierNode , self ) . __init__ ( children , connector , negated ) <EOL> def evaluate ( self , evaluator , qn , connection ) : <EOL> return evaluator . evaluate_date_modifier_node ( self , qn , connection ) </s>
