Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several deprecation warnings #3197

Merged
merged 4 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions beets/dbcore/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@
import threading
import sqlite3
import contextlib
import collections

import beets
from beets.util.functemplate import Template
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):
Expand All @@ -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
Expand Down
20 changes: 12 additions & 8 deletions beets/util/confit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
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'
Expand Down Expand Up @@ -1165,7 +1169,7 @@ def convert(self, value, view):
view
)

if isinstance(self.choices, collections.Mapping):
if isinstance(self.choices, Mapping):
return self.choices[value]
else:
return value
Expand Down Expand Up @@ -1306,11 +1310,11 @@ def _convert_value(self, x, view):
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
Expand Down Expand Up @@ -1367,7 +1371,7 @@ def __repr__(self):
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.'
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion beetsplug/discogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def get_album_info(self, result):
# 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])
Expand Down
2 changes: 1 addition & 1 deletion beetsplug/lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) # <br> eats up surrounding '\n'.
html = re.sub(r'<(script).*?</\1>(?s)', '', html) # Strip script tags.
html = re.sub(r'(?s)<(script).*?</\1>', '', html) # Strip script tags.

if plain_text_out: # Strip remaining HTML tags
html = COMMENT_RE.sub('', html)
Expand Down
7 changes: 6 additions & 1 deletion beetsplug/metasync/itunes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import tempfile
import plistlib

import six
from six.moves.urllib.parse import urlparse, unquote
from time import mktime

Expand Down Expand Up @@ -84,7 +85,11 @@ def __init__(self, config, log):
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:
Expand Down