diff --git a/tests/conftest.py b/tests/conftest.py index 0bd1b3b..8dcda61 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -424,7 +424,7 @@ def value(): @pytest.fixture(scope='session') -def id(): +def id_(): return Id(TestId.type, TestId.tag) @@ -434,8 +434,8 @@ def sequence(track): @pytest.fixture(scope='session') -def station(id, icon, restrictions): - return Station(id, TestStation.name, icon, icon, icon, TestStation.id_for_from, restrictions, restrictions, id) +def station(id_, icon, restrictions): + return Station(id_, TestStation.name, icon, icon, icon, TestStation.id_for_from, restrictions, restrictions, id_) @pytest.fixture(scope='session') diff --git a/tests/test_album.py b/tests/test_album.py index b497cb3..0cf3230 100644 --- a/tests/test_album.py +++ b/tests/test_album.py @@ -52,10 +52,9 @@ class TestAlbum: assert album.regions == self.regions def test_de_json_required(self, client, artist, label): - json_dict = {'id': self.id, 'title': self.title, 'cover_uri': self.cover_uri, 'track_count': self.track_count, + json_dict = {'id_': self.id, 'title': self.title, 'cover_uri': self.cover_uri, 'track_count': self.track_count, 'artists': [artist.to_dict()], 'labels': [label.to_dict()], - 'available': self.available, - 'available_for_premium_users': self.available_for_premium_users} + 'available': self.available, 'available_for_premium_users': self.available_for_premium_users} album = Album.de_json(json_dict, client) assert album.id == self.id @@ -68,7 +67,7 @@ class TestAlbum: assert album.available_for_premium_users == self.available_for_premium_users def test_de_json_all(self, client, artist, label, track_position, track): - json_dict = {'id': self.id, 'title': self.title, 'cover_uri': self.cover_uri, 'track_count': self.track_count, + json_dict = {'id_': self.id, 'title': self.title, 'cover_uri': self.cover_uri, 'track_count': self.track_count, 'artists': [artist.to_dict()], 'labels': [label.to_dict()], 'available': self.available, 'available_for_premium_users': self.available_for_premium_users, 'content_warning': self.content_warning, 'original_release_year': self.original_release_year, @@ -77,7 +76,7 @@ class TestAlbum: 'available_partially': self.available_partially, 'bests': self.bests, 'prerolls': self.prerolls, 'volumes': [[track.to_dict()]], 'year': self.year, 'release_date': self.release_date, - 'type': self.type, 'track_position': track_position.to_dict(), 'regions': self.regions} + 'type_': self.type, 'track_position': track_position.to_dict(), 'regions': self.regions} album = Album.de_json(json_dict, client) assert album.id == self.id diff --git a/tests/test_albums_likes.py b/tests/test_albums_likes.py index e04cdcc..76f7bad 100644 --- a/tests/test_albums_likes.py +++ b/tests/test_albums_likes.py @@ -24,7 +24,7 @@ class TestAlbumsLikes: assert albums_likes.timestamp == self.timestamp def test_de_json_all(self, client, album): - json_dict = {'timestamp': self.timestamp, 'id': self.id, 'album': album.to_dict()} + json_dict = {'timestamp': self.timestamp, 'id_': self.id, 'album': album.to_dict()} albums_likes = AlbumsLikes.de_json(json_dict, client) assert albums_likes.timestamp == self.timestamp diff --git a/tests/test_artist.py b/tests/test_artist.py index 23f371d..0689c7f 100644 --- a/tests/test_artist.py +++ b/tests/test_artist.py @@ -50,7 +50,7 @@ class TestArtist: assert artist.end_date == self.end_date def test_de_json_required(self, client, cover): - json_dict = {'id': self.id, 'name': self.name, 'cover': cover.to_dict()} + json_dict = {'id_': self.id, 'name': self.name, 'cover': cover.to_dict()} artist = Artist.de_json(json_dict, client) assert artist.id == self.id @@ -58,7 +58,7 @@ class TestArtist: assert artist.cover == cover def test_de_json_all(self, client, cover, counts, ratings, link, track_without_artists, description): - json_dict = {'id': self.id, 'name': self.name, 'various': self.various, 'composer': self.composer, + json_dict = {'id_': self.id, 'name': self.name, 'various': self.various, 'composer': self.composer, 'cover': cover.to_dict(), 'genres': self.genres, 'op_image': self.op_image, 'no_pictures_from_search': self.no_pictures_from_search, 'counts': counts.to_dict(), 'available': self.available, 'ratings': ratings.to_dict(), 'links': [link.to_dict()], diff --git a/tests/test_artists_likes.py b/tests/test_artists_likes.py index 53fb490..ccccaea 100644 --- a/tests/test_artists_likes.py +++ b/tests/test_artists_likes.py @@ -22,7 +22,7 @@ class TestArtistsLikes: artists_likes = ArtistsLikes.de_json(json_dict, client) def test_de_json_all(self, client, artist): - json_dict = {'id': self.id, 'artist': artist.to_dict(), 'timestamp': self.timestamp} + json_dict = {'id_': self.id, 'artist': artist.to_dict(), 'timestamp': self.timestamp} artists_likes = ArtistsLikes.de_json(json_dict, client) assert artists_likes.id == self.id diff --git a/tests/test_best.py b/tests/test_best.py index b2ca2a7..bf5651a 100644 --- a/tests/test_best.py +++ b/tests/test_best.py @@ -15,7 +15,7 @@ class TestBest: def test_de_json_required(self, client, best_with_result): best_fixture, result = best_with_result - json_dict = {'type': best_fixture.type, 'result': result.to_dict()} + json_dict = {'type_': best_fixture.type, 'result': result.to_dict()} best = Best.de_json(json_dict, client) assert best.type == best_fixture.type @@ -24,7 +24,7 @@ class TestBest: def test_de_json_all(self, client, best_with_result): best_fixture, result = best_with_result - json_dict = {'type': best_fixture.type, 'result': result.to_dict(), 'text': self.text} + json_dict = {'type_': best_fixture.type, 'result': result.to_dict(), 'text': self.text} best = Best.de_json(json_dict, client) assert best.type == best_fixture.type diff --git a/tests/test_block.py b/tests/test_block.py index 020cefa..2203a3b 100644 --- a/tests/test_block.py +++ b/tests/test_block.py @@ -28,7 +28,7 @@ class TestBlock: assert block.data == data def test_de_json_required(self, client, block_entity): - json_dict = {'id': self.id, 'type': self.type, 'type_for_from': self.type_for_from, 'title': self.title, + json_dict = {'id_': self.id, 'type_': self.type, 'type_for_from': self.type_for_from, 'title': self.title, 'entities': [block_entity.to_dict()]} block = Block.de_json(json_dict, client) @@ -41,7 +41,7 @@ class TestBlock: def test_de_json_all(self, client, block_entity, data_with_type): data, type = data_with_type - json_dict = {'id': self.id, 'type': type, 'type_for_from': self.type_for_from, 'title': self.title, + json_dict = {'id_': self.id, 'type_': type, 'type_for_from': self.type_for_from, 'title': self.title, 'entities': [block_entity.to_dict()], 'description': self.description, 'data': data.to_dict()} block = Block.de_json(json_dict, client) diff --git a/tests/test_block_entity.py b/tests/test_block_entity.py index bbcff77..4ad4bdb 100644 --- a/tests/test_block_entity.py +++ b/tests/test_block_entity.py @@ -28,7 +28,7 @@ class TestBlockEntity: def test_de_json_required(self, client, block_entity_data_with_type): data, type = block_entity_data_with_type - json_dict = {'id': self.id, 'type': type, 'data': data.to_dict()} + json_dict = {'id_': self.id, 'type_': type, 'data': data.to_dict()} block_entity = BlockEntity.de_json(json_dict, client) assert block_entity.id == self.id @@ -38,7 +38,7 @@ class TestBlockEntity: def test_de_json_all(self, client, block_entity_data_with_type): data, type = block_entity_data_with_type - json_dict = {'id': self.id, 'type': type, 'data': data.to_dict()} + json_dict = {'id_': self.id, 'type_': type, 'data': data.to_dict()} block_entity = BlockEntity.de_json(json_dict, client) assert block_entity.id == self.id diff --git a/tests/test_cover.py b/tests/test_cover.py index ca40909..c4b0f46 100644 --- a/tests/test_cover.py +++ b/tests/test_cover.py @@ -26,7 +26,7 @@ class TestCover: cover = Cover.de_json(json_dict, client) def test_de_json_all(self, client): - json_dict = {'type': self.type, 'uri': self.uri, 'items_uri': self.items_uri, 'dir': self.dir, + json_dict = {'type_': self.type, 'uri': self.uri, 'items_uri': self.items_uri, 'dir_': self.dir, 'version': self.version, 'custom': self.custom, 'prefix': self.prefix, 'error': self.error} cover = Cover.de_json(json_dict, client) diff --git a/tests/test_discrete_scale.py b/tests/test_discrete_scale.py index 523a3d8..6a413c5 100644 --- a/tests/test_discrete_scale.py +++ b/tests/test_discrete_scale.py @@ -12,7 +12,7 @@ class TestDiscreteScale: assert discrete_scale.max == value def test_de_json_required(self, client, value): - json_dict = {'type': self.type, 'name': self.name, 'min': value.to_dict(), 'max': value.to_dict()} + json_dict = {'type_': self.type, 'name': self.name, 'min_': value.to_dict(), 'max_': value.to_dict()} discrete_scale = DiscreteScale.de_json(json_dict, client) assert discrete_scale.type == self.type @@ -21,7 +21,7 @@ class TestDiscreteScale: assert discrete_scale.max == value def test_de_json_all(self, client, value): - json_dict = {'type': self.type, 'name': self.name, 'min': value.to_dict(), 'max': value.to_dict()} + json_dict = {'type_': self.type, 'name': self.name, 'min_': value.to_dict(), 'max_': value.to_dict()} discrete_scale = DiscreteScale.de_json(json_dict, client) assert discrete_scale.type == self.type diff --git a/tests/test_enum.py b/tests/test_enum.py index 65db9f0..16b3097 100644 --- a/tests/test_enum.py +++ b/tests/test_enum.py @@ -11,7 +11,7 @@ class TestEnum: assert enum.possible_values == [value] def test_de_json_required(self, client, value): - json_dict = {'type': self.type, 'name': self.name, 'possible_values': [value.to_dict()]} + json_dict = {'type_': self.type, 'name': self.name, 'possible_values': [value.to_dict()]} enum = Enum.de_json(json_dict, client) assert enum.type == self.type @@ -19,7 +19,7 @@ class TestEnum: assert enum.possible_values == [value] def test_de_json_all(self, client, value): - json_dict = {'type': self.type, 'name': self.name, 'possible_values': [value.to_dict()]} + json_dict = {'type_': self.type, 'name': self.name, 'possible_values': [value.to_dict()]} enum = Enum.de_json(json_dict, client) assert enum.type == self.type diff --git a/tests/test_event.py b/tests/test_event.py index 3beeb17..492068d 100644 --- a/tests/test_event.py +++ b/tests/test_event.py @@ -23,14 +23,14 @@ class TestEvent: assert event.tracks_count == self.tracks_count def test_de_json_required(self, client): - json_dict = {'id': self.id, 'type': self.type} + json_dict = {'id_': self.id, 'type_': self.type} event = Event.de_json(json_dict, client) assert event.id == self.id assert event.type == self.type def test_de_json_all(self, client, track, artist_event, album_event): - json_dict = {'id': self.id, 'type': self.type, 'type_for_from': self.type_for_from, 'title': self.title, + json_dict = {'id_': self.id, 'type_': self.type, 'type_for_from': self.type_for_from, 'title': self.title, 'tracks': [track.to_dict()], 'artists': [artist_event.to_dict()], 'albums': [album_event.to_dict()], 'message': self.message, 'device': self.device, 'tracks_count': self.tracks_count} diff --git a/tests/test_generated_playlist.py b/tests/test_generated_playlist.py index be5c98d..44c9db4 100644 --- a/tests/test_generated_playlist.py +++ b/tests/test_generated_playlist.py @@ -13,7 +13,7 @@ class TestGeneratedPlaylist: assert generated_playlist.data == playlist def test_de_json_required(self, client, playlist): - json_dict = {'type': self.type, 'ready': self.ready, 'notify': self.notify, 'data': playlist.to_dict()} + json_dict = {'type_': self.type, 'ready': self.ready, 'notify': self.notify, 'data': playlist.to_dict()} generated_playlist = GeneratedPlaylist.de_json(json_dict, client) assert generated_playlist.type == self.type @@ -22,7 +22,7 @@ class TestGeneratedPlaylist: assert generated_playlist.data == playlist def test_de_json_all(self, client, playlist): - json_dict = {'type': self.type, 'ready': self.ready, 'notify': self.notify, 'data': playlist.to_dict()} + json_dict = {'type_': self.type, 'ready': self.ready, 'notify': self.notify, 'data': playlist.to_dict()} generated_playlist = GeneratedPlaylist.de_json(json_dict, client) assert generated_playlist.type == self.type diff --git a/tests/test_genre.py b/tests/test_genre.py index 577af4a..ed2f100 100644 --- a/tests/test_genre.py +++ b/tests/test_genre.py @@ -43,7 +43,7 @@ class TestGenre: assert genre.hide_in_regions == self.hide_in_regions def test_de_json_required(self, client, title, images): - json_dict = {'id': self.id, 'weight': self.weight, 'composer_top': self.composer_top, 'title': self.title, + json_dict = {'id_': self.id, 'weight': self.weight, 'composer_top': self.composer_top, 'title': self.title, 'titles': {'uz': title.to_dict()}, 'images': images.to_dict(), 'show_in_menu': self.show_in_menu} genre = Genre.de_json(json_dict, client) @@ -56,7 +56,7 @@ class TestGenre: assert genre.show_in_menu == self.show_in_menu def test_de_json_all(self, client, title, images, icon, genre_without_sub_genre): - json_dict = {'id': self.id, 'weight': self.weight, 'composer_top': self.composer_top, 'title': self.title, + json_dict = {'id_': self.id, 'weight': self.weight, 'composer_top': self.composer_top, 'title': self.title, 'titles': {'uz': title.to_dict()}, 'images': images.to_dict(), 'show_in_menu': self.show_in_menu, 'full_title': self.full_title, 'url_part': self.url_part, 'color': self.color, 'radio_icon': icon.to_dict(), 'sub_genres': [genre_without_sub_genre.to_dict()], diff --git a/tests/test_id.py b/tests/test_id.py index bcadc08..5237b4d 100644 --- a/tests/test_id.py +++ b/tests/test_id.py @@ -5,23 +5,23 @@ class TestId: type = 'user' tag = 'onyourwave' - def test_expected_values(self, id): - assert id.type == self.type - assert id.tag == self.tag + def test_expected_values(self, id_): + assert id_.type == self.type + assert id_.tag == self.tag def test_de_json_required(self, client): - json_dict = {'type': self.type, 'tag': self.tag} - id = Id.de_json(json_dict, client) + json_dict = {'type_': self.type, 'tag': self.tag} + id_ = Id.de_json(json_dict, client) - assert id.type == self.type - assert id.tag == self.tag + assert id_.type == self.type + assert id_.tag == self.tag def test_de_json_all(self, client): - json_dict = {'type': self.type, 'tag': self.tag} - id = Id.de_json(json_dict, client) + json_dict = {'type_': self.type, 'tag': self.tag} + id_ = Id.de_json(json_dict, client) - assert id.type == self.type - assert id.tag == self.tag + assert id_.type == self.type + assert id_.tag == self.tag def test_equality(self): a = Id(self.type, self.tag) diff --git a/tests/test_label.py b/tests/test_label.py index 014b709..8ff7914 100644 --- a/tests/test_label.py +++ b/tests/test_label.py @@ -10,14 +10,14 @@ class TestLabel: assert label.name == self.name def test_de_json_required(self, client): - json_dict = {'id': self.id, 'name': self.name} + json_dict = {'id_': self.id, 'name': self.name} label = Label.de_json(json_dict, client) assert label.id == self.id assert label.name == self.name def test_de_json_all(self, client): - json_dict = {'id': self.id, 'name': self.name} + json_dict = {'id_': self.id, 'name': self.name} label = Label.de_json(json_dict, client) assert label.id == self.id diff --git a/tests/test_link.py b/tests/test_link.py index 2d0659b..09a36e3 100644 --- a/tests/test_link.py +++ b/tests/test_link.py @@ -14,7 +14,7 @@ class TestLink: assert link.social_network == self.social_network def test_de_json_required(self, client): - json_dict = {'title': self.title, 'href': self.href, 'type': self.type} + json_dict = {'title': self.title, 'href': self.href, 'type_': self.type} link = Link.de_json(json_dict, client) assert link.title == self.title @@ -22,7 +22,7 @@ class TestLink: assert link.type == self.type def test_de_json_all(self, client): - json_dict = {'title': self.title, 'href': self.href, 'type': self.type, 'social_network': self.social_network} + json_dict = {'title': self.title, 'href': self.href, 'type_': self.type, 'social_network': self.social_network} link = Link.de_json(json_dict, client) assert link.title == self.title diff --git a/tests/test_lyrics.py b/tests/test_lyrics.py index f3b1717..39f455e 100644 --- a/tests/test_lyrics.py +++ b/tests/test_lyrics.py @@ -33,7 +33,7 @@ class TestLyrics: assert lyrics.show_translation == self.show_translation def test_de_json_required(self, client): - json_dict = {'id': self.id, 'lyrics': self.lyrics, 'full_lyrics': self.full_lyrics, + json_dict = {'id_': self.id, 'lyrics': self.lyrics, 'full_lyrics': self.full_lyrics, 'has_rights': self.has_rights, 'text_language': self.text_language, 'show_translation': self.show_translation} lyrics = Lyrics.de_json(json_dict, client) @@ -46,7 +46,7 @@ class TestLyrics: assert lyrics.show_translation == self.show_translation def test_de_json_all(self, client): - json_dict = {'id': self.id, 'lyrics': self.lyrics, 'full_lyrics': self.full_lyrics, + json_dict = {'id_': self.id, 'lyrics': self.lyrics, 'full_lyrics': self.full_lyrics, 'has_rights': self.has_rights, 'text_language': self.text_language, 'show_translation': self.show_translation} lyrics = Lyrics.de_json(json_dict, client) diff --git a/tests/test_major.py b/tests/test_major.py index db72143..8bdf8fd 100644 --- a/tests/test_major.py +++ b/tests/test_major.py @@ -10,14 +10,14 @@ class TestMajor: assert major.name == self.name def test_de_json_required(self, client): - json_dict = {'id': self.id, 'name': self.name} + json_dict = {'id_': self.id, 'name': self.name} major = Major.de_json(json_dict, client) assert major.id == self.id assert major.name == self.name def test_de_json_all(self, client): - json_dict = {'id': self.id, 'name': self.name} + json_dict = {'id_': self.id, 'name': self.name} major = Major.de_json(json_dict, client) assert major.id == self.id diff --git a/tests/test_playlists_likes.py b/tests/test_playlists_likes.py index 1dbfc09..b33b48b 100644 --- a/tests/test_playlists_likes.py +++ b/tests/test_playlists_likes.py @@ -24,7 +24,7 @@ class TestPlaylistsLikes: assert playlists_likes.timestamp == self.timestamp def test_de_json_all(self, client, playlist): - json_dict = {'timestamp': self.timestamp, 'id': self.id, 'playlist': playlist.to_dict()} + json_dict = {'timestamp': self.timestamp, 'id_': self.id, 'playlist': playlist.to_dict()} playlists_likes = PlaylistsLikes.de_json(json_dict, client) assert playlists_likes.timestamp == self.timestamp diff --git a/tests/test_product.py b/tests/test_product.py index b41005f..fe08688 100644 --- a/tests/test_product.py +++ b/tests/test_product.py @@ -37,7 +37,7 @@ class TestProduct: assert product.payment_method_types == self.payment_method_types def test_de_json_required(self, client, price): - json_dict = {'product_id': self.product_id, 'type': self.type, + json_dict = {'product_id': self.product_id, 'type_': self.type, 'common_period_duration': self.common_period_duration, 'duration': self.duration, 'trial_duration': self.trial_duration, 'price': price.to_dict(), 'feature': self.feature, 'debug': self.debug} @@ -53,7 +53,7 @@ class TestProduct: assert product.debug == self.debug def test_de_json_all(self, client, price): - json_dict = {'product_id': self.product_id, 'type': self.type, + json_dict = {'product_id': self.product_id, 'type_': self.type, 'common_period_duration': self.common_period_duration, 'duration': self.duration, 'trial_duration': self.trial_duration, 'price': price.to_dict(), 'feature': self.feature, 'debug': self.debug, 'features': self.features, 'description': self.description, diff --git a/tests/test_sequence.py b/tests/test_sequence.py index 2b69662..7f688bc 100644 --- a/tests/test_sequence.py +++ b/tests/test_sequence.py @@ -11,7 +11,7 @@ class TestSequence: assert sequence.liked == self.liked def test_de_json_required(self, client, track): - json_dict = {'type': self.type, 'track': track.to_dict(), 'liked': self.liked} + json_dict = {'type_': self.type, 'track': track.to_dict(), 'liked': self.liked} sequence = Sequence.de_json(json_dict, client) assert sequence.type == self.type @@ -19,7 +19,7 @@ class TestSequence: assert sequence.liked == self.liked def test_de_json_all(self, client, track): - json_dict = {'type': self.type, 'track': track.to_dict(), 'liked': self.liked} + json_dict = {'type_': self.type, 'track': track.to_dict(), 'liked': self.liked} sequence = Sequence.de_json(json_dict, client) assert sequence.type == self.type diff --git a/tests/test_station.py b/tests/test_station.py index 6476da4..e97887d 100644 --- a/tests/test_station.py +++ b/tests/test_station.py @@ -5,8 +5,8 @@ class TestStation: name = 'На вашей волне' id_for_from = 'user-561231028' - def test_expected_values(self, station, id, icon, restrictions): - assert station.id == id + def test_expected_values(self, station, id_, icon, restrictions): + assert station.id == id_ assert station.name == self.name assert station.icon == icon assert station.mts_icon == icon @@ -14,15 +14,15 @@ class TestStation: assert station.id_for_from == self.id_for_from assert station.restrictions == restrictions assert station.restrictions2 == restrictions - assert station.parent_id == id + assert station.parent_id == id_ - def test_de_json_required(self, client, id, icon, restrictions): - json_dict = {'id': id.to_dict(), 'name': self.name, 'icon': icon.to_dict(), 'mts_icon': icon.to_dict(), + def test_de_json_required(self, client, id_, icon, restrictions): + json_dict = {'id_': id_.to_dict(), 'name': self.name, 'icon': icon.to_dict(), 'mts_icon': icon.to_dict(), 'geocell_icon': icon.to_dict(), 'id_for_from': self.id_for_from, 'restrictions': restrictions.to_dict(), 'restrictions2': restrictions.to_dict()} station = Station.de_json(json_dict, client) - assert station.id == id + assert station.id == id_ assert station.name == self.name assert station.icon == icon assert station.mts_icon == icon @@ -31,14 +31,14 @@ class TestStation: assert station.restrictions == restrictions assert station.restrictions2 == restrictions - def test_de_json_all(self, client, id, icon, restrictions): - json_dict = {'id': id.to_dict(), 'name': self.name, 'icon': icon.to_dict(), 'mts_icon': icon.to_dict(), + def test_de_json_all(self, client, id_, icon, restrictions): + json_dict = {'id_': id_.to_dict(), 'name': self.name, 'icon': icon.to_dict(), 'mts_icon': icon.to_dict(), 'geocell_icon': icon.to_dict(), 'id_for_from': self.id_for_from, 'restrictions': restrictions.to_dict(), 'restrictions2': restrictions.to_dict(), - 'parent_id': id.to_dict()} + 'parent_id': id_.to_dict()} station = Station.de_json(json_dict, client) - assert station.id == id + assert station.id == id_ assert station.name == self.name assert station.icon == icon assert station.mts_icon == icon @@ -46,13 +46,13 @@ class TestStation: assert station.id_for_from == self.id_for_from assert station.restrictions == restrictions assert station.restrictions2 == restrictions - assert station.parent_id == id + assert station.parent_id == id_ - def test_equality(self, id, icon, restrictions): - a = Station(id, icon, self.name, icon, icon, icon, self.id_for_from, restrictions, restrictions) - b = Station(id, icon, self.name, None, icon, icon, self.id_for_from, restrictions, restrictions) - c = Station(id, icon, '', icon, icon, None, self.id_for_from, restrictions, restrictions) - d = Station(id, icon, self.name, icon, icon, icon, self.id_for_from, restrictions, restrictions) + def test_equality(self, id_, icon, restrictions): + a = Station(id_, icon, self.name, icon, icon, icon, self.id_for_from, restrictions, restrictions) + b = Station(id_, icon, self.name, None, icon, icon, self.id_for_from, restrictions, restrictions) + c = Station(id_, icon, '', icon, icon, None, self.id_for_from, restrictions, restrictions) + d = Station(id_, icon, self.name, icon, icon, icon, self.id_for_from, restrictions, restrictions) assert a != b != c assert hash(a) != hash(b) != hash(c) diff --git a/tests/test_station_tracks_result.py b/tests/test_station_tracks_result.py index 6dc3e49..96dc4b4 100644 --- a/tests/test_station_tracks_result.py +++ b/tests/test_station_tracks_result.py @@ -4,44 +4,44 @@ from yandex_music import StationTracksResult @pytest.fixture(scope='class') -def station_tracks_result(id, sequence): - return StationTracksResult(id, [sequence], TestStationTracksResult.batch_id, TestStationTracksResult.pumpkin) +def station_tracks_result(id_, sequence): + return StationTracksResult(id_, [sequence], TestStationTracksResult.batch_id, TestStationTracksResult.pumpkin) class TestStationTracksResult: batch_id = '1573227402825981-2727432063278102211' pumpkin = False - def test_expected_values(self, station_tracks_result, id, sequence): - assert station_tracks_result.id == id + def test_expected_values(self, station_tracks_result, id_, sequence): + assert station_tracks_result.id == id_ assert station_tracks_result.sequence == [sequence] assert station_tracks_result.batch_id == self.batch_id assert station_tracks_result.pumpkin == self.pumpkin - def test_de_json_required(self, client, id, sequence): - json_dict = {'id': id.to_dict(), 'sequence': [sequence.to_dict()], 'batch_id': self.batch_id, + def test_de_json_required(self, client, id_, sequence): + json_dict = {'id_': id_.to_dict(), 'sequence': [sequence.to_dict()], 'batch_id': self.batch_id, 'pumpkin': self.pumpkin} station_tracks_result = StationTracksResult.de_json(json_dict, client) - assert station_tracks_result.id == id + assert station_tracks_result.id == id_ assert station_tracks_result.sequence == [sequence] assert station_tracks_result.batch_id == self.batch_id assert station_tracks_result.pumpkin == self.pumpkin - def test_de_json_all(self, client, id, sequence): - json_dict = {'id': id.to_dict(), 'sequence': [sequence.to_dict()], 'batch_id': self.batch_id, + def test_de_json_all(self, client, id_, sequence): + json_dict = {'id_': id_.to_dict(), 'sequence': [sequence.to_dict()], 'batch_id': self.batch_id, 'pumpkin': self.pumpkin} station_tracks_result = StationTracksResult.de_json(json_dict, client) - assert station_tracks_result.id == id + assert station_tracks_result.id == id_ assert station_tracks_result.sequence == [sequence] assert station_tracks_result.batch_id == self.batch_id assert station_tracks_result.pumpkin == self.pumpkin - def test_equality(self, id, sequence): - a = StationTracksResult(id, sequence, self.batch_id, self.pumpkin) - b = StationTracksResult(id, sequence, "", False) - c = StationTracksResult(id, sequence, self.batch_id, self.pumpkin) + def test_equality(self, id_, sequence): + a = StationTracksResult(id_, sequence, self.batch_id, self.pumpkin) + b = StationTracksResult(id_, sequence, "", False) + c = StationTracksResult(id_, sequence, self.batch_id, self.pumpkin) assert a != b assert hash(a) != hash(b) diff --git a/tests/test_supplement.py b/tests/test_supplement.py index cc111cc..139a608 100644 --- a/tests/test_supplement.py +++ b/tests/test_supplement.py @@ -19,7 +19,7 @@ class TestSupplement: assert supplement.radio_is_available == self.radio_is_available def test_de_json_required(self, client, lyrics, video_supplement): - json_dict = {'id': self.id, 'lyrics': lyrics.to_dict(), 'videos': [video_supplement.to_dict()], + json_dict = {'id_': self.id, 'lyrics': lyrics.to_dict(), 'videos': [video_supplement.to_dict()], 'radio_is_available': self.radio_is_available} supplement = Supplement.de_json(json_dict, client) @@ -29,7 +29,7 @@ class TestSupplement: assert supplement.radio_is_available == self.radio_is_available def test_de_json_all(self, client, lyrics, video_supplement): - json_dict = {'id': self.id, 'lyrics': lyrics.to_dict(), 'videos': [video_supplement.to_dict()], + json_dict = {'id_': self.id, 'lyrics': lyrics.to_dict(), 'videos': [video_supplement.to_dict()], 'radio_is_available': self.radio_is_available} supplement = Supplement.de_json(json_dict, client) diff --git a/tests/test_track.py b/tests/test_track.py index a37e701..3c406dd 100644 --- a/tests/test_track.py +++ b/tests/test_track.py @@ -48,7 +48,7 @@ class TestTrack: assert track.available_full_without_permission == self.available_full_without_permission def test_de_json_required(self, client, artist, album): - json_dict = {'id': self.id, 'title': self.title, 'available': self.available, + json_dict = {'id_': self.id, 'title': self.title, 'available': self.available, 'artists': [artist.to_dict()], 'albums': [album.to_dict()]} track = Track.de_json(json_dict, client) @@ -59,11 +59,11 @@ class TestTrack: assert track.albums == [album] def test_de_json_all(self, client, artist, album, major, normalization): - json_dict = {'id': self.id, 'title': self.title, 'available': self.available, + json_dict = {'id_': self.id, 'title': self.title, 'available': self.available, 'available_for_premium_users': self.available_for_premium_users, 'artists': [artist.to_dict()], 'albums': [album.to_dict()], 'lyrics_available': self.lyrics_available, 'real_id': self.real_id, - 'og_image': self.og_image, 'type': self.type, 'cover_uri': self.cover_uri, + 'og_image': self.og_image, 'type_': self.type, 'cover_uri': self.cover_uri, 'major': major.to_dict(), 'duration_ms': self.duration_ms, 'storage_dir': self.storage_dir, 'file_size': self.file_size, 'normalization': normalization.to_dict(), 'error': self.error, 'regions': self.regions, 'available_as_rbt': self.available_as_rbt, diff --git a/tests/test_track_id.py b/tests/test_track_id.py index a63e233..847abf9 100644 --- a/tests/test_track_id.py +++ b/tests/test_track_id.py @@ -10,13 +10,13 @@ class TestTrackId: assert track_id.album_id == self.album_id def test_de_json_required(self, client): - json_dict = {'id': self.id} + json_dict = {'id_': self.id} track_id = TrackId.de_json(json_dict, client) assert track_id.id == self.id def test_de_json_all(self, client): - json_dict = {'id': self.id, 'album_id': self.album_id} + json_dict = {'id_': self.id, 'album_id': self.album_id} track_id = TrackId.de_json(json_dict, client) assert track_id.id == self.id diff --git a/tests/test_track_short.py b/tests/test_track_short.py index b8d92d9..6a77de5 100644 --- a/tests/test_track_short.py +++ b/tests/test_track_short.py @@ -19,14 +19,14 @@ class TestTrackShort: assert track_short.album_id == self.album_id def test_de_json_required(self, client): - json_dict = {'id': self.id, 'timestamp': self.timestamp} + json_dict = {'id_': self.id, 'timestamp': self.timestamp} track_short = TrackShort.de_json(json_dict, client) assert track_short.id == self.id assert track_short.timestamp == self.timestamp def test_de_json_all(self, client): - json_dict = {'id': self.id, 'timestamp': self.timestamp, 'album_id': self.album_id} + json_dict = {'id_': self.id, 'timestamp': self.timestamp, 'album_id': self.album_id} track_short = TrackShort.de_json(json_dict, client) assert track_short.id == self.id diff --git a/tests/test_track_with_ads.py b/tests/test_track_with_ads.py index 45bcff9..b6045d1 100644 --- a/tests/test_track_with_ads.py +++ b/tests/test_track_with_ads.py @@ -9,14 +9,14 @@ class TestTrackWithAds: assert track_with_ads.track == track def test_de_json_required(self, client, track): - json_dict = {'type': self.type, 'track': track.to_dict()} + json_dict = {'type_': self.type, 'track': track.to_dict()} track_with_ads = TrackWithAds.de_json(json_dict, client) assert track_with_ads.type == self.type assert track_with_ads.track == track def test_de_json_all(self, client, track): - json_dict = {'type': self.type, 'track': track.to_dict()} + json_dict = {'type_': self.type, 'track': track.to_dict()} track_with_ads = TrackWithAds.de_json(json_dict, client) assert track_with_ads.type == self.type diff --git a/yandex_music/__init__.py b/yandex_music/__init__.py index 8a16d51..ea716eb 100644 --- a/yandex_music/__init__.py +++ b/yandex_music/__init__.py @@ -97,7 +97,6 @@ from .supplement.video_supplement import VideoSupplement from .pager import Pager from .cover import Cover -from .experiments import Experiments from .invocation_info import InvocationInfo from .track_short import TrackShort from .icon import Icon diff --git a/yandex_music/album/album.py b/yandex_music/album/album.py index af03301..2dcab04 100644 --- a/yandex_music/album/album.py +++ b/yandex_music/album/album.py @@ -3,7 +3,7 @@ from yandex_music import YandexMusicObject class Album(YandexMusicObject): def __init__(self, - id, + id_, title, track_count, artists, @@ -25,12 +25,12 @@ class Album(YandexMusicObject): volumes=None, year=None, release_date=None, - type=None, + type_=None, track_position=None, regions=None, client=None, **kwargs): - self.id = id + self.id = id_ self.title = title self.track_count = track_count self.artists = artists @@ -51,7 +51,7 @@ class Album(YandexMusicObject): self.very_important = very_important self.available_for_mobile = available_for_mobile self.available_partially = available_partially - self.type = type + self.type = type_ self.track_position = track_position self.regions = regions self.original_release_year = original_release_year diff --git a/yandex_music/album/label.py b/yandex_music/album/label.py index 861370b..9b19a28 100644 --- a/yandex_music/album/label.py +++ b/yandex_music/album/label.py @@ -3,25 +3,25 @@ from yandex_music import YandexMusicObject class Label(YandexMusicObject): """Класс, представляющий лейбл альбома. - + Attributes: id (:obj:`int`): Идентификатор альбома. name (:obj:`str`): Название альбома. client (:obj:`yandex_music.Client`): Объект класса :class:`yandex_music.Client` представляющий клиент Yandex Music. Args: - id (:obj:`int`): Идентификатор альбома. + id_ (:obj:`int`): Идентификатор альбома. name (:obj:`str`): Название альбома. client (:obj:`yandex_music.Client`, optional): Объект класса :class:`yandex_music.Client` представляющий клиент Yandex Music. **kwargs: Произвольные ключевые аргументы полученные от API. """ def __init__(self, - id, + id_, name, client=None, **kwargs): - self.id = id + self.id = id_ self.name = name self.client = client @@ -33,8 +33,8 @@ class Label(YandexMusicObject): Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. - client (:obj:`yandex_music.Client`): Объект класса :class:`yandex_music.Client` представляющий клиент Yandex - Music. + client (:obj:`yandex_music.Client`): Объект класса :class:`yandex_music.Client` представляющий клиент + Yandex Music. Returns: :obj:`yandex_music.Label`: Объект класса :class:`yandex_music.Label`. """ diff --git a/yandex_music/artist/artist.py b/yandex_music/artist/artist.py index b766c16..6405269 100644 --- a/yandex_music/artist/artist.py +++ b/yandex_music/artist/artist.py @@ -3,7 +3,7 @@ from yandex_music import YandexMusicObject class Artist(YandexMusicObject): def __init__(self, - id, + id_, name, cover, various=None, @@ -30,7 +30,7 @@ class Artist(YandexMusicObject): end_date=None, client=None, **kwargs): - self.id = id + self.id = id_ self.name = name self.cover = cover diff --git a/yandex_music/artist/artist_tracks.py b/yandex_music/artist/artist_tracks.py index 0c69949..40ba151 100644 --- a/yandex_music/artist/artist_tracks.py +++ b/yandex_music/artist/artist_tracks.py @@ -17,7 +17,7 @@ class ArtistTracks(YandexMusicObject): Music. **kwargs: Произвольные ключевые аргументы полученные от API. """ - + def __init__(self, tracks, pager, diff --git a/yandex_music/artist/link.py b/yandex_music/artist/link.py index 1bf4dce..2e42a38 100644 --- a/yandex_music/artist/link.py +++ b/yandex_music/artist/link.py @@ -5,13 +5,13 @@ class Link(YandexMusicObject): def __init__(self, title, href, - type, + type_, social_network=None, client=None, **kwargs): self.title = title self.href = href - self.type = type + self.type = type_ self.social_network = social_network diff --git a/yandex_music/base.py b/yandex_music/base.py index e16575b..7d00dc8 100644 --- a/yandex_music/base.py +++ b/yandex_music/base.py @@ -1,5 +1,7 @@ from abc import ABCMeta +import builtins + ujson = False try: import ujson as json @@ -7,6 +9,8 @@ try: except ImportError: import json +reserved_names = [name.lower() for name in dir(builtins)] + class YandexMusicObject: __metaclass__ = ABCMeta @@ -48,6 +52,11 @@ class YandexMusicObject: data.pop('client', None) data.pop('_id_attrs', None) + for k, v in data.copy().items(): + if k.lower() in reserved_names: + data.pop(k) + data.update({f'{k}_': v}) + return parse(data) def __eq__(self, other): diff --git a/yandex_music/cover.py b/yandex_music/cover.py index ca6915d..c0da12a 100644 --- a/yandex_music/cover.py +++ b/yandex_music/cover.py @@ -17,10 +17,10 @@ class Cover(YandexMusicObject): Music. Args: - type (:obj:`str`, optional): Тип обложки. + type_ (:obj:`str`, optional): Тип обложки. uri (:obj:`str`, optional): Ссылка на изображение. items_uri (:obj:`str`, optional): Список ссылок на изображения. - dir (:obj:`str`, optional): Директория хранения изображения на сервере. + dir_ (:obj:`str`, optional): Директория хранения изображения на сервере. version (:obj:`str`, optional): Версия. custom (:obj:`bool`, optional): Является ли обложка пользовательской. prefix (:obj:`str`, optional): Уникальный идентификатор. @@ -31,21 +31,21 @@ class Cover(YandexMusicObject): """ def __init__(self, - type=None, + type_=None, uri=None, items_uri=None, - dir=None, + dir_=None, version=None, custom=None, prefix=None, error=None, client=None, **kwargs): - self.type = type + self.type = type_ self.uri = uri self.items_uri = items_uri self.prefix = prefix - self.dir = dir + self.dir = dir_ self.version = version self.custom = custom self.error = error diff --git a/yandex_music/feed/event.py b/yandex_music/feed/event.py index 4369e00..5ae4f08 100644 --- a/yandex_music/feed/event.py +++ b/yandex_music/feed/event.py @@ -3,8 +3,8 @@ from yandex_music import YandexMusicObject class Event(YandexMusicObject): def __init__(self, - id, - type, + id_, + type_, type_for_from=None, title=None, tracks=None, @@ -15,8 +15,8 @@ class Event(YandexMusicObject): tracks_count=None, client=None, **kwargs): - self.id = id - self.type = type + self.id = id_ + self.type = type_ self.type_for_from = type_for_from self.title = title diff --git a/yandex_music/feed/generated_playlist.py b/yandex_music/feed/generated_playlist.py index a8a0e3f..a537a16 100644 --- a/yandex_music/feed/generated_playlist.py +++ b/yandex_music/feed/generated_playlist.py @@ -3,13 +3,13 @@ from yandex_music import YandexMusicObject class GeneratedPlaylist(YandexMusicObject): def __init__(self, - type, + type_, ready, notify, data, client=None, **kwargs): - self.type = type + self.type = type_ self.ready = ready self.notify = notify self.data = data diff --git a/yandex_music/feed/track_with_ads.py b/yandex_music/feed/track_with_ads.py index dcf2c62..86c62a2 100644 --- a/yandex_music/feed/track_with_ads.py +++ b/yandex_music/feed/track_with_ads.py @@ -3,11 +3,11 @@ from yandex_music import YandexMusicObject class TrackWithAds(YandexMusicObject): def __init__(self, - type, + type_, track, client=None, **kwargs): - self.type = type + self.type = type_ self.track = track self.client = client diff --git a/yandex_music/genre/genre.py b/yandex_music/genre/genre.py index c8f7e89..0035e35 100644 --- a/yandex_music/genre/genre.py +++ b/yandex_music/genre/genre.py @@ -3,7 +3,7 @@ from yandex_music import YandexMusicObject class Genre(YandexMusicObject): def __init__(self, - id, + id_, weight, composer_top, title, @@ -18,7 +18,7 @@ class Genre(YandexMusicObject): hide_in_regions=None, client=None, **kwargs): - self.id = id + self.id = id_ self.weight = weight self.composer_top = composer_top self.title = title diff --git a/yandex_music/landing/block.py b/yandex_music/landing/block.py index bd11a3c..a58cf7c 100644 --- a/yandex_music/landing/block.py +++ b/yandex_music/landing/block.py @@ -3,8 +3,8 @@ from yandex_music import YandexMusicObject class Block(YandexMusicObject): def __init__(self, - id, - type, + id_, + type_, type_for_from, title, entities, @@ -13,8 +13,8 @@ class Block(YandexMusicObject): client=None, **kwargs): - self.id = id - self.type = type + self.id = id_ + self.type = type_ self.type_for_from = type_for_from self.title = title self.entities = entities @@ -37,7 +37,7 @@ class Block(YandexMusicObject): from yandex_music import BlockEntity, PlayContextsData, PersonalPlaylistsData data['entities'] = BlockEntity.de_list(data.get('entities'), client) - block_type = data.get('type') + block_type = data.get('type_') if block_type == 'personal-playlists': data['data'] = PersonalPlaylistsData.de_json(data.get('data'), client) elif block_type == 'play-contexts': diff --git a/yandex_music/landing/block_entity.py b/yandex_music/landing/block_entity.py index 8312eaa..76d643c 100644 --- a/yandex_music/landing/block_entity.py +++ b/yandex_music/landing/block_entity.py @@ -15,14 +15,14 @@ de_json = { class BlockEntity(YandexMusicObject): def __init__(self, - id, - type, + id_, + type_, data, client=None, **kwargs): - self.id = id - self.type = type + self.id = id_ + self.type = type_ self.data = data self.client = client @@ -34,7 +34,7 @@ class BlockEntity(YandexMusicObject): return None data = super(BlockEntity, cls).de_json(data, client) - data['data'] = de_json.get(data.get('type'))(data.get('data'), client) + data['data'] = de_json.get(data.get('type_'))(data.get('data'), client) return cls(client=client, **data) diff --git a/yandex_music/landing/track_id.py b/yandex_music/landing/track_id.py index 4762271..1d10694 100644 --- a/yandex_music/landing/track_id.py +++ b/yandex_music/landing/track_id.py @@ -3,11 +3,11 @@ from yandex_music import YandexMusicObject class TrackId(YandexMusicObject): def __init__(self, - id, + id_, album_id=None, client=None, **kwargs): - self.id = id + self.id = id_ self.album_id = album_id self.client = client diff --git a/yandex_music/likes/albums_likes.py b/yandex_music/likes/albums_likes.py index 3e07eb2..11ed75d 100644 --- a/yandex_music/likes/albums_likes.py +++ b/yandex_music/likes/albums_likes.py @@ -4,11 +4,11 @@ from yandex_music import YandexMusicObject class AlbumsLikes(YandexMusicObject): def __init__(self, timestamp, - id=None, + id_=None, album=None, client=None, **kwargs): - self.id = id + self.id = id_ self.album = album self.timestamp = timestamp diff --git a/yandex_music/likes/artists_likes.py b/yandex_music/likes/artists_likes.py index 574b9e1..3c38051 100644 --- a/yandex_music/likes/artists_likes.py +++ b/yandex_music/likes/artists_likes.py @@ -3,12 +3,12 @@ from yandex_music import YandexMusicObject class ArtistsLikes(YandexMusicObject): def __init__(self, - id=None, + id_=None, artist=None, timestamp=None, client=None, **kwargs): - self.id = id + self.id = id_ self.artist = artist self.timestamp = timestamp diff --git a/yandex_music/likes/playlists_likes.py b/yandex_music/likes/playlists_likes.py index c07a257..f68f6e6 100644 --- a/yandex_music/likes/playlists_likes.py +++ b/yandex_music/likes/playlists_likes.py @@ -4,11 +4,11 @@ from yandex_music import YandexMusicObject class PlaylistsLikes(YandexMusicObject): def __init__(self, timestamp, - id=None, + id_=None, playlist=None, client=None, **kwargs): - self.id = id + self.id = id_ self.playlist = playlist self.timestamp = timestamp diff --git a/yandex_music/playlist/user.py b/yandex_music/playlist/user.py index 5a8cb5b..500e376 100644 --- a/yandex_music/playlist/user.py +++ b/yandex_music/playlist/user.py @@ -39,15 +39,15 @@ class User(YandexMusicObject): self.client = client self._id_attrs = (self.uid, self.login) - def download_avatar(self, filename, format='normal'): + def download_avatar(self, filename, format_='normal'): """Загрузка изображения пользователя. Args: filename (:obj:`str`): Путь для сохранения файла с названием и расширением. - format (:obj:`str`, optional): Формат желаемого изображения (normal, orig, small, big). + format_ (:obj:`str`, optional): Формат желаемого изображения (normal, orig, small, big). """ - self.client.request.download(f'https://upics.yandex.net/{self.uid}/{format}', filename) + self.client.request.download(f'https://upics.yandex.net/{self.uid}/{format_}', filename) @classmethod def de_json(cls, data, client): diff --git a/yandex_music/rotor/discrete_scale.py b/yandex_music/rotor/discrete_scale.py index ae007e1..286b7df 100644 --- a/yandex_music/rotor/discrete_scale.py +++ b/yandex_music/rotor/discrete_scale.py @@ -3,16 +3,16 @@ from yandex_music import YandexMusicObject class DiscreteScale(YandexMusicObject): def __init__(self, - type, + type_, name, - min, - max, + min_, + max_, client=None, **kwargs): - self.type = type + self.type = type_ self.name = name - self.min = min - self.max = max + self.min = min_ + self.max = max_ self.client = client self._id_attrs = (self.type, self.name, self.min, self.max) @@ -24,7 +24,7 @@ class DiscreteScale(YandexMusicObject): data = super(DiscreteScale, cls).de_json(data, client) from yandex_music import Value - data['min'] = Value.de_json(data.get('min'), client) - data['max'] = Value.de_json(data.get('max'), client) + data['min_'] = Value.de_json(data.get('min_'), client) + data['max_'] = Value.de_json(data.get('max_'), client) return cls(client=client, **data) diff --git a/yandex_music/rotor/enum.py b/yandex_music/rotor/enum.py index 76e8baa..90c74c4 100644 --- a/yandex_music/rotor/enum.py +++ b/yandex_music/rotor/enum.py @@ -3,12 +3,12 @@ from yandex_music import YandexMusicObject class Enum(YandexMusicObject): def __init__(self, - type, + type_, name, possible_values, client=None, **kwargs): - self.type = type + self.type = type_ self.name = name self.possible_values = possible_values diff --git a/yandex_music/rotor/id.py b/yandex_music/rotor/id.py index f9e76a2..17cfe33 100644 --- a/yandex_music/rotor/id.py +++ b/yandex_music/rotor/id.py @@ -3,11 +3,11 @@ from yandex_music import YandexMusicObject class Id(YandexMusicObject): def __init__(self, - type, + type_, tag, client=None, **kwargs): - self.type = type + self.type = type_ self.tag = tag self.client = client diff --git a/yandex_music/rotor/restrictions.py b/yandex_music/rotor/restrictions.py index e684cbf..2908eb5 100644 --- a/yandex_music/rotor/restrictions.py +++ b/yandex_music/rotor/restrictions.py @@ -33,6 +33,6 @@ class Restrictions(YandexMusicObject): data = super(Restrictions, cls).de_json(data, client) for key, value in data.items(): - data[key] = de_json.get(value.get('type'))(value, client) + data[key] = de_json.get(value.get('type_'))(value, client) return cls(client=client, **data) diff --git a/yandex_music/rotor/sequence.py b/yandex_music/rotor/sequence.py index 99d0c3e..65425ff 100644 --- a/yandex_music/rotor/sequence.py +++ b/yandex_music/rotor/sequence.py @@ -3,12 +3,12 @@ from yandex_music import YandexMusicObject class Sequence(YandexMusicObject): def __init__(self, - type, + type_, track, liked, client=None, **kwargs): - self.type = type + self.type = type_ self.track = track self.liked = liked diff --git a/yandex_music/rotor/station.py b/yandex_music/rotor/station.py index f22539d..742eb61 100644 --- a/yandex_music/rotor/station.py +++ b/yandex_music/rotor/station.py @@ -3,7 +3,7 @@ from yandex_music import YandexMusicObject class Station(YandexMusicObject): def __init__(self, - id, + id_, name, icon, mts_icon, @@ -14,7 +14,7 @@ class Station(YandexMusicObject): parent_id=None, client=None, **kwargs): - self.id = id + self.id = id_ self.name = name self.icon = icon self.mts_icon = mts_icon @@ -36,7 +36,7 @@ class Station(YandexMusicObject): data = super(Station, cls).de_json(data, client) from yandex_music import Id, Icon, Restrictions - data['id'] = Id.de_json(data.get('id'), client) + data['id_'] = Id.de_json(data.get('id_'), client) data['parent_id'] = Id.de_json(data.get('parent_id'), client) data['icon'] = Icon.de_json(data.get('icon'), client) data['mts_icon'] = Icon.de_json(data.get('mts_icon'), client) diff --git a/yandex_music/rotor/station_tracks_result.py b/yandex_music/rotor/station_tracks_result.py index ca6e8df..cf13d5c 100644 --- a/yandex_music/rotor/station_tracks_result.py +++ b/yandex_music/rotor/station_tracks_result.py @@ -3,13 +3,13 @@ from yandex_music import YandexMusicObject class StationTracksResult(YandexMusicObject): def __init__(self, - id, + id_, sequence, batch_id, pumpkin, client=None, **kwargs): - self.id = id + self.id = id_ self.sequence = sequence self.batch_id = batch_id self.pumpkin = pumpkin @@ -24,7 +24,7 @@ class StationTracksResult(YandexMusicObject): data = super(StationTracksResult, cls).de_json(data, client) from yandex_music import Id, Sequence - data['id'] = Id.de_json(data.get('id'), client) + data['id_'] = Id.de_json(data.get('id_'), client) data['sequence'] = Sequence.de_list(data.get('sequence'), client) return cls(client=client, **data) diff --git a/yandex_music/search/best.py b/yandex_music/search/best.py index fb25dbf..cd194ba 100644 --- a/yandex_music/search/best.py +++ b/yandex_music/search/best.py @@ -12,12 +12,12 @@ de_json_result = { class Best(YandexMusicObject): def __init__(self, - type, + type_, result, text=None, client=None, **kwargs): - self.type = type + self.type = type_ self.result = result self.text = text @@ -31,6 +31,6 @@ class Best(YandexMusicObject): return None data = super(Best, cls).de_json(data, client) - data['result'] = de_json_result.get(data.get('type'))(data.get('result'), client) + data['result'] = de_json_result.get(data.get('type_'))(data.get('result'), client) return cls(client=client, **data) diff --git a/yandex_music/search/search_result.py b/yandex_music/search/search_result.py index 2a4d164..8ca3bbd 100644 --- a/yandex_music/search/search_result.py +++ b/yandex_music/search/search_result.py @@ -27,11 +27,11 @@ class SearchResult(YandexMusicObject): self._id_attrs = (self.total, self.per_page, self.order, self.results) @classmethod - def de_json(cls, data, client, type=None): + def de_json(cls, data, client, type_=None): if not data: return None data = super(SearchResult, cls).de_json(data, client) - data['results'] = de_json_result.get(type)(data.get('results'), client) + data['results'] = de_json_result.get(type_)(data.get('results'), client) return cls(client=client, **data) diff --git a/yandex_music/status/account.py b/yandex_music/status/account.py index 4eca212..7aee150 100644 --- a/yandex_music/status/account.py +++ b/yandex_music/status/account.py @@ -82,15 +82,15 @@ class Account(YandexMusicObject): if self.uid: self._id_attrs = (self.uid,) - def download_avatar(self, filename, format='normal'): + def download_avatar(self, filename, format_='normal'): """Загрузка изображения пользователя. Args: filename (:obj:`str`): Путь для сохранения файла с названием и расширением. - format (:obj:`str`): Формат желаемого изображения (normal, orig, small, big). + format_ (:obj:`str`): Формат желаемого изображения (normal, orig, small, big). """ - self.client.request.download(f'https://upics.yandex.net/{self.uid}/{format}', filename) + self.client.request.download(f'https://upics.yandex.net/{self.uid}/{format_}', filename) @classmethod def de_json(cls, data, client): diff --git a/yandex_music/status/product.py b/yandex_music/status/product.py index 1a40067..39f0b08 100644 --- a/yandex_music/status/product.py +++ b/yandex_music/status/product.py @@ -26,7 +26,7 @@ class Product(YandexMusicObject): Args: product_id (:obj:`str`): Уникальный идентификатор. - type (:obj:`str`): Тип продаваемого. + type_ (:obj:`str`): Тип продаваемого. common_period_duration (:obj:`str`): Длительность общего периода. duration (:obj:`int`): Длительность. trial_duration (:obj:`int`): Длительность испытательного срока. @@ -48,7 +48,7 @@ class Product(YandexMusicObject): def __init__(self, product_id, - type, + type_, common_period_duration, duration, trial_duration, @@ -66,7 +66,7 @@ class Product(YandexMusicObject): client=None, **kwargs): self.product_id = product_id - self.type = type + self.type = type_ self.common_period_duration = common_period_duration self.duration = duration self.trial_duration = trial_duration diff --git a/yandex_music/supplement/lyrics.py b/yandex_music/supplement/lyrics.py index 5132362..b9efea6 100644 --- a/yandex_music/supplement/lyrics.py +++ b/yandex_music/supplement/lyrics.py @@ -15,7 +15,7 @@ class Lyrics(YandexMusicObject): Music. Args: - id (:obj:`int`): Уникальный идентификатор текста трека. + id_ (:obj:`int`): Уникальный идентификатор текста трека. lyrics (:obj:`str`): Первые строки текст песни. has_rights (:obj:`bool`): Есть ли права. full_lyrics (:obj:`str`): Текст песни. @@ -27,7 +27,7 @@ class Lyrics(YandexMusicObject): """ def __init__(self, - id, + id_, lyrics, full_lyrics, has_rights, @@ -35,7 +35,7 @@ class Lyrics(YandexMusicObject): show_translation, client=None, **kwargs): - self.id = id + self.id = id_ self.lyrics = lyrics self.full_lyrics = full_lyrics self.has_rights = has_rights @@ -60,7 +60,7 @@ class Lyrics(YandexMusicObject): """ if not data: return None - + data = super(Lyrics, cls).de_json(data, client) return cls(client=client, **data) diff --git a/yandex_music/supplement/supplement.py b/yandex_music/supplement/supplement.py index 218a6af..0583bba 100644 --- a/yandex_music/supplement/supplement.py +++ b/yandex_music/supplement/supplement.py @@ -14,7 +14,7 @@ class Supplement(YandexMusicObject): Music. Args: - id (:obj:`int`): Уникальный идентификатор дополнительной информации. + id_ (:obj:`int`): Уникальный идентификатор дополнительной информации. lyrics (:obj:`yandex_music.Lyrics`): Объект класса :class:`yandex_music.Lyrics` представляющий текст песни. videos (:obj:`yandex_music.VideoSupplement`): Объект класса :class:`yandex_music.VideoSupplement` представляющий видео. @@ -25,13 +25,13 @@ class Supplement(YandexMusicObject): """ def __init__(self, - id, + id_, lyrics, videos, radio_is_available, client=None, **kwargs): - self.id = id + self.id = id_ self.lyrics = lyrics self.videos = videos self.radio_is_available = radio_is_available @@ -53,7 +53,7 @@ class Supplement(YandexMusicObject): """ if not data: return None - + data = super(Supplement, cls).de_json(data, client) from yandex_music import Lyrics, VideoSupplement data['lyrics'] = Lyrics.de_json(data.get('lyrics'), client) diff --git a/yandex_music/track/major.py b/yandex_music/track/major.py index 78e85d3..9f5009f 100644 --- a/yandex_music/track/major.py +++ b/yandex_music/track/major.py @@ -3,11 +3,11 @@ from yandex_music import YandexMusicObject class Major(YandexMusicObject): def __init__(self, - id, + id_, name, client=None, **kwargs): - self.id = id + self.id = id_ self.name = name self.client = client diff --git a/yandex_music/track/track.py b/yandex_music/track/track.py index 6569e64..d219b88 100644 --- a/yandex_music/track/track.py +++ b/yandex_music/track/track.py @@ -3,7 +3,7 @@ from yandex_music import YandexMusicObject class Track(YandexMusicObject): def __init__(self, - id, + id_, title, available, artists, @@ -12,7 +12,7 @@ class Track(YandexMusicObject): lyrics_available=None, real_id=None, og_image=None, - type=None, + type_=None, cover_uri=None, major=None, duration_ms=None, @@ -28,7 +28,7 @@ class Track(YandexMusicObject): available_full_without_permission=None, client=None, **kwargs): - self.id = id + self.id = id_ self.title = title self.available = available self.artists = artists @@ -38,7 +38,7 @@ class Track(YandexMusicObject): self.lyrics_available = lyrics_available self.real_id = real_id self.og_image = og_image - self.type = type + self.type = type_ self.cover_uri = cover_uri self.major = major self.duration_ms = duration_ms diff --git a/yandex_music/track_short.py b/yandex_music/track_short.py index b35cfef..187bdfc 100644 --- a/yandex_music/track_short.py +++ b/yandex_music/track_short.py @@ -12,7 +12,7 @@ class TrackShort(YandexMusicObject): Music. Args: - id (:obj:`str`): Уникальный идентификатор трека. + id_ (:obj:`str`): Уникальный идентификатор трека. timestamp (:obj:`str`): Дата TODO. album_id (:obj:`str`, optional): Уникальный идентификатор альбома. client (:obj:`yandex_music.Client`, optional): Объект класса :class:`yandex_music.Client` представляющий клиент @@ -21,12 +21,12 @@ class TrackShort(YandexMusicObject): """ def __init__(self, - id, + id_, timestamp, album_id=None, client=None, **kwargs): - self.id = id + self.id = id_ self.timestamp = timestamp self.album_id = album_id diff --git a/yandex_music/utils/request.py b/yandex_music/utils/request.py index 49911b2..5df4471 100644 --- a/yandex_music/utils/request.py +++ b/yandex_music/utils/request.py @@ -1,12 +1,14 @@ import re import logging -import requests +import builtins # Не используется ujson из-за отсутствия в нём object_hook'a # Отправка вообще application/x-www-form-urlencoded, а не JSON'a # https://github.com/psf/requests/blob/master/requests/models.py#L508 import json +import requests + from yandex_music.utils.captcha_response import CaptchaResponse from yandex_music.utils.response import Response from yandex_music.exceptions import Unauthorized, BadRequest, NetworkError, YandexMusicError, CaptchaRequired, \ @@ -17,6 +19,7 @@ HEADERS = { 'X-Yandex-Music-Client': 'WindowsPhone/3.20', } +reserved_names = [name.lower() for name in dir(builtins)] + ['client'] logging.getLogger('urllib3').setLevel(logging.WARNING) @@ -63,7 +66,8 @@ class Request: cleaned_object = {} for key, value in obj.items(): key = Request._convert_camel_to_snake(key.replace('-', '_')) - key = key.replace('client', 'client_') + if key.lower() in reserved_names: + key += '_' if len(key) and key[0].isdigit(): key = '_' + key