From ca60555ffa4af0382269ed2c3fb0c68a8e519b19 Mon Sep 17 00:00:00 2001 From: Carl Suster Date: Sun, 31 Mar 2019 19:24:21 +1100 Subject: [PATCH 1/4] Fix deprecated call log.warn -> log.warning https://bugs.python.org/issue13235 --- beetsplug/discogs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index d7797e409..5a2bf57e0 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -284,7 +284,7 @@ class DiscogsPlugin(BeetsPlugin): # https://www.discogs.com/help/doc/submission-guidelines-general-rules if not all([result.data.get(k) for k in ['artists', 'title', 'id', 'tracklist']]): - self._log.warn(u"Release does not contain the required fields") + self._log.warning(u"Release does not contain the required fields") return None artist, artist_id = self.get_artist([a.data for a in result.artists]) From 3997141250ce310ea64127692295e14f797757b2 Mon Sep 17 00:00:00 2001 From: Carl Suster Date: Sun, 31 Mar 2019 19:36:33 +1100 Subject: [PATCH 2/4] Fix deprecated imports from collections for Py3 Since Python 3.3 the abstract base classes from `collections` are moved to the `collections.abc` module. From Python 3.8 they will be unavailable from their original location. https://docs.python.org/3/library/collections.abc.html --- beets/dbcore/db.py | 7 +++++-- beets/util/confit.py | 20 ++++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/beets/dbcore/db.py b/beets/dbcore/db.py index 24c20ef1a..b0c29e84c 100755 --- a/beets/dbcore/db.py +++ b/beets/dbcore/db.py @@ -23,7 +23,6 @@ from collections import defaultdict import threading import sqlite3 import contextlib -import collections import beets from beets.util.functemplate import Template @@ -31,6 +30,10 @@ from beets.util import py3_path from beets.dbcore import types from .query import MatchQuery, NullSort, TrueQuery import six +if six.PY2: + from collections import Mapping +else: + from collections.abc import Mapping class DBAccessError(Exception): @@ -42,7 +45,7 @@ class DBAccessError(Exception): """ -class FormattedMapping(collections.Mapping): +class FormattedMapping(Mapping): """A `dict`-like formatted view of a model. The accessor `mapping[key]` returns the formatted version of diff --git a/beets/util/confit.py b/beets/util/confit.py index 5f4d862ea..a5e522552 100644 --- a/beets/util/confit.py +++ b/beets/util/confit.py @@ -22,9 +22,13 @@ import os import pkgutil import sys import yaml -import collections import re +import six from collections import OrderedDict +if six.PY2: + from collections import Mapping, Sequence +else: + from collections.abc import Mapping, Sequence UNIX_DIR_VAR = 'XDG_CONFIG_HOME' UNIX_DIR_FALLBACK = '~/.config' @@ -1165,7 +1169,7 @@ class Choice(Template): view ) - if isinstance(self.choices, collections.Mapping): + if isinstance(self.choices, Mapping): return self.choices[value] else: return value @@ -1306,11 +1310,11 @@ class Pairs(StrSeq): return (super(Pairs, self)._convert_value(x, view), self.default_value) except ConfigTypeError: - if isinstance(x, collections.Mapping): + if isinstance(x, Mapping): if len(x) != 1: self.fail(u'must be a single-element mapping', view, True) k, v = iter_first(x.items()) - elif isinstance(x, collections.Sequence): + elif isinstance(x, Sequence): if len(x) != 2: self.fail(u'must be a two-element list', view, True) k, v = x @@ -1367,7 +1371,7 @@ class Filename(Template): return 'Filename({0})'.format(', '.join(args)) def resolve_relative_to(self, view, template): - if not isinstance(template, (collections.Mapping, MappingTemplate)): + if not isinstance(template, (Mapping, MappingTemplate)): # disallow config.get(Filename(relative_to='foo')) raise ConfigTemplateError( u'relative_to may only be used when getting multiple values.' @@ -1486,7 +1490,7 @@ def as_template(value): if isinstance(value, Template): # If it's already a Template, pass it through. return value - elif isinstance(value, collections.Mapping): + elif isinstance(value, Mapping): # Dictionaries work as templates. return MappingTemplate(value) elif value is int: @@ -1507,9 +1511,9 @@ def as_template(value): elif value is None: return Template() elif value is dict: - return TypeTemplate(collections.Mapping) + return TypeTemplate(Mapping) elif value is list: - return TypeTemplate(collections.Sequence) + return TypeTemplate(Sequence) elif isinstance(value, type): return TypeTemplate(value) else: From e4c03fd63f9c351b45234f978a9e5bbb524c8920 Mon Sep 17 00:00:00 2001 From: Carl Suster Date: Sun, 31 Mar 2019 19:44:00 +1100 Subject: [PATCH 3/4] Fix deprecated placement of inline regex flags https://bugs.python.org/issue22493 --- beetsplug/lyrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index 6ecdbd1d0..9e44eeef6 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -446,7 +446,7 @@ def _scrape_strip_cruft(html, plain_text_out=False): html = html.replace('\r', '\n') # Normalize EOL. html = re.sub(r' +', ' ', html) # Whitespaces collapse. html = BREAK_RE.sub('\n', html) #
eats up surrounding '\n'. - html = re.sub(r'<(script).*?(?s)', '', html) # Strip script tags. + html = re.sub(r'(?s)<(script).*?', '', html) # Strip script tags. if plain_text_out: # Strip remaining HTML tags html = COMMENT_RE.sub('', html) From a6305c36e111ffb4a3dcc17ee0f4baf7ab28be8d Mon Sep 17 00:00:00 2001 From: Carl Suster Date: Sun, 31 Mar 2019 19:53:17 +1100 Subject: [PATCH 4/4] Fix deprecated plistlib function https://docs.python.org/3.7/library/plistlib.html#plistlib.readPlist --- beetsplug/metasync/itunes.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/beetsplug/metasync/itunes.py b/beetsplug/metasync/itunes.py index 17ab1637f..d594fa591 100644 --- a/beetsplug/metasync/itunes.py +++ b/beetsplug/metasync/itunes.py @@ -24,6 +24,7 @@ import shutil import tempfile import plistlib +import six from six.moves.urllib.parse import urlparse, unquote from time import mktime @@ -84,7 +85,11 @@ class Itunes(MetaSource): self._log.debug( u'loading iTunes library from {0}'.format(library_path)) with create_temporary_copy(library_path) as library_copy: - raw_library = plistlib.readPlist(library_copy) + if six.PY2: + raw_library = plistlib.readPlist(library_copy) + else: + with open(library_copy, 'rb') as library_copy_f: + raw_library = plistlib.load(library_copy_f) except IOError as e: raise ConfigValueError(u'invalid iTunes library: ' + e.strerror) except Exception: