From 8491c61f0c347b77d224026883a50c578dedda9a Mon Sep 17 00:00:00 2001 From: Til Boerner Date: Wed, 26 Jun 2024 11:49:35 +0200 Subject: [PATCH] Make compatible with Python 3.12 Keep backward compatibility while dealing with removed symbols, see https://docs.python.org/3/whatsnew/3.12.html#removed --- cherrymusicserver/cherrymodel.py | 6 +++++- cherrymusicserver/configuration.py | 3 ++- cherrymusicserver/resultorder.py | 6 +++++- cherrymusicserver/sqlitecache.py | 6 +++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cherrymusicserver/cherrymodel.py b/cherrymusicserver/cherrymodel.py index 079042cf..a312bc1c 100644 --- a/cherrymusicserver/cherrymodel.py +++ b/cherrymusicserver/cherrymodel.py @@ -40,7 +40,11 @@ import json import cherrypy import audiotranscode -from imp import reload + +try: + from imp import reload +except ModuleNotFoundError: + from importlib import reload try: from urllib.parse import quote diff --git a/cherrymusicserver/configuration.py b/cherrymusicserver/configuration.py index 8c4140e4..2927fd48 100644 --- a/cherrymusicserver/configuration.py +++ b/cherrymusicserver/configuration.py @@ -297,8 +297,9 @@ def from_configparser(filepath): except ImportError: from backport.configparser import ConfigParser cfgp = ConfigParser() + read_file = cfgp.read_file if hasattr(cfgp, "read_file") else cfgp.readfp with open(filepath, encoding='utf-8') as fp: - cfgp.readfp(fp) + read_file(fp) dic = OrderedDict() for section_name in cfgp.sections(): if 'DEFAULT' == section_name: diff --git a/cherrymusicserver/resultorder.py b/cherrymusicserver/resultorder.py index 66e956d9..c32c61d4 100644 --- a/cherrymusicserver/resultorder.py +++ b/cherrymusicserver/resultorder.py @@ -33,10 +33,14 @@ fetched from the database by some mystic-voodoo- hocuspocus heuristics""" +try: + from imp import reload +except ModuleNotFoundError: + from importlib import reload + from cherrymusicserver import pathprovider from cherrymusicserver import log import cherrymusicserver.tweak -from imp import reload from cherrymusicserver.util import Performance class ResultOrder: diff --git a/cherrymusicserver/sqlitecache.py b/cherrymusicserver/sqlitecache.py index 0ab2b999..11dd6d60 100644 --- a/cherrymusicserver/sqlitecache.py +++ b/cherrymusicserver/sqlitecache.py @@ -42,6 +42,11 @@ from contextlib import closing from operator import itemgetter +try: + from imp import reload +except ModuleNotFoundError: + from importlib import reload + import cherrymusicserver as cherry from cherrymusicserver import database from cherrymusicserver import log @@ -52,7 +57,6 @@ from cherrymusicserver.util import Performance from cherrymusicserver.progress import ProgressTree, ProgressReporter import cherrymusicserver.tweak -from imp import reload import random from backport import unichr