コード例 #1
0
ファイル: toplist.py プロジェクト: jcranston/juke
    def __init__(
            self, session, type=None, region=None, canonical_username=None,
            callback=None, sp_toplistbrowse=None, add_ref=True):

        assert (type is not None and region is not None) or sp_toplistbrowse, \
            'type and region, or sp_toplistbrowse, is required'

        self._session = session
        self.type = type
        self.region = region
        self.canonical_username = canonical_username
        self.loaded_event = threading.Event()

        if sp_toplistbrowse is None:
            if isinstance(region, ToplistRegion):
                region = int(region)
            else:
                region = utils.to_country_code(region)

            handle = ffi.new_handle((self._session, self, callback))
            self._session._callback_handles.add(handle)

            sp_toplistbrowse = lib.sp_toplistbrowse_create(
                self._session._sp_session, int(type), region,
                utils.to_char_or_null(canonical_username),
                _toplistbrowse_complete_callback, handle)
            add_ref = False

        if add_ref:
            lib.sp_toplistbrowse_add_ref(sp_toplistbrowse)
        self._sp_toplistbrowse = ffi.gc(
            sp_toplistbrowse, lib.sp_toplistbrowse_release)
コード例 #2
0
    def __init__(
        self,
        session,
        type=None,
        region=None,
        canonical_username=None,
        callback=None,
        sp_toplistbrowse=None,
        add_ref=True,
    ):

        assert (type is not None and region is not None) or sp_toplistbrowse, (
            'type and region, or sp_toplistbrowse, is required')

        self._session = session
        self.type = type
        self.region = region
        self.canonical_username = canonical_username
        self.loaded_event = threading.Event()

        if sp_toplistbrowse is None:
            if isinstance(region, ToplistRegion):
                region = int(region)
            else:
                region = utils.to_country_code(region)

            handle = ffi.new_handle((self._session, self, callback))
            self._session._callback_handles.add(handle)

            sp_toplistbrowse = lib.sp_toplistbrowse_create(
                self._session._sp_session,
                int(type),
                region,
                utils.to_char_or_null(canonical_username),
                _toplistbrowse_complete_callback,
                handle,
            )
            add_ref = False

        if add_ref:
            lib.sp_toplistbrowse_add_ref(sp_toplistbrowse)
        self._sp_toplistbrowse = ffi.gc(sp_toplistbrowse,
                                        lib.sp_toplistbrowse_release)
コード例 #3
0
ファイル: toplist.py プロジェクト: thomasvs/pyspotify
    def __init__(self,
                 type=None,
                 region=None,
                 canonical_username=None,
                 callback=None,
                 sp_toplistbrowse=None,
                 add_ref=True):

        assert (type is not None and region is not None) or sp_toplistbrowse, \
            'type and region, or sp_toplistbrowse, is required'

        # TODO Document these attributes?
        self.type = type
        self.region = region
        self.canonical_username = canonical_username

        self.complete_event = threading.Event()
        self._callback_handles = set()

        if sp_toplistbrowse is None:
            if isinstance(region, ToplistRegion):
                region = int(region)
            else:
                region = utils.to_country_code(region)

            handle = ffi.new_handle((callback, self))
            # TODO Think through the life cycle of the handle object. Can it
            # happen that we GC the search and handle object, and then later
            # the callback is called?
            self._callback_handles.add(handle)

            sp_toplistbrowse = lib.sp_toplistbrowse_create(
                spotify.session_instance._sp_session, int(type), region,
                utils.to_char_or_null(canonical_username),
                _toplistbrowse_complete_callback, handle)
            add_ref = False

        if add_ref:
            lib.sp_toplistbrowse_add_ref(sp_toplistbrowse)
        self._sp_toplistbrowse = ffi.gc(sp_toplistbrowse,
                                        lib.sp_toplistbrowse_release)
コード例 #4
0
ファイル: test_utils.py プロジェクト: mdries14887/pyspotify
 def test_fails_if_not_in_uppercase(self):
     with self.assertRaises(ValueError):
         utils.to_country_code('no')
コード例 #5
0
ファイル: test_utils.py プロジェクト: mdries14887/pyspotify
 def test_fails_if_not_exactly_two_chars(self):
     with self.assertRaises(ValueError):
         utils.to_country_code('NOR')
コード例 #6
0
ファイル: test_utils.py プロジェクト: mdries14887/pyspotify
 def test_bytes_to_country_code(self):
     self.assertEqual(utils.to_country_code(b'NO'), 20047)
     self.assertEqual(utils.to_country_code(b'SE'), 21317)
コード例 #7
0
ファイル: test_utils.py プロジェクト: mdries14887/pyspotify
 def test_unicode_to_country_code(self):
     self.assertEqual(utils.to_country_code('NO'), 20047)
     self.assertEqual(utils.to_country_code('SE'), 21317)