<s> class Operator ( object ) : <EOL> op = '<STR_LIT>' <EOL> allow_negation = False <EOL> def __init__ ( self , allow_negation = False ) : <EOL> self . allow_negation = allow_negation <EOL> def __call__ ( self ) : <EOL> return self <EOL> def prepare_queryset_kwargs ( self , field , value , negate ) : <EOL> if negate : <EOL> return { '<STR_LIT>' . join ( filter ( None , [ field , '<STR_LIT>' , self . op ] ) ) : value } <EOL> else : <EOL> return { '<STR_LIT>' . join ( filter ( None , [ field , self . op ] ) ) : value } <EOL> def apply ( self , queryset , field , value , negate = False ) : <EOL> kwargs = self . prepare_queryset_kwargs ( field , value , negate ) <EOL> return queryset . filter ( ** kwargs ) <EOL> class Ne ( Operator ) : <EOL> op = '<STR_LIT>' <EOL> class Lt ( Operator ) : <EOL> op = '<STR_LIT>' <EOL> class Lte ( Operator ) : <EOL> op = '<STR_LIT>' <EOL> class Gt ( Operator ) : <EOL> op = '<STR_LIT>' <EOL> class Gte ( Operator ) : <EOL> op = '<STR_LIT>' <EOL> class Exact ( Operator ) : <EOL> op = '<STR_LIT>' <EOL> def prepare_queryset_kwargs ( self , field , value , negate ) : <EOL> if negate : <EOL> return { '<STR_LIT>' % field : value } <EOL> else : <EOL> return { field : value } <EOL> class IExact ( Operator ) : <EOL> op = '<STR_LIT>' <EOL> class In ( Operator ) : <EOL> op = '<STR_LIT>' <EOL> def prepare_queryset_kwargs ( self , field , value , negate ) : <EOL> if '<STR_LIT:U+002C>' in value : <EOL> value = value . split ( '<STR_LIT:U+002C>' ) <EOL> op = negate and '<STR_LIT>' or self . op <EOL> else : <EOL> op = negate and '<STR_LIT>' or '<STR_LIT>' <EOL> return { '<STR_LIT>' . join ( filter ( None , [ field , op ] ) ) : value } <EOL> class Contains ( Operator ) : <EOL> op = '<STR_LIT>' <EOL> class IContains ( Operator ) : <EOL> op = '<STR_LIT>' <EOL> class Startswith ( Operator ) : <EOL> op = '<STR_LIT>' <EOL> class IStartswith ( Operator ) : <EOL> op = '<STR_LIT>' <EOL> class Endswith ( Operator ) : <EOL> op = '<STR_LIT>' <EOL> class IEndswith ( Operator ) : <EOL> op = '<STR_LIT>' <EOL> class Boolean ( Operator ) : <EOL> op = '<STR_LIT>' <EOL> def prepare_queryset_kwargs ( self , field , value , negate ) : <EOL> if value == '<STR_LIT:false>' : <EOL> bool_value = False <EOL> else : <EOL> bool_value = True <EOL> if negate : <EOL> bool_value = not bool_value <EOL> return { field : bool_value } </s>
