1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 17:06:17 +00:00

Dropped simplejson dependency

Ref #79
This commit is contained in:
spl0k 2018-01-21 22:02:32 +01:00
parent c6992a4726
commit 8275966db0
5 changed files with 10 additions and 13 deletions

View File

@ -53,7 +53,6 @@ You'll need these to run Supysonic:
* [Flask](http://flask.pocoo.org/) >= 0.9 * [Flask](http://flask.pocoo.org/) >= 0.9
* [PonyORM](https://ponyorm.com/) * [PonyORM](https://ponyorm.com/)
* [Python Imaging Library](https://github.com/python-pillow/Pillow) * [Python Imaging Library](https://github.com/python-pillow/Pillow)
* [simplejson](https://simplejson.readthedocs.io/en/latest/)
* [requests](http://docs.python-requests.org/) * [requests](http://docs.python-requests.org/)
* [mutagen](https://mutagen.readthedocs.io/en/latest/) * [mutagen](https://mutagen.readthedocs.io/en/latest/)
* [watchdog](https://github.com/gorakhargosh/watchdog) * [watchdog](https://github.com/gorakhargosh/watchdog)

View File

@ -1,7 +1,6 @@
flask>=0.9 flask>=0.9
pony pony
Pillow Pillow
simplejson
requests>=1.0.0 requests>=1.0.0
mutagen mutagen
watchdog watchdog

View File

@ -19,10 +19,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import binascii import binascii
import simplejson
import uuid 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 pony.orm import db_session, ObjectNotFound
from xml.dom import minidom from xml.dom import minidom
from xml.etree import ElementTree from xml.etree import ElementTree
@ -163,11 +162,11 @@ class ResponseHelper:
status = 'failed' if error else 'ok', status = 'failed' if error else 'ok',
version = version version = version
) )
return simplejson.dumps({ 'subsonic-response': ret }, indent = True, encoding = 'utf-8') return json.dumps({ 'subsonic-response': ret }, indent = True)
@staticmethod @staticmethod
def responsize_jsonp(ret, callback, error = False, version = "1.8.0"): 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 @staticmethod
def responsize_xml(ret, error = False, version = "1.8.0"): def responsize_xml(ret, error = False, version = "1.8.0"):

View File

@ -11,7 +11,7 @@
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
import base64 import base64
import simplejson import flask.json
from xml.etree import ElementTree from xml.etree import ElementTree
@ -104,7 +104,7 @@ class ApiSetupTestCase(TestBase):
rv = self.client.get('/rest/getLicense.view', query_string = args) rv = self.client.get('/rest/getLicense.view', query_string = args)
self.assertEqual(rv.status_code, 200) self.assertEqual(rv.status_code, 200)
self.assertEqual(rv.mimetype, 'application/json') self.assertEqual(rv.mimetype, 'application/json')
json = simplejson.loads(rv.data) json = flask.json.loads(rv.data)
self.assertIn('subsonic-response', json) self.assertIn('subsonic-response', json)
self.assertEqual(json['subsonic-response']['status'], 'ok') self.assertEqual(json['subsonic-response']['status'], 'ok')
self.assertIn('license', json['subsonic-response']) self.assertIn('license', json['subsonic-response'])
@ -112,7 +112,7 @@ class ApiSetupTestCase(TestBase):
args.update({ 'f': 'jsonp' }) args.update({ 'f': 'jsonp' })
rv = self.client.get('/rest/getLicense.view', query_string = args) rv = self.client.get('/rest/getLicense.view', query_string = args)
self.assertEqual(rv.mimetype, 'application/javascript') self.assertEqual(rv.mimetype, 'application/javascript')
json = simplejson.loads(rv.data) json = flask.json.loads(rv.data)
self.assertIn('subsonic-response', json) self.assertIn('subsonic-response', json)
self.assertEqual(json['subsonic-response']['status'], 'failed') self.assertEqual(json['subsonic-response']['status'], 'failed')
self.assertEqual(json['subsonic-response']['error']['code'], 10) self.assertEqual(json['subsonic-response']['error']['code'], 10)
@ -123,7 +123,7 @@ class ApiSetupTestCase(TestBase):
self.assertEqual(rv.mimetype, 'application/javascript') self.assertEqual(rv.mimetype, 'application/javascript')
self.assertTrue(rv.data.startswith('dummy_cb({')) self.assertTrue(rv.data.startswith('dummy_cb({'))
self.assertTrue(rv.data.endswith('})')) 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.assertIn('subsonic-response', json)
self.assertEqual(json['subsonic-response']['status'], 'ok') self.assertEqual(json['subsonic-response']['status'], 'ok')
self.assertIn('license', json['subsonic-response']) self.assertIn('license', json['subsonic-response'])

View File

@ -10,8 +10,8 @@
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
import unittest import unittest
import flask.json
import simplejson
from xml.etree import ElementTree from xml.etree import ElementTree
from supysonic.py23 import strtype from supysonic.py23 import strtype
@ -31,7 +31,7 @@ class ResponseHelperJsonTestCase(ResponseHelperBaseCase):
raise TypeError('Invalid tested value, expecting a dict') raise TypeError('Invalid tested value, expecting a dict')
json = self.helper.responsize_json(d, error) json = self.helper.responsize_json(d, error)
return simplejson.loads(json) return flask.json.loads(json)
def process_and_extract(self, d, error = False): def process_and_extract(self, d, error = False):
# Basically returns d with additional version and status # Basically returns d with additional version and status
@ -123,7 +123,7 @@ class ResponseHelperJsonpTestCase(ResponseHelperBaseCase):
self.assertTrue(result.startswith('callback({')) self.assertTrue(result.startswith('callback({'))
self.assertTrue(result.endswith('})')) self.assertTrue(result.endswith('})'))
json = simplejson.loads(result[9:-1]) json = flask.json.loads(result[9:-1])
self.assertIn('subsonic-response', json) self.assertIn('subsonic-response', json)
class ResponseHelperXMLTestCase(ResponseHelperBaseCase): class ResponseHelperXMLTestCase(ResponseHelperBaseCase):