From 8275966db045b67ab815bf82d0d710c89e9aa823 Mon Sep 17 00:00:00 2001 From: spl0k Date: Sun, 21 Jan 2018 22:02:32 +0100 Subject: [PATCH] Dropped simplejson dependency Ref #79 --- README.md | 1 - requirements.txt | 1 - supysonic/api/__init__.py | 7 +++---- tests/api/test_api_setup.py | 8 ++++---- tests/api/test_response_helper.py | 6 +++--- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 64bff06..b04a073 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,6 @@ You'll need these to run Supysonic: * [Flask](http://flask.pocoo.org/) >= 0.9 * [PonyORM](https://ponyorm.com/) * [Python Imaging Library](https://github.com/python-pillow/Pillow) -* [simplejson](https://simplejson.readthedocs.io/en/latest/) * [requests](http://docs.python-requests.org/) * [mutagen](https://mutagen.readthedocs.io/en/latest/) * [watchdog](https://github.com/gorakhargosh/watchdog) diff --git a/requirements.txt b/requirements.txt index d048741..df2c04e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ flask>=0.9 pony Pillow -simplejson requests>=1.0.0 mutagen watchdog diff --git a/supysonic/api/__init__.py b/supysonic/api/__init__.py index d0104ad..d7f5abe 100644 --- a/supysonic/api/__init__.py +++ b/supysonic/api/__init__.py @@ -19,10 +19,9 @@ # along with this program. If not, see . import binascii -import simplejson import uuid -from flask import request, current_app as app +from flask import request, json, current_app as app from pony.orm import db_session, ObjectNotFound from xml.dom import minidom from xml.etree import ElementTree @@ -163,11 +162,11 @@ class ResponseHelper: status = 'failed' if error else 'ok', version = version ) - return simplejson.dumps({ 'subsonic-response': ret }, indent = True, encoding = 'utf-8') + return json.dumps({ 'subsonic-response': ret }, indent = True) @staticmethod def responsize_jsonp(ret, callback, error = False, version = "1.8.0"): - return "%s(%s)" % (callback, ResponseHelper.responsize_json(ret, error, version)) + return '{}({})'.format(callback, ResponseHelper.responsize_json(ret, error, version)) @staticmethod def responsize_xml(ret, error = False, version = "1.8.0"): diff --git a/tests/api/test_api_setup.py b/tests/api/test_api_setup.py index c68f342..989c1c7 100644 --- a/tests/api/test_api_setup.py +++ b/tests/api/test_api_setup.py @@ -11,7 +11,7 @@ # Distributed under terms of the GNU AGPLv3 license. import base64 -import simplejson +import flask.json from xml.etree import ElementTree @@ -104,7 +104,7 @@ class ApiSetupTestCase(TestBase): rv = self.client.get('/rest/getLicense.view', query_string = args) self.assertEqual(rv.status_code, 200) self.assertEqual(rv.mimetype, 'application/json') - json = simplejson.loads(rv.data) + json = flask.json.loads(rv.data) self.assertIn('subsonic-response', json) self.assertEqual(json['subsonic-response']['status'], 'ok') self.assertIn('license', json['subsonic-response']) @@ -112,7 +112,7 @@ class ApiSetupTestCase(TestBase): args.update({ 'f': 'jsonp' }) rv = self.client.get('/rest/getLicense.view', query_string = args) self.assertEqual(rv.mimetype, 'application/javascript') - json = simplejson.loads(rv.data) + json = flask.json.loads(rv.data) self.assertIn('subsonic-response', json) self.assertEqual(json['subsonic-response']['status'], 'failed') self.assertEqual(json['subsonic-response']['error']['code'], 10) @@ -123,7 +123,7 @@ class ApiSetupTestCase(TestBase): self.assertEqual(rv.mimetype, 'application/javascript') self.assertTrue(rv.data.startswith('dummy_cb({')) self.assertTrue(rv.data.endswith('})')) - json = simplejson.loads(rv.data[9:-1]) + json = flask.json.loads(rv.data[9:-1]) self.assertIn('subsonic-response', json) self.assertEqual(json['subsonic-response']['status'], 'ok') self.assertIn('license', json['subsonic-response']) diff --git a/tests/api/test_response_helper.py b/tests/api/test_response_helper.py index 4cee2ba..68f6dc5 100644 --- a/tests/api/test_response_helper.py +++ b/tests/api/test_response_helper.py @@ -10,8 +10,8 @@ # Distributed under terms of the GNU AGPLv3 license. import unittest +import flask.json -import simplejson from xml.etree import ElementTree from supysonic.py23 import strtype @@ -31,7 +31,7 @@ class ResponseHelperJsonTestCase(ResponseHelperBaseCase): raise TypeError('Invalid tested value, expecting a dict') json = self.helper.responsize_json(d, error) - return simplejson.loads(json) + return flask.json.loads(json) def process_and_extract(self, d, error = False): # Basically returns d with additional version and status @@ -123,7 +123,7 @@ class ResponseHelperJsonpTestCase(ResponseHelperBaseCase): self.assertTrue(result.startswith('callback({')) self.assertTrue(result.endswith('})')) - json = simplejson.loads(result[9:-1]) + json = flask.json.loads(result[9:-1]) self.assertIn('subsonic-response', json) class ResponseHelperXMLTestCase(ResponseHelperBaseCase):