Exemple #1
0
def create_g(func, schema=None):
    data = func()
    if data is None:
        raise QQIOError('server responses with error status code')

    count = int(data['total'])

    def read_func(start, end):
        data = func()
        return [_deserialize(data, schema) for data in data['list']]

    reader = RandomSequentialReader(count,
                                    read_func=read_func,
                                    max_per_read=200)
    return reader
Exemple #2
0
    def create_songs_g(self):
        data = self._api.get_album_songs(self.mid)
        if data is None:
            raise QQIOError('server responses with error status code')

        song_list = data

        def read_func(start, end):

            songs = []
            for song in song_list:
                track = _deserialize(song, QQSongSchema)
                songs.append(track)
            return songs

        count = len(song_list)
        reader = RandomSequentialReader(count,
                                        read_func=read_func,
                                        max_per_read=200)
        return reader
Exemple #3
0
 def test_usage(self):
     count = 11
     mock_read_func = mock.MagicMock()
     mock_read_func.side_effect = [list(range(0, 10)), list(range(10, 11))]
     reader = RandomSequentialReader(count,
                                     read_func=mock_read_func,
                                     max_per_read=10)
     self.assertTrue(reader.allow_sequential_read)
     value = next(reader)
     mock_read_func.assert_called_once_with(0, 10)
     self.assertEqual(value, 0)
     self.assertEqual(reader.offset, 1)
     for _ in range(1, 11):
         next(reader)
     mock_read_func.assert_has_calls([
         mock.call(0, 10),
         mock.call(10, 11),
     ])
     self.assertEqual(reader.offset, 11)
     with self.assertRaises(StopIteration):
         next(reader)
     self.assertEqual(reader.offset, 11)
Exemple #4
0
    def create_songs_g(self):
        data = self._api.get_playlist(self.identifier)
        if data is None:
            raise QQIOError('server responses with error status code')

        songlist = data

        count = songlist['cur_song_num']

        song_list = songlist['songlist']

        def read_func(start, end):
            songs = []
            for song in song_list[start:end]:
                track = _deserialize(song, QQSongSchema)
                songs.append(track)
            return songs

        reader = RandomSequentialReader(count,
                                        read_func=read_func,
                                        max_per_read=200)
        return reader