From 6b7990a3de49ebf9483a70003a20dd6636e8c000 Mon Sep 17 00:00:00 2001 From: Hugo Date: Sun, 7 Apr 2019 18:17:11 +0300 Subject: Upgrade Python syntax with pyupgrade --py3-plus --- pandora/client.py | 2 +- pandora/clientbuilder.py | 10 +++++----- pandora/errors.py | 2 +- pandora/models/_base.py | 8 ++++---- pandora/models/ad.py | 2 +- pandora/transport.py | 12 ++++++------ pydora/audio_backend.py | 8 ++++---- pydora/configure.py | 6 +++--- pydora/player.py | 12 ++++++------ pydora/utils.py | 16 ++++++++-------- setup.py | 4 ++-- tests/test_pandora/test_client.py | 2 +- tests/test_pandora/test_models.py | 2 +- tests/test_pandora/test_transport.py | 4 ++-- 14 files changed, 45 insertions(+), 45 deletions(-) diff --git a/pandora/client.py b/pandora/client.py index b077954..bb30738 100644 --- a/pandora/client.py +++ b/pandora/client.py @@ -16,7 +16,7 @@ instance of a client. from . import errors -class BaseAPIClient(object): +class BaseAPIClient: """Base Pandora API Client The base API client has lower level methods that are composed together to diff --git a/pandora/clientbuilder.py b/pandora/clientbuilder.py index 7543df7..bc55cec 100644 --- a/pandora/clientbuilder.py +++ b/pandora/clientbuilder.py @@ -30,7 +30,7 @@ class TranslatingDict(dict): VALUE_TRANSLATIONS = None def __init__(self, initial=None): - super(TranslatingDict, self).__init__() + super().__init__() assert self.KEY_TRANSLATIONS is not None assert self.VALUE_TRANSLATIONS is not None @@ -70,11 +70,11 @@ class TranslatingDict(dict): def __setitem__(self, key, value): key = self.translate_key(key) - super(TranslatingDict, self).__setitem__( + super().__setitem__( key, self.translate_value(key, value)) -class APIClientBuilder(object): +class APIClientBuilder: """Abstract API Client Builder Provides the basic functions for building an API client. Expects a @@ -141,7 +141,7 @@ class SettingsDictBuilder(APIClientBuilder): def __init__(self, settings, **kwargs): self.settings = settings - super(SettingsDictBuilder, self).__init__(**kwargs) + super().__init__(**kwargs) def build(self): settings = SettingsDict(self.settings) @@ -160,7 +160,7 @@ class FileBasedClientBuilder(APIClientBuilder): def __init__(self, path=None, authenticate=True, **kwargs): self.path = path or self.DEFAULT_CONFIG_FILE self.authenticate = authenticate - super(FileBasedClientBuilder, self).__init__(**kwargs) + super().__init__(**kwargs) @property def file_exists(self): diff --git a/pandora/errors.py b/pandora/errors.py index ba377b5..c978708 100644 --- a/pandora/errors.py +++ b/pandora/errors.py @@ -56,7 +56,7 @@ class PandoraException(Exception): def __init__(self, extended_message=""): self.extended_message = extended_message - super(PandoraException, self).__init__(self.message) + super().__init__(self.message) @classmethod def from_code(cls, code, extended_message): diff --git a/pandora/models/_base.py b/pandora/models/_base.py index 214f3c1..5689cdf 100644 --- a/pandora/models/_base.py +++ b/pandora/models/_base.py @@ -26,7 +26,7 @@ class Field(namedtuple("Field", ["field", "default", "formatter", "model"])): """ def __new__(cls, field, default=None, formatter=None, model=None): - return super(Field, cls).__new__(cls, field, default, formatter, model) + return super().__new__(cls, field, default, formatter, model) class SyntheticField(namedtuple("SyntheticField", ["field"])): @@ -84,10 +84,10 @@ class ModelMetaClass(type): fields[key] = val del new_dct[key] - return super(ModelMetaClass, cls).__new__(cls, name, parents, new_dct) + return super().__new__(cls, name, parents, new_dct) -class PandoraModel(object, metaclass=ModelMetaClass): +class PandoraModel(metaclass=ModelMetaClass): """Pandora API Model A single object representing a Pandora data object. Subclasses are @@ -208,7 +208,7 @@ class PandoraListModel(PandoraModel, list): __index_key__ = None def __init__(self, *args, **kwargs): - super(PandoraListModel, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self._index = {} @classmethod diff --git a/pandora/models/ad.py b/pandora/models/ad.py index 91820c9..040c76b 100644 --- a/pandora/models/ad.py +++ b/pandora/models/ad.py @@ -33,7 +33,7 @@ class AdItem(PlaylistModel): except ParameterMissing as exc: if self.tracking_tokens: raise exc - return super(AdItem, self).prepare_playback() + return super().prepare_playback() def thumbs_up(self): # pragma: no cover return diff --git a/pandora/transport.py b/pandora/transport.py index 6f1a174..721882d 100644 --- a/pandora/transport.py +++ b/pandora/transport.py @@ -94,12 +94,12 @@ class RetryingSession(requests.Session): """ def __init__(self): - super(RetryingSession, self).__init__() + super().__init__() self.mount('https://', HTTPAdapter(max_retries=3)) self.mount('http://', HTTPAdapter(max_retries=3)) -class APITransport(object): +class APITransport: """Pandora API Transport The transport is responsible for speaking the low-level protocol required @@ -161,7 +161,7 @@ class APITransport(object): return int(self.server_sync_time + (time.time() - self.start_time)) def remove_empty_values(self, data): - return dict((k, v) for k, v in data.items() if v is not None) + return {k: v for k, v in data.items() if v is not None} @sync_time.setter def sync_time(self, sync_time): @@ -198,7 +198,7 @@ class APITransport(object): } def _build_url(self, method): - return "{0}://{1}".format( + return "{}://{}".format( "https" if method in self.REQUIRE_TLS else "http", self.api_host) @@ -236,7 +236,7 @@ class APITransport(object): return self._parse_response(result) -class BlowfishCryptor(object): +class BlowfishCryptor: """Low-Level Blowfish Cryptography Handles symmetric Blowfish cryptography of raw byte messages with or @@ -285,7 +285,7 @@ class PurePythonBlowfish(BlowfishCryptor): return b"".join(self.cipher.encrypt_ecb(self._add_padding(data))) -class Encryptor(object): +class Encryptor: """Pandora Blowfish Encryptor The blowfish encryptor can encrypt and decrypt the relevant parts of the diff --git a/pydora/audio_backend.py b/pydora/audio_backend.py index d39bb9b..bd778ad 100644 --- a/pydora/audio_backend.py +++ b/pydora/audio_backend.py @@ -30,7 +30,7 @@ class PlayerUnusable(PlayerException): pass -class BasePlayer(object): +class BasePlayer: """Audio Backend Process Manager Starts and owns a handle to an audio backend process then feeds commands to @@ -208,7 +208,7 @@ class MPG123Player(BasePlayer): """ def __init__(self, callbacks, control_channel): - super(MPG123Player, self).__init__(callbacks, control_channel) + super().__init__(callbacks, control_channel) self._cmd.extend(["-q", "-R", "--ignore-mime", "."]) def _find_path(self): @@ -246,7 +246,7 @@ class VLCPlayer(BasePlayer): VOL_STEPS = 5 def __init__(self, callbacks, control_channel): - super(VLCPlayer, self).__init__(callbacks, control_channel) + super().__init__(callbacks, control_channel) self._cmd.extend(["-I", "rc", "--advanced", "--rc-fake-tty", "-q"]) self._last_poll = 0 @@ -300,7 +300,7 @@ class RemoteVLC(VLCPlayer): def __init__(self, host, port, callbacks, control_channel): self._connect_to = (host, int(port)) self._control_sock = None - super(RemoteVLC, self).__init__(callbacks, control_channel) + super().__init__(callbacks, control_channel) def _get_select_readers(self): return [self._control_channel, self._control_sock] diff --git a/pydora/configure.py b/pydora/configure.py index 7c051df..d31c097 100644 --- a/pydora/configure.py +++ b/pydora/configure.py @@ -10,7 +10,7 @@ from pandora.clientbuilder import PydoraConfigFileBuilder from .utils import Screen, Colors -class Umask(object): +class Umask: """Set/Restore Umask Context Manager """ @@ -25,7 +25,7 @@ class Umask(object): os.umask(self.old_umask) -class PandoraKeysConfigParser(object): +class PandoraKeysConfigParser: """Parser for Pandora Keys Source Page This is an extremely naive restructured text parser designed only to parse @@ -97,7 +97,7 @@ class PandoraKeysConfigParser(object): return partners -class Configurator(object): +class Configurator: """Interactive Configuration Builder Allows a user to configure pydora interactively. Ultimately writes the diff --git a/pydora/player.py b/pydora/player.py index 74b6110..fdacc63 100644 --- a/pydora/player.py +++ b/pydora/player.py @@ -18,7 +18,7 @@ from .audio_backend import MPG123Player, VLCPlayer from .audio_backend import UnsupportedEncoding, PlayerUnusable -class PlayerCallbacks(object): +class PlayerCallbacks: """Interface for Player Callbacks This class simply exists to document the interface for callback @@ -46,7 +46,7 @@ class PlayerCallbacks(object): pass -class PlayerApp(object): +class PlayerApp: CMD_MAP = { "n": ("play next song", "skip_song"), @@ -122,7 +122,7 @@ class PlayerApp(object): for i, station in enumerate(self.stations): i = "{:>3}".format(i) - print(u"{}: {}".format(Colors.yellow(i), station.name)) + print("{}: {}".format(Colors.yellow(i), station.name)) return self.stations[self.screen.get_integer("Station: ")] @@ -130,10 +130,10 @@ class PlayerApp(object): """Play callback """ if song.is_ad: - print(u"{} ".format(Colors.cyan("Advertisement"))) + print("{} ".format(Colors.cyan("Advertisement"))) else: - print(u"{} by {}".format(Colors.cyan(song.song_name), - Colors.yellow(song.artist_name))) + print("{} by {}".format(Colors.cyan(song.song_name), + Colors.yellow(song.artist_name))) def skip_song(self, song): if song.is_ad: diff --git a/pydora/utils.py b/pydora/utils.py index ca40095..6675773 100644 --- a/pydora/utils.py +++ b/pydora/utils.py @@ -13,15 +13,15 @@ class TerminalPlatformUnsupported(Exception): pass -class Colors(object): +class Colors: def __wrap_with(raw_code): @staticmethod def inner(text, bold=False): code = raw_code if bold: - code = u"1;{}".format(code) - return u"\033[{}m{}\033[0m".format(code, text) + code = "1;{}".format(code) + return "\033[{}m{}\033[0m".format(code, text) return inner red = __wrap_with("31") @@ -33,7 +33,7 @@ class Colors(object): white = __wrap_with("37") -class PosixEchoControl(object): +class PosixEchoControl: """Posix Console Echo Control Driver Uses termios on POSIX compliant platforms to control console echo. Is not @@ -63,7 +63,7 @@ class PosixEchoControl(object): self.termios.tcsetattr(handle, self.termios.TCSANOW, attrs) -class Win32EchoControl(object): +class Win32EchoControl: """Windows Console Echo Control Driver This uses the console API from WinCon.h and ctypes to control console echo @@ -109,7 +109,7 @@ class Win32EchoControl(object): self._SetConsoleMode(stdin, mode & self.DISABLE_ECHO_INPUT) -class Screen(object): +class Screen: def __init__(self): try: @@ -201,8 +201,8 @@ class SilentPopen(subprocess.Popen): kwargs["stdin"] = subprocess.PIPE kwargs["stdout"] = subprocess.PIPE kwargs["stderr"] = self._dev_null - super(SilentPopen, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def __del__(self): self._dev_null.close() - super(SilentPopen, self).__del__() + super().__del__() diff --git a/setup.py b/setup.py index 614df41..63abed1 100755 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ from setuptools import setup, find_packages # Python 2 setuptools test class is not an object -class TestsWithCoverage(test, object): +class TestsWithCoverage(test): description = "run unit tests with coverage" @@ -28,7 +28,7 @@ class TestsWithCoverage(test, object): # Unittest calls exit prior to python 3. How naughty try: - super(TestsWithCoverage, self).run() + super().run() except SystemExit: pass diff --git a/tests/test_pandora/test_client.py b/tests/test_pandora/test_client.py index 901e072..9945bff 100644 --- a/tests/test_pandora/test_client.py +++ b/tests/test_pandora/test_client.py @@ -10,7 +10,7 @@ from tests.test_pandora.test_models import TestAdItem class TestAPIClientLogin(TestCase): - class StubTransport(object): + class StubTransport: API_VERSION = None diff --git a/tests/test_pandora/test_models.py b/tests/test_pandora/test_models.py index 8cfbd9d..0d37ca0 100644 --- a/tests/test_pandora/test_models.py +++ b/tests/test_pandora/test_models.py @@ -25,7 +25,7 @@ class TestField(TestCase): class TestModelMetaClass(TestCase): - class TestModel(object, metaclass=m.ModelMetaClass): + class TestModel(metaclass=m.ModelMetaClass): foo = "bar" a_field = m.Field("testing") diff --git a/tests/test_pandora/test_transport.py b/tests/test_pandora/test_transport.py index 96dd40e..7eaaa6b 100644 --- a/tests/test_pandora/test_transport.py +++ b/tests/test_pandora/test_transport.py @@ -247,7 +247,7 @@ class TestTransportRequestPrep(TestCase): # All Cryptor implementations must pass these test cases unmodified -class CommonCryptorTestCases(object): +class CommonCryptorTestCases: def test_decrypt_invalid_padding(self): with self.assertRaises(ValueError): @@ -288,7 +288,7 @@ class TestEncryptor(TestCase): EXPECTED_TIME = 4111 ENCODED_TIME = "31353037343131313539" - class NoopCrypto(object): + class NoopCrypto: def __init__(self, key): pass -- cgit v1.2.3