1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-09 11:42:16 +00:00

pyupgrade

This commit is contained in:
Alban Féron 2020-11-22 16:12:14 +01:00
parent d6f1a11aca
commit 81d141e540
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
81 changed files with 110 additions and 205 deletions

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
@ -9,10 +8,15 @@
# Distributed under terms of the GNU AGPLv3 license.
from supysonic.web import create_application
app = create_application()
if __name__ == '__main__':
if __name__ == "__main__":
if app:
import sys
app.run(host = sys.argv[1] if len(sys.argv) > 1 else None, port = int(sys.argv[2]) if len(sys.argv) > 2 else 5000, debug = True)
app.run(
host=sys.argv[1] if len(sys.argv) > 1 else None,
port=int(sys.argv[2]) if len(sys.argv) > 2 else 5000,
debug=True,
)

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
@ -25,7 +23,7 @@ from .exceptions import AggregateException, GenericError, MissingParameter, NotF
def star_single(cls, eid):
""" Stars an entity
"""Stars an entity
:param cls: entity class, Folder, Artist, Album or Track
:param eid: id of the entity to star
@ -47,7 +45,7 @@ def star_single(cls, eid):
def unstar_single(cls, eid):
""" Unstars an entity
"""Unstars an entity
:param cls: entity class, Folder, Artist, Album or Track
:param eid: id of the entity to unstar

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
@ -30,7 +28,7 @@ class GenericError(SubsonicAPIException):
api_code = 0
def __init__(self, message, *args, **kwargs):
super(GenericError, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.message = message
@ -41,14 +39,14 @@ class ServerError(GenericError):
class UnsupportedParameter(GenericError):
def __init__(self, parameter, *args, **kwargs):
message = "Unsupported parameter '{}'".format(parameter)
super(UnsupportedParameter, self).__init__(message, *args, **kwargs)
super().__init__(message, *args, **kwargs)
class MissingParameter(SubsonicAPIException):
api_code = 10
def __init__(self, *args, **kwargs):
super(MissingParameter, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.message = "A required parameter is missing."
@ -90,13 +88,13 @@ class NotFound(SubsonicAPIException):
api_code = 70
def __init__(self, entity, *args, **kwargs):
super(NotFound, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.message = "{} not found".format(entity)
class AggregateException(SubsonicAPIException):
def __init__(self, exceptions, *args, **kwargs):
super(AggregateException, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.exceptions = []
for exc in exceptions:
@ -114,7 +112,7 @@ class AggregateException(SubsonicAPIException):
if len(self.exceptions) == 1:
return self.exceptions[0].get_response()
codes = set(exc.api_code for exc in self.exceptions)
codes = {exc.api_code for exc in self.exceptions}
errors = [
dict(code=exc.api_code, message=exc.message) for exc in self.exceptions
]

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
@ -13,7 +11,7 @@ from xml.etree import ElementTree
from . import API_VERSION
class BaseFormatter(object):
class BaseFormatter:
def make_response(self, elem, data):
raise NotImplementedError()

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
@ -332,7 +330,7 @@ def lyrics():
logger.debug("Found lyrics file: " + lyrics_path)
try:
with open(lyrics_path, "rt") as f:
with open(lyrics_path) as f:
lyrics = f.read()
except UnicodeError:
# Lyrics file couldn't be decoded. Rather than displaying an error, try with the potential next files or

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -86,7 +86,14 @@ def old_search():
@api.route("/search2.view", methods=["GET", "POST"])
def new_search():
query = request.values["query"]
artist_count, artist_offset, album_count, album_offset, song_count, song_offset = map(
(
artist_count,
artist_offset,
album_count,
album_offset,
song_count,
song_offset,
) = map(
request.values.get,
[
"artistCount",
@ -131,7 +138,14 @@ def new_search():
@api.route("/search3.view", methods=["GET", "POST"])
def search_id3():
query = request.values["query"]
artist_count, artist_offset, album_count, album_offset, song_count, song_offset = map(
(
artist_count,
artist_offset,
album_count,
album_offset,
song_count,
song_offset,
) = map(
request.values.get,
[
"artistCount",

View File

@ -1,4 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
@ -38,7 +36,7 @@ CacheEntry = namedtuple("CacheEntry", ["size", "expires"])
NULL_ENTRY = CacheEntry(0, 0)
class Cache(object):
class Cache:
"""Provides a common interface for caching files to disk"""
# Modeled after werkzeug.contrib.cache.FileSystemCache

View File

@ -33,7 +33,7 @@ class TimedProgressDisplay:
def __call__(self, name, scanned):
if time.time() - self.__last_display > self.__interval:
progress = "Scanning '{0}': {1} files scanned".format(name, scanned)
progress = "Scanning '{}': {} files scanned".format(name, scanned)
self.__stdout.write("\b" * self.__last_len)
self.__stdout.write(progress)
self.__stdout.flush()
@ -188,7 +188,7 @@ class SupysonicCLI(cmd.Cmd):
self.write_line("Name\t\tPath\n----\t\t----")
self.write_line(
"\n".join(
"{0: <16}{1}".format(f.name, f.path)
"{: <16}{}".format(f.name, f.path)
for f in Folder.select(lambda f: f.root)
)
)
@ -354,7 +354,7 @@ class SupysonicCLI(cmd.Cmd):
self.write_line("----\t\t-----\t-------\t-----")
self.write_line(
"\n".join(
"{0: <16}{1}\t{2}\t{3}".format(
"{: <16}{}\t{}\t{}".format(
u.name, "*" if u.admin else "", "*" if u.jukebox else "", u.mail
)
for u in User.select()
@ -393,16 +393,16 @@ class SupysonicCLI(cmd.Cmd):
else:
if admin:
user.admin = True
self.write_line("Granted '{0}' admin rights".format(name))
self.write_line("Granted '{}' admin rights".format(name))
elif noadmin:
user.admin = False
self.write_line("Revoked '{0}' admin rights".format(name))
self.write_line("Revoked '{}' admin rights".format(name))
if jukebox:
user.jukebox = True
self.write_line("Granted '{0}' jukebox rights".format(name))
self.write_line("Granted '{}' jukebox rights".format(name))
elif nojukebox:
user.jukebox = False
self.write_line("Revoked '{0}' jukebox rights".format(name))
self.write_line("Revoked '{}' jukebox rights".format(name))
@db_session
def user_changepass(self, name, password):

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
@ -21,7 +19,7 @@ def get_current_config():
return current_config or DefaultConfig()
class DefaultConfig(object):
class DefaultConfig:
DEBUG = False
tempdir = os.path.join(tempfile.gettempdir(), "supysonic")
@ -67,7 +65,7 @@ class IniConfig(DefaultConfig):
]
def __init__(self, paths):
super(IniConfig, self).__init__()
super().__init__()
parser = RawConfigParser()
parser.read(paths)

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
@ -27,7 +25,7 @@ NAMING_SCORE_RULES = (
)
class CoverFile(object):
class CoverFile:
__clean_regex = re.compile(r"[^a-z]")
@staticmethod
@ -63,7 +61,7 @@ def is_valid_cover(path):
warnings.simplefilter("ignore")
with Image.open(path):
return True
except IOError:
except OSError:
return False

View File

@ -1,5 +1,3 @@
# coding: utf-8
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
@ -16,7 +14,7 @@ from ..utils import get_secret_key
__all__ = ["DaemonClient"]
class DaemonCommand(object):
class DaemonCommand:
def apply(self, connection, daemon):
raise NotImplementedError()
@ -102,7 +100,7 @@ class JukeboxCommand(DaemonCommand):
connection.send(rv)
class DaemonCommandResult(object):
class DaemonCommandResult:
pass
@ -128,7 +126,7 @@ class JukeboxResult(DaemonCommandResult):
self.playlist = ()
class DaemonClient(object):
class DaemonClient:
def __init__(self, address=None):
self.__address = address or get_current_config().DAEMON["socket"]
self.__key = get_secret_key("daemon_key")
@ -138,7 +136,7 @@ class DaemonClient(object):
raise DaemonUnavailableError("No daemon address set")
try:
return Client(address=self.__address, authkey=self.__key)
except IOError:
except OSError:
raise DaemonUnavailableError(
"Couldn't connect to daemon at {}".format(self.__address)
)

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
@ -26,7 +24,7 @@ __all__ = ["Daemon"]
logger = logging.getLogger(__name__)
class Daemon(object):
class Daemon:
def __init__(self, config):
self.__config = config
self.__listener = None

View File

@ -46,7 +46,7 @@ def sqlite_case_insensitive_like(db, connection):
cursor.execute("PRAGMA case_sensitive_like = OFF")
class PathMixin(object):
class PathMixin:
@classmethod
def get(cls, *args, **kwargs):
if kwargs:
@ -529,7 +529,7 @@ class Playlist(db.Entity):
id=str(self.id),
name=self.name
if self.user.id == user.id
else "[%s] %s" % (self.user.name, self.name),
else "[{}] {}".format(self.user.name, self.name),
owner=self.user.name,
public=self.public,
songCount=len(tracks),

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
@ -22,7 +20,7 @@ from .db import Track
logger = logging.getLogger(__name__)
class Jukebox(object):
class Jukebox:
def __init__(self, cmd):
self.__cmd = shlex.split(cmd)
self.__playlist = []

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
@ -26,14 +24,14 @@ from .db import RatingFolder, RatingTrack
logger = logging.getLogger(__name__)
class StatsDetails(object):
class StatsDetails:
def __init__(self):
self.artists = 0
self.albums = 0
self.tracks = 0
class Stats(object):
class Stats:
def __init__(self):
self.scanned = 0
self.added = StatsDetails()
@ -66,7 +64,7 @@ class Scanner(Thread):
on_folder_end=None,
on_done=None,
):
super(Scanner, self).__init__()
super().__init__()
if extensions is not None and not isinstance(extensions, list):
raise TypeError("Invalid extensions type")

View File

@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
@ -45,10 +42,10 @@ def process_table(connection, table, fields, nullable_fields=()):
sql = "UPDATE {0} SET {1}=%s WHERE {1}=%s".format(table, field)
c.executemany(sql, map(lambda v: (UUID(v).bytes, v), values))
for field in fields:
sql = "ALTER TABLE {0} MODIFY {1} BINARY(16) NOT NULL".format(table, field)
sql = "ALTER TABLE {} MODIFY {} BINARY(16) NOT NULL".format(table, field)
c.execute(sql)
for field in nullable_fields:
sql = "ALTER TABLE {0} MODIFY {1} BINARY(16)".format(table, field)
sql = "ALTER TABLE {} MODIFY {} BINARY(16)".format(table, field)
c.execute(sql)
connection.commit()

View File

@ -20,17 +20,17 @@ def process_table(connection, table):
c = connection.cursor()
c.execute(
r"ALTER TABLE {0} ADD COLUMN path_hash BYTEA NOT NULL DEFAULT E'\\0000'".format(
r"ALTER TABLE {} ADD COLUMN path_hash BYTEA NOT NULL DEFAULT E'\\0000'".format(
table
)
)
hashes = dict()
c.execute("SELECT path FROM {0}".format(table))
c.execute("SELECT path FROM {}".format(table))
for row in c.fetchall():
hashes[row[0]] = hashlib.sha1(row[0].encode("utf-8")).digest()
c.executemany(
"UPDATE {0} SET path_hash=%s WHERE path=%s".format(table),
"UPDATE {} SET path_hash=%s WHERE path=%s".format(table),
[(bytes(h), p) for p, h in hashes.items()],
)

View File

@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -17,14 +17,14 @@ def process_table(connection, table):
c = connection.cursor()
c.execute(
"ALTER TABLE {0} ADD COLUMN path_hash BLOB NOT NULL DEFAULT ROWID".format(table)
"ALTER TABLE {} ADD COLUMN path_hash BLOB NOT NULL DEFAULT ROWID".format(table)
)
hashes = dict()
for row in c.execute("SELECT path FROM {0}".format(table)):
for row in c.execute("SELECT path FROM {}".format(table)):
hashes[row[0]] = hashlib.sha1(row[0].encode("utf-8")).digest()
c.executemany(
"UPDATE {0} SET path_hash=? WHERE path=?".format(table),
"UPDATE {} SET path_hash=? WHERE path=?".format(table),
[(bytes(h), p) for p, h in hashes.items()],
)

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
@ -36,13 +34,11 @@ class SupysonicWatcherEventHandler(PatternMatchingEventHandler):
patterns = list(map(lambda e: "*." + e.lower(), extensions.split())) + list(
map(lambda e: "*" + e, covers.EXTENSIONS)
)
super(SupysonicWatcherEventHandler, self).__init__(
patterns=patterns, ignore_directories=True
)
super().__init__(patterns=patterns, ignore_directories=True)
def dispatch(self, event):
try:
super(SupysonicWatcherEventHandler, self).dispatch(event)
super().dispatch(event)
except Exception as e: # pragma: nocover
logger.critical(e)
@ -85,7 +81,7 @@ class SupysonicWatcherEventHandler(PatternMatchingEventHandler):
self.queue.put(event.dest_path, op, src_path=event.src_path)
class Event(object):
class Event:
def __init__(self, path, operation, **kwargs):
if operation & (OP_SCAN | OP_REMOVE) == (OP_SCAN | OP_REMOVE):
raise Exception("Flags SCAN and REMOVE both set") # pragma: nocover
@ -131,7 +127,7 @@ class Event(object):
class ScannerProcessingQueue(Thread):
def __init__(self, delay):
super(ScannerProcessingQueue, self).__init__()
super().__init__()
self.__timeout = delay
self.__cond = Condition()
@ -254,7 +250,7 @@ class ScannerProcessingQueue(Thread):
return None
class SupysonicWatcher(object):
class SupysonicWatcher:
def __init__(self, config):
self.__delay = config.DAEMON["wait_delay"]
self.__handler = SupysonicWatcherEventHandler(config.BASE["scanner_extensions"])

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -22,7 +22,7 @@ class ApiTestBase(TestBase):
__with_api__ = True
def setUp(self):
super(ApiTestBase, self).setUp()
super().setUp()
xsd = etree.parse("tests/assets/subsonic-rest-api-1.10.2.xsd")
self.schema = etree.XMLSchema(xsd)

View File

@ -21,7 +21,7 @@ class AlbumSongsTestCase(ApiTestBase):
# Let's just check paramter validation and ensure coverage
def setUp(self):
super(AlbumSongsTestCase, self).setUp()
super().setUp()
with db_session:
folder = Folder(name="Root", root=True, path="tests/assets")

View File

@ -18,7 +18,7 @@ from .apitestbase import ApiTestBase
class AnnotationTestCase(ApiTestBase):
def setUp(self):
super(AnnotationTestCase, self).setUp()
super().setUp()
with db_session:
root = Folder(name="Root", root=True, path="tests")

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
@ -22,7 +21,7 @@ class ApiSetupTestCase(TestBase):
__with_api__ = True
def setUp(self):
super(ApiSetupTestCase, self).setUp()
super().setUp()
self._patch_client()
def __basic_auth_get(self, username, password):

View File

@ -20,7 +20,7 @@ from .apitestbase import ApiTestBase
class BrowseTestCase(ApiTestBase):
def setUp(self):
super(BrowseTestCase, self).setUp()
super().setUp()
with db_session:
Folder(root=True, name="Empty root", path="/tmp")

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
@ -21,7 +20,7 @@ from .apitestbase import ApiTestBase
class LyricsTestCase(ApiTestBase):
def setUp(self):
super(LyricsTestCase, self).setUp()
super().setUp()
with db_session:
folder = Folder(

View File

@ -22,7 +22,7 @@ from .apitestbase import ApiTestBase
class MediaTestCase(ApiTestBase):
def setUp(self):
super(MediaTestCase, self).setUp()
super().setUp()
with db_session:
folder = Folder(
@ -61,7 +61,7 @@ class MediaTestCase(ApiTestBase):
artist=artist,
album=album,
path=os.path.abspath(
"tests/assets/formats/silence.{0}".format(self.formats[i])
"tests/assets/formats/silence.{}".format(self.formats[i])
),
root_folder=folder,
folder=folder,

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
@ -19,7 +18,7 @@ from .apitestbase import ApiTestBase
class PlaylistTestCase(ApiTestBase):
def setUp(self):
super(PlaylistTestCase, self).setUp()
super().setUp()
with db_session:
root = Folder(root=True, name="Root folder", path="tests/assets")

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
@ -19,7 +18,7 @@ from .apitestbase import ApiTestBase
class RadioStationTestCase(ApiTestBase):
def setUp(self):
super(RadioStationTestCase, self).setUp()
super().setUp()
@db_session
def assertRadioStationCountEqual(self, count):

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
@ -18,10 +17,10 @@ from supysonic.api.formatters import JSONFormatter, JSONPFormatter, XMLFormatter
from ..testbase import TestBase
class UnwrapperMixin(object):
class UnwrapperMixin:
def make_response(self, elem, data):
with self.request_context():
rv = super(UnwrapperMixin, self).make_response(elem, data)
rv = super().make_response(elem, data)
return rv.get_data(as_text=True)
@staticmethod
@ -34,7 +33,7 @@ class UnwrapperMixin(object):
class ResponseHelperJsonTestCase(TestBase, UnwrapperMixin.create_from(JSONFormatter)):
def make_response(self, elem, data):
rv = super(ResponseHelperJsonTestCase, self).make_response(elem, data)
rv = super().make_response(elem, data)
return flask.json.loads(rv)
def process_and_extract(self, d):
@ -117,7 +116,7 @@ class ResponseHelperJsonpTestCase(TestBase, UnwrapperMixin.create_from(JSONPForm
class ResponseHelperXMLTestCase(TestBase, UnwrapperMixin.create_from(XMLFormatter)):
def make_response(self, elem, data):
xml = super(ResponseHelperXMLTestCase, self).make_response(elem, data)
xml = super().make_response(elem, data)
xml = xml.replace('xmlns="http://subsonic.org/restapi"', "")
root = ElementTree.fromstring(xml)
return root
@ -131,7 +130,7 @@ class ResponseHelperXMLTestCase(TestBase, UnwrapperMixin.create_from(XMLFormatte
self.assertDictEqual(elem.attrib, d)
def test_root(self):
xml = super(ResponseHelperXMLTestCase, self).make_response("tag", {})
xml = super().make_response("tag", {})
self.assertIn("<subsonic-response ", xml)
self.assertIn('xmlns="http://subsonic.org/restapi"', xml)
self.assertTrue(xml.strip().endswith("</subsonic-response>"))

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
@ -20,7 +19,7 @@ from .apitestbase import ApiTestBase
class SearchTestCase(ApiTestBase):
def setUp(self):
super(SearchTestCase, self).setUp()
super().setUp()
with db_session:
root = Folder(root=True, name="Root folder", path="tests/assets")

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.

View File

@ -22,7 +22,7 @@ from .apitestbase import ApiTestBase
class TranscodingTestCase(ApiTestBase):
def setUp(self):
super(TranscodingTestCase, self).setUp()
super().setUp()
with db_session:
folder = FolderManager.add("Folder", "tests/assets/folder")

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
@ -74,8 +73,7 @@ class CacheTestCase(unittest.TestCase):
val = [b"0", b"12", b"345", b"6789"]
def gen():
for b in val:
yield b
yield from val
t = []
for x in cache.set_generated("key", gen):
@ -160,8 +158,7 @@ class CacheTestCase(unittest.TestCase):
def gen():
# Cause a TypeError halfway through
for b in [b"0", b"12", object(), b"345", b"6789"]:
yield b
yield from [b"0", b"12", object(), b"345", b"6789"]
with self.assertRaises(TypeError):
for x in cache.set_generated("key", gen):
@ -174,8 +171,7 @@ class CacheTestCase(unittest.TestCase):
cache = Cache(self.__dir, 20)
def gen():
for b in [b"0", b"12", b"345", b"6789"]:
yield b
yield from [b"0", b"12", b"345", b"6789"]
g1 = cache.set_generated("key", gen)
g2 = cache.set_generated("key", gen)

View File

@ -42,7 +42,7 @@ class CLITestCase(unittest.TestCase):
os.remove(self.__db[1])
def __add_folder(self, name, path):
self.__cli.onecmd("folder add {0} {1}".format(name, shlex.quote(path)))
self.__cli.onecmd("folder add {} {}".format(name, shlex.quote(path)))
def test_folder_add(self):
with tempfile.TemporaryDirectory() as d:

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
@ -21,7 +20,7 @@ class LastFmTestCase(unittest.TestCase):
logging.getLogger("supysonic.lastfm").addHandler(logging.NullHandler())
lastfm = LastFm({"api_key": "key", "secret": "secret"}, None)
rv = lastfm._LastFm__api_request(False, method="dummy", accents=u"àéèùö")
rv = lastfm._LastFm__api_request(False, method="dummy", accents="àéèùö")
self.assertIsInstance(rv, dict)

View File

@ -42,7 +42,7 @@ class ScannerTestCase(unittest.TestCase):
with tempfile.NamedTemporaryFile(
dir=os.path.dirname(track.path), delete=False
) as tf:
with io.open(track.path, "rb") as f:
with open(track.path, "rb") as f:
tf.write(f.read())
try:
yield tf.name

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.

View File

@ -28,7 +28,7 @@ class WatcherTestConfig(TestConfig):
DAEMON = {"wait_delay": 0.5, "log_file": "/dev/null", "log_level": "DEBUG"}
def __init__(self, db_uri):
super(WatcherTestConfig, self).__init__(False, False)
super().__init__(False, False)
self.BASE["database_uri"] = db_uri
@ -64,7 +64,7 @@ class WatcherTestBase(unittest.TestCase):
class WatcherTestCase(WatcherTestBase):
def setUp(self):
super(WatcherTestCase, self).setUp()
super().setUp()
self.__dir = tempfile.mkdtemp()
with db_session:
FolderManager.add("Folder", self.__dir)
@ -73,7 +73,7 @@ class WatcherTestCase(WatcherTestBase):
def tearDown(self):
self._stop()
shutil.rmtree(self.__dir)
super(WatcherTestCase, self).tearDown()
super().tearDown()
@staticmethod
def _tempname():

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
@ -14,7 +12,7 @@ class FrontendTestBase(TestBase):
__with_webui__ = True
def setUp(self):
super(FrontendTestBase, self).setUp()
super().setUp()
self._patch_client()
def _login(self, username, password):

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
@ -19,7 +18,7 @@ from .frontendtestbase import FrontendTestBase
class PlaylistTestCase(FrontendTestBase):
def setUp(self):
super(PlaylistTestCase, self).setUp()
super().setUp()
with db_session:
folder = Folder(name="Root", path="tests/assets", root=True)

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
@ -20,7 +19,7 @@ from .frontendtestbase import FrontendTestBase
class UserTestCase(FrontendTestBase):
def setUp(self):
super(UserTestCase, self).setUp()
super().setUp()
with db_session:
self.users = {u.name: u.id for u in User.select()}

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
@ -21,7 +19,7 @@ from .testbase import TestBase
class Issue129TestCase(TestBase):
def setUp(self):
super(Issue129TestCase, self).setUp()
super().setUp()
with db_session:
folder = FolderManager.add("folder", os.path.abspath("tests/assets/folder"))

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.

View File

@ -71,7 +71,7 @@ class UserManagerTestCase(unittest.TestCase):
("d68c95a91ed7773aa57c7c044d2309a5bf1da2e7", "pepper"),
)
self.assertEqual(
func(u"éèàïô", "ABC+"), ("b639ba5217b89c906019d89d5816b407d8730898", "ABC+")
func("éèàïô", "ABC+"), ("b639ba5217b89c906019d89d5816b407d8730898", "ABC+")
)
@db_session

View File

@ -32,7 +32,7 @@ class TestConfig(DefaultConfig):
}
def __init__(self, with_webui, with_api):
super(TestConfig, self).__init__()
super().__init__()
for cls in reversed(inspect.getmro(self.__class__)):
for attr, value in cls.__dict__.items():
@ -47,7 +47,7 @@ class TestConfig(DefaultConfig):
self.WEBAPP.update({"mount_webui": with_webui, "mount_api": with_api})
class MockResponse(object):
class MockResponse:
def __init__(self, response):
self.__status_code = response.status_code
self.__data = response.get_data(as_text=True)

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#

View File

@ -1,5 +1,3 @@
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#