<s> """<STR_LIT>""" <EOL> import util <EOL> class ResultList ( list ) : <EOL> def __init__ ( self , li , start = <NUM_LIT:0> , total = <NUM_LIT:0> ) : <EOL> self . extend ( li ) <EOL> self . start = start <EOL> if total == <NUM_LIT:0> : <EOL> total = len ( li ) <EOL> self . total = total <EOL> class GenericProxy ( object ) : <EOL> def __init__ ( self ) : <EOL> self . cache = { } <EOL> def get_attribute ( self , method_name , ** kwargs ) : <EOL> result = util . callm ( "<STR_LIT>" % ( self . _object_type , method_name ) , kwargs ) <EOL> return result [ '<STR_LIT>' ] <EOL> def post_attribute ( self , method_name , ** kwargs ) : <EOL> data = kwargs . pop ( '<STR_LIT:data>' ) if '<STR_LIT:data>' in kwargs else { } <EOL> result = util . callm ( "<STR_LIT>" % ( self . _object_type , method_name ) , kwargs , POST = True , data = data ) <EOL> return result [ '<STR_LIT>' ] <EOL> class ArtistProxy ( GenericProxy ) : <EOL> def __init__ ( self , identifier , buckets = None , ** kwargs ) : <EOL> super ( ArtistProxy , self ) . __init__ ( ) <EOL> buckets = buckets or [ ] <EOL> self . id = identifier <EOL> self . _object_type = '<STR_LIT>' <EOL> kwargs = dict ( ( str ( k ) , v ) for ( k , v ) in kwargs . iteritems ( ) ) <EOL> core_attrs = [ '<STR_LIT:name>' ] <EOL> if not all ( ca in kwargs for ca in core_attrs ) : <EOL> profile = self . get_attribute ( '<STR_LIT>' , ** { '<STR_LIT>' : buckets } ) <EOL> kwargs . update ( profile . get ( '<STR_LIT>' ) ) <EOL> [ self . __dict__ . update ( { ca : kwargs . pop ( ca ) } ) for ca in core_attrs + [ '<STR_LIT:id>' ] if ca in kwargs ] <EOL> self . cache . update ( kwargs ) <EOL> def get_attribute ( self , * args , ** kwargs ) : <EOL> if util . short_regex . match ( self . id ) or util . long_regex . match ( self . id ) or util . foreign_regex . match ( self . id ) : <EOL> kwargs [ '<STR_LIT:id>' ] = self . id <EOL> else : <EOL> kwargs [ '<STR_LIT:name>' ] = self . id <EOL> return super ( ArtistProxy , self ) . get_attribute ( * args , ** kwargs ) <EOL> class CatalogProxy ( GenericProxy ) : <EOL> def __init__ ( self , identifier , type , buckets = None , ** kwargs ) : <EOL> super ( CatalogProxy , self ) . __init__ ( ) <EOL> buckets = buckets or [ ] <EOL> self . id = identifier <EOL> self . _object_type = '<STR_LIT>' <EOL> kwargs = dict ( ( str ( k ) , v ) for ( k , v ) in kwargs . iteritems ( ) ) <EOL> core_attrs = [ '<STR_LIT:name>' ] <EOL> if not all ( ca in kwargs for ca in core_attrs ) : <EOL> if util . short_regex . match ( self . id ) or util . long_regex . match ( self . id ) or util . foreign_regex . match ( self . id ) : <EOL> profile = self . get_attribute ( '<STR_LIT>' ) <EOL> kwargs . update ( profile [ '<STR_LIT>' ] ) <EOL> else : <EOL> if not type : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> try : <EOL> profile = self . get_attribute ( '<STR_LIT>' ) <EOL> existing_type = profile [ '<STR_LIT>' ] . get ( '<STR_LIT:type>' , '<STR_LIT>' ) <EOL> if type != existing_type : <EOL> raise Exception ( "<STR_LIT>" % ( type , existing_type ) ) <EOL> kwargs . update ( profile [ '<STR_LIT>' ] ) <EOL> except util . EchoNestAPIError : <EOL> profile = self . post_attribute ( '<STR_LIT>' , type = type , ** kwargs ) <EOL> kwargs . update ( profile ) <EOL> [ self . __dict__ . update ( { ca : kwargs . pop ( ca ) } ) for ca in core_attrs + [ '<STR_LIT:id>' ] if ca in kwargs ] <EOL> self . cache . update ( kwargs ) <EOL> def get_attribute_simple ( self , * args , ** kwargs ) : <EOL> return super ( CatalogProxy , self ) . get_attribute ( * args , ** kwargs ) <EOL> def get_attribute ( self , * args , ** kwargs ) : <EOL> if util . short_regex . match ( self . id ) or util . long_regex . match ( self . id ) or util . foreign_regex . match ( self . id ) : <EOL> kwargs [ '<STR_LIT:id>' ] = self . id <EOL> else : <EOL> kwargs [ '<STR_LIT:name>' ] = self . id <EOL> return super ( CatalogProxy , self ) . get_attribute ( * args , ** kwargs ) <EOL> def post_attribute ( self , * args , ** kwargs ) : <EOL> if util . short_regex . match ( self . id ) or util . long_regex . match ( self . id ) or util . foreign_regex . match ( self . id ) : <EOL> kwargs [ '<STR_LIT:id>' ] = self . id <EOL> else : <EOL> kwargs [ '<STR_LIT:name>' ] = self . id <EOL> return super ( CatalogProxy , self ) . post_attribute ( * args , ** kwargs ) <EOL> class PlaylistProxy ( GenericProxy ) : <EOL> def __init__ ( self , session_id = None , buckets = None , ** kwargs ) : <EOL> super ( PlaylistProxy , self ) . __init__ ( ) <EOL> core_attrs = [ '<STR_LIT>' ] <EOL> self . _object_type = '<STR_LIT>' <EOL> if session_id : <EOL> self . session_id = session_id <EOL> else : <EOL> buckets = buckets or [ ] <EOL> kwargs [ '<STR_LIT>' ] = buckets <EOL> kwargs [ '<STR_LIT>' ] = kwargs [ '<STR_LIT>' ] <EOL> del kwargs [ '<STR_LIT>' ] <EOL> kwargs = dict ( ( str ( k ) , v ) for ( k , v ) in kwargs . iteritems ( ) ) <EOL> if not all ( ca in kwargs for ca in core_attrs ) : <EOL> kwargs = dict ( ( str ( k ) , v ) for ( k , v ) in kwargs . iteritems ( ) ) <EOL> profile = self . get_attribute ( '<STR_LIT>' , ** kwargs ) <EOL> kwargs . update ( profile ) <EOL> [ self . __dict__ . update ( { ca : kwargs . pop ( ca ) } ) for ca in core_attrs if ca in kwargs ] <EOL> self . cache . update ( kwargs ) <EOL> def get_attribute ( self , method , ** kwargs ) : <EOL> return super ( PlaylistProxy , self ) . get_attribute ( '<STR_LIT>' + method , ** kwargs ) <EOL> class SongProxy ( GenericProxy ) : <EOL> def __init__ ( self , identifier , buckets = None , ** kwargs ) : <EOL> super ( SongProxy , self ) . __init__ ( ) <EOL> buckets = buckets or [ ] <EOL> self . id = identifier <EOL> self . _object_type = '<STR_LIT>' <EOL> kwargs = dict ( ( str ( k ) , v ) for ( k , v ) in kwargs . iteritems ( ) ) <EOL> if kwargs . has_key ( "<STR_LIT>" ) : <EOL> self . track_id = kwargs [ "<STR_LIT>" ] <EOL> if kwargs . has_key ( "<STR_LIT>" ) : <EOL> self . tag = kwargs [ "<STR_LIT>" ] <EOL> if kwargs . has_key ( "<STR_LIT>" ) : <EOL> self . score = kwargs [ "<STR_LIT>" ] <EOL> if kwargs . has_key ( '<STR_LIT>' ) : <EOL> self . audio = kwargs [ '<STR_LIT>' ] <EOL> if kwargs . has_key ( '<STR_LIT>' ) : <EOL> self . release_image = kwargs [ '<STR_LIT>' ] <EOL> core_attrs = [ '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if not all ( ca in kwargs for ca in core_attrs ) : <EOL> profile = self . get_attribute ( '<STR_LIT>' , ** { '<STR_LIT:id>' : self . id , '<STR_LIT>' : buckets } ) <EOL> kwargs . update ( profile . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] ) <EOL> [ self . __dict__ . update ( { ca : kwargs . pop ( ca ) } ) for ca in core_attrs ] <EOL> self . cache . update ( kwargs ) <EOL> def get_attribute ( self , * args , ** kwargs ) : <EOL> kwargs [ '<STR_LIT:id>' ] = self . id <EOL> return super ( SongProxy , self ) . get_attribute ( * args , ** kwargs ) <EOL> class TrackProxy ( GenericProxy ) : <EOL> def __init__ ( self , identifier , md5 , properties ) : <EOL> """<STR_LIT>""" <EOL> super ( TrackProxy , self ) . __init__ ( ) <EOL> self . id = identifier <EOL> self . md5 = md5 <EOL> self . analysis_url = None <EOL> self . _object_type = '<STR_LIT>' <EOL> self . __dict__ . update ( properties ) </s>
