From 9f8bd4cd3fb1a9d92a270be39d76e77f1a168647 Mon Sep 17 00:00:00 2001 From: Jef LeCompte Date: Mon, 25 May 2020 19:39:40 -0400 Subject: [PATCH] style: flake8 linting --- beetsplug/export.py | 14 +++++++------- beetsplug/lyrics.py | 5 +++-- beetsplug/plexupdate.py | 4 ++-- beetsplug/subsonicplaylist.py | 9 ++++----- beetsplug/thumbnails.py | 2 +- setup.py | 4 ++-- test/test_export.py | 4 ++-- tox.ini | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/beetsplug/export.py b/beetsplug/export.py index 0b4876bbf..8d98d0ba2 100644 --- a/beetsplug/export.py +++ b/beetsplug/export.py @@ -21,7 +21,7 @@ import sys import codecs import json import csv -import xml.etree.ElementTree as et +from xml.etree import ElementTree from datetime import datetime, date from beets.plugins import BeetsPlugin @@ -188,18 +188,18 @@ class XMLFormat(ExportFormat): def export(self, data, **kwargs): # Creates the XML file structure. - library = et.Element(u'library') - tracks = et.SubElement(library, u'tracks') + library = ElementTree.Element(u'library') + tracks = ElementTree.SubElement(library, u'tracks') if data and isinstance(data[0], dict): for index, item in enumerate(data): - track = et.SubElement(tracks, u'track') + track = ElementTree.SubElement(tracks, u'track') for key, value in item.items(): - track_details = et.SubElement(track, key) + track_details = ElementTree.SubElement(track, key) track_details.text = value # Depending on the version of python the encoding needs to change try: - data = et.tostring(library, encoding='unicode', **kwargs) + data = ElementTree.tostring(library, encoding='unicode', **kwargs) except LookupError: - data = et.tostring(library, encoding='utf-8', **kwargs) + data = ElementTree.tostring(library, encoding='utf-8', **kwargs) self.out_stream.write(data) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index f73d72dfd..8807225a9 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -907,7 +907,7 @@ class LyricsPlugin(plugins.BeetsPlugin): return _scrape_strip_cruft(lyrics, True) def append_translation(self, text, to_lang): - import xml.etree.ElementTree as et + from xml.etree import ElementTree if not self.bing_auth_token: self.bing_auth_token = self.get_bing_access_token() @@ -925,7 +925,8 @@ class LyricsPlugin(plugins.BeetsPlugin): self.bing_auth_token = None return self.append_translation(text, to_lang) return text - lines_translated = et.fromstring(r.text.encode('utf-8')).text + lines_translated = ElementTree.fromstring( + r.text.encode('utf-8')).text # Use a translation mapping dict to build resulting lyrics translations = dict(zip(text_lines, lines_translated.split('|'))) result = '' diff --git a/beetsplug/plexupdate.py b/beetsplug/plexupdate.py index d3d7caf5c..ab3396191 100644 --- a/beetsplug/plexupdate.py +++ b/beetsplug/plexupdate.py @@ -12,7 +12,7 @@ Put something like the following in your config.yaml to configure: from __future__ import division, absolute_import, print_function import requests -import xml.etree.ElementTree as et +from xml.etree import ElementTree from six.moves.urllib.parse import urljoin, urlencode from beets import config from beets.plugins import BeetsPlugin @@ -28,7 +28,7 @@ def get_music_section(host, port, token, library_name): r = requests.get(url) # Parse xml tree and extract music section key. - tree = et.fromstring(r.content) + tree = ElementTree.fromstring(r.content) for child in tree.findall('Directory'): if child.get('title') == library_name: return child.get('key') diff --git a/beetsplug/subsonicplaylist.py b/beetsplug/subsonicplaylist.py index a4577278a..732b51c2f 100644 --- a/beetsplug/subsonicplaylist.py +++ b/beetsplug/subsonicplaylist.py @@ -17,7 +17,7 @@ from __future__ import absolute_import, division, print_function import random import string -import xml.etree.ElementTree as et +from xml.etree import ElementTree from hashlib import md5 from urllib.parse import urlencode @@ -85,7 +85,7 @@ class SubsonicPlaylistPlugin(BeetsPlugin): def get_playlist(self, playlist_id): xml = self.send('getPlaylist', {'id': playlist_id}).text - playlist = et.fromstring(xml)[0] + playlist = ElementTree.fromstring(xml)[0] if playlist.attrib.get('code', '200') != '200': alt_error = 'error getting playlist, but no error message found' self._log.warn(playlist.attrib.get('message', alt_error)) @@ -101,9 +101,8 @@ class SubsonicPlaylistPlugin(BeetsPlugin): self.config.set_args(opts) ids = self.config['playlist_ids'].as_str_seq() if self.config['playlist_names'].as_str_seq(): - playlists = et.fromstring( - self.send('getPlaylists').text - )[0] + playlists = ElementTree.fromstring( + self.send('getPlaylists').text)[0] if playlists.attrib.get('code', '200') != '200': alt_error = 'error getting playlists,' \ ' but no error message found' diff --git a/beetsplug/thumbnails.py b/beetsplug/thumbnails.py index 01da5afff..fe36fbd13 100644 --- a/beetsplug/thumbnails.py +++ b/beetsplug/thumbnails.py @@ -25,7 +25,7 @@ from hashlib import md5 import os import shutil from itertools import chain -from pathlib2 import PurePosixPath +from pathlib import PurePosixPath import ctypes import ctypes.util diff --git a/setup.py b/setup.py index 0be671f5d..c50e65bf5 100755 --- a/setup.py +++ b/setup.py @@ -122,7 +122,7 @@ setup( 'requests_oauthlib' ] + ( # Tests for the thumbnails plugin need pathlib on Python 2 too. - ['pathlib2'] if (sys.version_info < (3, 4, 0)) else [] + ['pathlib'] if (sys.version_info < (3, 4, 0)) else [] ), # Plugin (optional) dependencies: @@ -144,7 +144,7 @@ setup( 'web': ['flask', 'flask-cors'], 'import': ['rarfile'], 'thumbnails': ['pyxdg', 'Pillow'] + - (['pathlib2'] if (sys.version_info < (3, 4, 0)) else []), + (['pathlib'] if (sys.version_info < (3, 4, 0)) else []), 'metasync': ['dbus-python'], 'sonosupdate': ['soco'], 'scrub': ['mutagen>=1.33'], diff --git a/test/test_export.py b/test/test_export.py index 18b2b17be..779e74423 100644 --- a/test/test_export.py +++ b/test/test_export.py @@ -23,7 +23,7 @@ from test.helper import TestHelper import re # used to test csv format import json from xml.etree.ElementTree import Element -import xml.etree.ElementTree as et +from xml.etree import ElementTree class ExportPluginTest(unittest.TestCase, TestHelper): @@ -85,7 +85,7 @@ class ExportPluginTest(unittest.TestCase, TestHelper): format_type='xml', artist=item1.artist ) - library = et.fromstring(out) + library = ElementTree.fromstring(out) self.assertIsInstance(library, Element) for track in library[0]: for details in track: diff --git a/tox.ini b/tox.ini index 06f0bda8c..92086b820 100644 --- a/tox.ini +++ b/tox.ini @@ -23,7 +23,7 @@ passenv = deps = {test,cov}: {[_test]deps} flake8: {[_flake8]deps} - py27: pathlib2 + py27: pathlib commands = py27-test: python -m nose {posargs} py38-cov: python -bb -m nose --with-coverage {posargs}