<s> """<STR_LIT>""" <EOL> from __future__ import division , absolute_import , print_function <EOL> from . import query <EOL> from beets . util import str2bool <EOL> class Type ( object ) : <EOL> """<STR_LIT>""" <EOL> sql = u'<STR_LIT>' <EOL> """<STR_LIT>""" <EOL> query = query . SubstringQuery <EOL> """<STR_LIT>""" <EOL> model_type = unicode <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def null ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . model_type ( ) <EOL> def format ( self , value ) : <EOL> """<STR_LIT>""" <EOL> if value is None : <EOL> value = self . null <EOL> if value is None : <EOL> value = u'<STR_LIT>' <EOL> if isinstance ( value , bytes ) : <EOL> value = value . decode ( '<STR_LIT:utf8>' , '<STR_LIT:ignore>' ) <EOL> return unicode ( value ) <EOL> def parse ( self , string ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . model_type ( string ) <EOL> except ValueError : <EOL> return self . null <EOL> def normalize ( self , value ) : <EOL> """<STR_LIT>""" <EOL> if value is None : <EOL> return self . null <EOL> else : <EOL> return value <EOL> def from_sql ( self , sql_value ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( sql_value , buffer ) : <EOL> sql_value = bytes ( sql_value ) . decode ( '<STR_LIT:utf8>' , '<STR_LIT:ignore>' ) <EOL> if isinstance ( sql_value , unicode ) : <EOL> return self . parse ( sql_value ) <EOL> else : <EOL> return self . normalize ( sql_value ) <EOL> def to_sql ( self , model_value ) : <EOL> """<STR_LIT>""" <EOL> return model_value <EOL> class Default ( Type ) : <EOL> null = None <EOL> class Integer ( Type ) : <EOL> """<STR_LIT>""" <EOL> sql = u'<STR_LIT>' <EOL> query = query . NumericQuery <EOL> model_type = int <EOL> class PaddedInt ( Integer ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , digits ) : <EOL> self . digits = digits <EOL> def format ( self , value ) : <EOL> return u'<STR_LIT>' . format ( value or <NUM_LIT:0> , self . digits ) <EOL> class ScaledInt ( Integer ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , unit , suffix = u'<STR_LIT>' ) : <EOL> self . unit = unit <EOL> self . suffix = suffix <EOL> def format ( self , value ) : <EOL> return u'<STR_LIT>' . format ( ( value or <NUM_LIT:0> ) // self . unit , self . suffix ) <EOL> class Id ( Integer ) : <EOL> """<STR_LIT>""" <EOL> null = None <EOL> def __init__ ( self , primary = True ) : <EOL> if primary : <EOL> self . sql = u'<STR_LIT>' <EOL> class Float ( Type ) : <EOL> """<STR_LIT>""" <EOL> sql = u'<STR_LIT>' <EOL> query = query . NumericQuery <EOL> model_type = float <EOL> def format ( self , value ) : <EOL> return u'<STR_LIT>' . format ( value or <NUM_LIT:0.0> ) <EOL> class NullFloat ( Float ) : <EOL> """<STR_LIT>""" <EOL> null = None <EOL> class String ( Type ) : <EOL> """<STR_LIT>""" <EOL> sql = u'<STR_LIT>' <EOL> query = query . SubstringQuery <EOL> class Boolean ( Type ) : <EOL> """<STR_LIT>""" <EOL> sql = u'<STR_LIT>' <EOL> query = query . BooleanQuery <EOL> model_type = bool <EOL> def format ( self , value ) : <EOL> return unicode ( bool ( value ) ) <EOL> def parse ( self , string ) : <EOL> return str2bool ( string ) <EOL> DEFAULT = Default ( ) <EOL> INTEGER = Integer ( ) <EOL> PRIMARY_ID = Id ( True ) <EOL> FOREIGN_ID = Id ( False ) <EOL> FLOAT = Float ( ) <EOL> NULL_FLOAT = NullFloat ( ) <EOL> STRING = String ( ) <EOL> BOOLEAN = Boolean ( ) </s>
