<s> from __future__ import unicode_literals <EOL> from django . db . models import F <EOL> from django_mysql . compat import BaseExpression , Value <EOL> from django_mysql . utils import collapse_spaces <EOL> class TwoSidedExpression ( BaseExpression ) : <EOL> def __init__ ( self , lhs , rhs ) : <EOL> super ( TwoSidedExpression , self ) . __init__ ( ) <EOL> self . lhs = lhs <EOL> self . rhs = rhs <EOL> def get_source_expressions ( self ) : <EOL> return [ self . lhs , self . rhs ] <EOL> def set_source_expressions ( self , exprs ) : <EOL> self . lhs , self . rhs = exprs <EOL> class ListF ( object ) : <EOL> def __init__ ( self , field_name ) : <EOL> self . field_name = field_name <EOL> self . field = F ( field_name ) <EOL> def append ( self , value ) : <EOL> if not hasattr ( value , '<STR_LIT>' ) : <EOL> value = Value ( value ) <EOL> return AppendListF ( self . field , value ) <EOL> def appendleft ( self , value ) : <EOL> if not hasattr ( value , '<STR_LIT>' ) : <EOL> value = Value ( value ) <EOL> return AppendLeftListF ( self . field , value ) <EOL> def pop ( self ) : <EOL> return PopListF ( self . field ) <EOL> def popleft ( self ) : <EOL> return PopLeftListF ( self . field ) <EOL> class AppendListF ( TwoSidedExpression ) : <EOL> sql_expression = collapse_spaces ( """<STR_LIT>""" ) <EOL> def as_sql ( self , compiler , connection ) : <EOL> field , field_params = compiler . compile ( self . lhs ) <EOL> value , value_params = compiler . compile ( self . rhs ) <EOL> sql = self . sql_expression % ( field , value ) <EOL> params = [ ] <EOL> params . extend ( value_params ) <EOL> params . extend ( field_params ) <EOL> return sql , params <EOL> class AppendLeftListF ( TwoSidedExpression ) : <EOL> sql_expression = collapse_spaces ( """<STR_LIT>""" ) <EOL> def as_sql ( self , compiler , connection ) : <EOL> field , field_params = compiler . compile ( self . lhs ) <EOL> value , value_params = compiler . compile ( self . rhs ) <EOL> sql = self . sql_expression % ( value , field ) <EOL> params = [ ] <EOL> params . extend ( field_params ) <EOL> params . extend ( value_params ) <EOL> return sql , params <EOL> class PopListF ( BaseExpression ) : <EOL> sql_expression = collapse_spaces ( """<STR_LIT>""" ) <EOL> def __init__ ( self , lhs ) : <EOL> super ( BaseExpression , self ) . __init__ ( ) <EOL> self . lhs = lhs <EOL> def get_source_expressions ( self ) : <EOL> return [ self . lhs ] <EOL> def set_source_expressions ( self , exprs ) : <EOL> self . lhs = exprs [ <NUM_LIT:0> ] <EOL> def as_sql ( self , compiler , connection ) : <EOL> field , field_params = compiler . compile ( self . lhs ) <EOL> sql = self . sql_expression % ( field ) <EOL> return sql , field_params <EOL> class PopLeftListF ( BaseExpression ) : <EOL> sql_expression = collapse_spaces ( """<STR_LIT>""" ) <EOL> def __init__ ( self , lhs ) : <EOL> super ( BaseExpression , self ) . __init__ ( ) <EOL> self . lhs = lhs <EOL> def get_source_expressions ( self ) : <EOL> return [ self . lhs ] <EOL> def set_source_expressions ( self , exprs ) : <EOL> self . lhs = exprs [ <NUM_LIT:0> ] <EOL> def as_sql ( self , compiler , connection ) : <EOL> field , field_params = compiler . compile ( self . lhs ) <EOL> sql = self . sql_expression % ( field ) <EOL> return sql , field_params <EOL> class SetF ( object ) : <EOL> def __init__ ( self , field_name ) : <EOL> self . field = F ( field_name ) <EOL> def add ( self , value ) : <EOL> if not hasattr ( value , '<STR_LIT>' ) : <EOL> value = Value ( value ) <EOL> return AddSetF ( self . field , value ) <EOL> def remove ( self , value ) : <EOL> if not hasattr ( value , '<STR_LIT>' ) : <EOL> value = Value ( value ) <EOL> return RemoveSetF ( self . field , value ) <EOL> class AddSetF ( TwoSidedExpression ) : <EOL> sql_expression = collapse_spaces ( """<STR_LIT>""" ) <EOL> def as_sql ( self , compiler , connection ) : <EOL> field , field_params = compiler . compile ( self . lhs ) <EOL> value , value_params = compiler . compile ( self . rhs ) <EOL> sql = self . sql_expression % ( value , field ) <EOL> params = [ ] <EOL> params . extend ( value_params ) <EOL> params . extend ( field_params ) <EOL> return sql , params <EOL> class RemoveSetF ( TwoSidedExpression ) : <EOL> sql_expression = collapse_spaces ( """<STR_LIT>""" ) <EOL> def as_sql ( self , compiler , connection ) : <EOL> field , field_params = compiler . compile ( self . lhs ) <EOL> value , value_params = compiler . compile ( self . rhs ) <EOL> sql = self . sql_expression % ( value , field ) <EOL> params = [ ] <EOL> params . extend ( value_params ) <EOL> params . extend ( field_params ) <EOL> return sql , params </s>
