<commit_before>'''
Created on 10/04/2011

@author: mikel
'''
import ctypes

from spotify import DuplicateCallbackError, UnknownCallbackError

from _spotify import playlistcontainer as _playlistcontainer

import playlist


class ProxyPlaylistContainerCallbacks:
    _container = None
    _callbacks = None
    
    
    def __init__(self, container, callbacks):
        self._container = container
        self._callbacks = callbacks
    
    
    def _playlist_added(self, c_container, c_playlist, position, data):
        self._callbacks.playlist_added(
            self._container, self._container.playlist(position), position
        )
    
    
    def _playlist_removed(self, c_container, c_playlist, position, data):
        self._callbacks.playlist_removed(
            self._container, self._container.playlist(position), position
        )
    
    
    def _playlist_moved(self, c_container, c_playlist, position, new_position, data):
        self._callbacks.playlist_moved(
            self._container, self._container.playlist(position),
            position, new_position
        )
    
    
    def _container_loaded(self, container, data):
        self._callbacks.container_loaded(self._container)
        
    
    def get_callback_struct(self):
        return _playlistcontainer.callbacks(
            _playlistcontainer.cb_playlist_added(self._playlist_added),
            _playlistcontainer.cb_playlist_removed(self._playlist_removed),
            _playlistcontainer.cb_playlist_moved(self._playlist_moved),
            _playlistcontainer.cb_container_loaded(self._container_loaded),
        )



class PlaylistContainerCallbacks:
    def playlist_added(self, container, playlist, position):
        pass
    
    def playlist_removed(self, container, playlist, position):
        pass
    
    def playlist_moved(self, container, playlist, position, new_position):
        pass
    
    def container_loaded(self, container):
        pass



class PlaylistContainerIterator:
    _container = None
    _pos = None
    
    def __init__(self, container):
        self._container = container
        self._pos = 0
    
    def __iter__(self):
        return self
    
    def next(self):
        if self._pos < self._container.num_playlists():
            playlist = self._container.playlist(self._pos)
            self._pos += 1
            return playlist
        else:
            raise StopIteration
        


class PlaylistContainer:
    _session = None
    _container = None
    
    _manager = None
    
    #Just a shortcut callback to avoid subclassing PlaylistContainerCallbacks
    _onload_callback = None
    
    #Keep references to callbacks structs an the like
    _callbacks = None
    
    #To store generated playlist instances
    _playlist_objects = None
    
    
    def __init__(self, session, container):
        self._session = session
        self._container = container
        self._playlist_objects = {}
        self._callbacks = {}
        _playlistcontainer.add_ref(self._container)
    
    
    def add_callbacks(self, callbacks):<commit_msg>spotify: playlistcontainer: Added a check for container load status.<commit_after>'''
Created on 10/04/2011

@author: mikel
'''
import ctypes

from spotify import DuplicateCallbackError, UnknownCallbackError

from _spotify import playlistcontainer as _playlistcontainer

import playlist


class ProxyPlaylistContainerCallbacks:
    _container = None
    _callbacks = None
    
    
    def __init__(self, container, callbacks):
        self._container = container
        self._callbacks = callbacks
    
    
    def _playlist_added(self, c_container, c_playlist, position, data):
        self._callbacks.playlist_added(
            self._container, self._container.playlist(position), position
        )
    
    
    def _playlist_removed(self, c_container, c_playlist, position, data):
        self._callbacks.playlist_removed(
            self._container, self._container.playlist(position), position
        )
    
    
    def _playlist_moved(self, c_container, c_playlist, position, new_position, data):
        self._callbacks.playlist_moved(
            self._container, self._container.playlist(position),
            position, new_position
        )
    
    
    def _container_loaded(self, container, data):
        #Also set the container's flag
        self._container.set_loaded(True)
        self._callbacks.container_loaded(self._container)
        
    
    def get_callback_struct(self):
        return _playlistcontainer.callbacks(
            _playlistcontainer.cb_playlist_added(self._playlist_added),
            _playlistcontainer.cb_playlist_removed(self._playlist_removed),
            _playlistcontainer.cb_playlist_moved(self._playlist_moved),
            _playlistcontainer.cb_container_loaded(self._container_loaded),
        )



class PlaylistContainerCallbacks:
    def playlist_added(self, container, playlist, position):
        pass
    
    def playlist_removed(self, container, playlist, position):
        pass
    
    def playlist_moved(self, container, playlist, position, new_position):
        pass
    
    def container_loaded(self, container):
        pass



class PlaylistContainerIterator:
    _container = None
    _pos = None
    
    def __init__(self, container):
        self._container = container
        self._pos = 0
    
    def __iter__(self):
        return self
    
    def next(self):
        if self._pos < self._container.num_playlists():
            playlist = self._container.playlist(self._pos)
            self._pos += 1
            return playlist
        else:
            raise StopIteration
        


class PlaylistContainer:
    _session = None
    _container = None
    
    _manager = None
    
    #Just a shortcut callback to avoid subclassing PlaylistContainerCallbacks
    _onload_callback = None
    
    #Keep references to callbacks structs an the like
    _callbacks = None
    
    #To store generated playlist instances
    _playlist_objects = None
    
    #Is loaded check, not provided by libspotify
    _is_loaded = None
    
    
    def __init__(self, session, container):
        self._session = session
        self._container = container
        self._playlist_objects = {}
        self._callbacks = {}
        self._is_loaded = False
        _playlistcontainer.add_ref(self._container)
    
    
    def set_loaded(self, status):
        self._is_loaded = status
    
    
    def is_loaded(self):
        return self._is_loaded
    
    
    def add_callbacks(self, callbacks):
{'fraction_non_alphanumeric': 0.06786366402921486, 'fraction_numerical': 0.0030432136335970784, 'mean_word_length': 2.520621317621853, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5607640', 'n_tokens_mistral': 1851, 'n_tokens_neox': 1823, 'n_words': 403}