From 27b9c232c2bdd1a870711dadd6eabb0a58d6081c Mon Sep 17 00:00:00 2001 From: spl0k Date: Tue, 30 Jan 2018 21:56:06 +0100 Subject: [PATCH] Small refactoring of supysonic.api.get_entity --- supysonic/api/__init__.py | 10 +++++----- supysonic/api/annotation.py | 2 +- supysonic/api/browse.py | 8 ++++---- supysonic/api/media.py | 6 +++--- supysonic/api/playlists.py | 6 +++--- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/supysonic/api/__init__.py b/supysonic/api/__init__.py index 56f6fb1..69789e2 100644 --- a/supysonic/api/__init__.py +++ b/supysonic/api/__init__.py @@ -99,19 +99,19 @@ def get_client_prefs(): def not_found(*args, **kwargs): return request.error_formatter(0, 'Not implemented'), 501 -def get_entity(req, cls, param = 'id'): - eid = req.values.get(param) +def get_entity(cls, param = 'id'): + eid = request.values.get(param) if not eid: - return False, req.error_formatter(10, 'Missing %s id' % cls.__name__) + return False, request.error_formatter(10, 'Missing %s id' % cls.__name__) try: eid = uuid.UUID(eid) entity = cls[eid] return True, entity except ValueError: - return False, req.error_formatter(0, 'Invalid %s id' % cls.__name__) + return False, request.error_formatter(0, 'Invalid %s id' % cls.__name__) except ObjectNotFound: - return False, (req.error_formatter(70, '%s not found' % cls.__name__), 404) + return False, (request.error_formatter(70, '%s not found' % cls.__name__), 404) from .system import * from .browse import * diff --git a/supysonic/api/annotation.py b/supysonic/api/annotation.py index be3b65e..a6cc38c 100644 --- a/supysonic/api/annotation.py +++ b/supysonic/api/annotation.py @@ -175,7 +175,7 @@ def rate(): @api.route('/scrobble.view', methods = [ 'GET', 'POST' ]) @db_session def scrobble(): - status, res = get_entity(request, Track) + status, res = get_entity(Track) if not status: return res diff --git a/supysonic/api/browse.py b/supysonic/api/browse.py index 354d42e..6049816 100644 --- a/supysonic/api/browse.py +++ b/supysonic/api/browse.py @@ -108,7 +108,7 @@ def list_indexes(): @api.route('/getMusicDirectory.view', methods = [ 'GET', 'POST' ]) @db_session def show_directory(): - status, res = get_entity(request, Folder) + status, res = get_entity(Folder) if not status: return res @@ -151,7 +151,7 @@ def list_artists(): @api.route('/getArtist.view', methods = [ 'GET', 'POST' ]) @db_session def artist_info(): - status, res = get_entity(request, Artist) + status, res = get_entity(Artist) if not status: return res @@ -165,7 +165,7 @@ def artist_info(): @api.route('/getAlbum.view', methods = [ 'GET', 'POST' ]) @db_session def album_info(): - status, res = get_entity(request, Album) + status, res = get_entity(Album) if not status: return res @@ -177,7 +177,7 @@ def album_info(): @api.route('/getSong.view', methods = [ 'GET', 'POST' ]) @db_session def track_info(): - status, res = get_entity(request, Track) + status, res = get_entity(Track) if not status: return res diff --git a/supysonic/api/media.py b/supysonic/api/media.py index 72c5284..2f05f29 100644 --- a/supysonic/api/media.py +++ b/supysonic/api/media.py @@ -49,7 +49,7 @@ def prepare_transcoding_cmdline(base_cmdline, input_file, input_format, output_f @api.route('/stream.view', methods = [ 'GET', 'POST' ]) @db_session def stream_media(): - status, res = get_entity(request, Track) + status, res = get_entity(Track) if not status: return res @@ -136,7 +136,7 @@ def stream_media(): @api.route('/download.view', methods = [ 'GET', 'POST' ]) def download_media(): with db_session: - status, res = get_entity(request, Track) + status, res = get_entity(Track) if not status: return res @@ -145,7 +145,7 @@ def download_media(): @api.route('/getCoverArt.view', methods = [ 'GET', 'POST' ]) def cover_art(): with db_session: - status, res = get_entity(request, Folder) + status, res = get_entity(Folder) if not status: return res diff --git a/supysonic/api/playlists.py b/supysonic/api/playlists.py index a3ed19b..91da1d7 100644 --- a/supysonic/api/playlists.py +++ b/supysonic/api/playlists.py @@ -51,7 +51,7 @@ def list_playlists(): @api.route('/getPlaylist.view', methods = [ 'GET', 'POST' ]) @db_session def show_playlist(): - status, res = get_entity(request, Playlist) + status, res = get_entity(Playlist) if not status: return res @@ -107,7 +107,7 @@ def create_playlist(): @api.route('/deletePlaylist.view', methods = [ 'GET', 'POST' ]) @db_session def delete_playlist(): - status, res = get_entity(request, Playlist) + status, res = get_entity(Playlist) if not status: return res @@ -120,7 +120,7 @@ def delete_playlist(): @api.route('/updatePlaylist.view', methods = [ 'GET', 'POST' ]) @db_session def update_playlist(): - status, res = get_entity(request, Playlist, 'playlistId') + status, res = get_entity(Playlist, 'playlistId') if not status: return res