From b9fe16fc341d516b52d282f67be6b2ae791aa84f Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Tue, 2 Apr 2019 02:09:49 +0000 Subject: Remove python 2 compatability --- pandora/clientbuilder.py | 2 +- pandora/models/__init__.py | 3 +- pandora/py2compat.py | 89 -------------------------------- pydora/audio_backend.py | 2 +- pydora/configure.py | 2 +- pydora/utils.py | 1 - setup.cfg | 1 - tests/test_pandora/test_client.py | 2 +- tests/test_pandora/test_clientbuilder.py | 2 +- tests/test_pandora/test_models.py | 4 +- tests/test_pandora/test_transport.py | 2 +- tests/test_pandora/test_util.py | 2 +- tests/test_pydora/test_utils.py | 2 +- 13 files changed, 11 insertions(+), 103 deletions(-) delete mode 100644 pandora/py2compat.py diff --git a/pandora/clientbuilder.py b/pandora/clientbuilder.py index 53abdf4..7543df7 100644 --- a/pandora/clientbuilder.py +++ b/pandora/clientbuilder.py @@ -6,7 +6,7 @@ configuration formats into a fully built APIClient. """ import os.path -from .py2compat import ConfigParser +from configparser import ConfigParser from .client import APIClient from .transport import Encryptor, APITransport, DEFAULT_API_HOST diff --git a/pandora/models/__init__.py b/pandora/models/__init__.py index bafb6ce..34ee2f7 100644 --- a/pandora/models/__init__.py +++ b/pandora/models/__init__.py @@ -1,6 +1,5 @@ from datetime import datetime from collections import namedtuple -from ..py2compat import with_metaclass class Field(namedtuple("Field", ["field", "default", "formatter", "model"])): @@ -88,7 +87,7 @@ class ModelMetaClass(type): return super(ModelMetaClass, cls).__new__(cls, name, parents, new_dct) -class PandoraModel(with_metaclass(ModelMetaClass, object)): +class PandoraModel(object, metaclass=ModelMetaClass): """Pandora API Model A single object representing a Pandora data object. Subclasses are diff --git a/pandora/py2compat.py b/pandora/py2compat.py deleted file mode 100644 index dfd9abd..0000000 --- a/pandora/py2compat.py +++ /dev/null @@ -1,89 +0,0 @@ -""" -Python 2 Compatibility Layer - -This module exists to work around compatibility issues between Python 2 and -Python 3. The main code-base will use Python 3 idioms and this module will -patch Python 2 code to support those changes. When Python 2 support is -dropped this module can be removed and imports can be updated. -""" - - -def with_metaclass(meta, *bases): - return meta("NewBase", bases, {}) - - -try: - from configparser import ConfigParser -except ImportError: - from ConfigParser import SafeConfigParser - - class ConfigParser(SafeConfigParser): - - def read_file(self, fp): - return self.readfp(fp) - - -# Used in pydora -def input(prompt): - try: - return raw_input(prompt) - except NameError: - import builtins - return builtins.input(prompt) - - -# Only used in tests -try: - from unittest.mock import Mock, MagicMock, call, patch # noqa: F401 -except ImportError: - try: - from mock import Mock, MagicMock, call, patch # noqa: F401 - except ImportError: - pass - - -try: - from shutil import which -except ImportError: - import os - import sys - - # Copypasta from Python 3.6, exists in 3.3+ - def which(cmd, mode=os.F_OK | os.X_OK, path=None): - def _access_check(fn, mode): - return (os.path.exists(fn) and os.access(fn, mode) - and not os.path.isdir(fn)) - - if os.path.dirname(cmd): - if _access_check(cmd, mode): - return cmd - return None - - if path is None: - path = os.environ.get("PATH", os.defpath) - if not path: - return None - path = path.split(os.pathsep) - - if sys.platform == "win32": - if os.curdir not in path: - path.insert(0, os.curdir) - - pathext = os.environ.get("PATHEXT", "").split(os.pathsep) - if any(cmd.lower().endswith(ext.lower()) for ext in pathext): - files = [cmd] - else: - files = [cmd + ext for ext in pathext] - else: - files = [cmd] - - seen = set() - for dir in path: - normdir = os.path.normcase(dir) - if normdir not in seen: - seen.add(normdir) - for thefile in files: - name = os.path.join(dir, thefile) - if _access_check(name, mode): - return name - return None diff --git a/pydora/audio_backend.py b/pydora/audio_backend.py index 1adf0a3..949301e 100644 --- a/pydora/audio_backend.py +++ b/pydora/audio_backend.py @@ -4,8 +4,8 @@ import fcntl import select import socket import logging +from shutil import which -from pandora.py2compat import which from .utils import iterate_forever, SilentPopen diff --git a/pydora/configure.py b/pydora/configure.py index ee56197..7c051df 100644 --- a/pydora/configure.py +++ b/pydora/configure.py @@ -2,9 +2,9 @@ import os import re import sys import requests +from configparser import ConfigParser from pandora.client import APIClient -from pandora.py2compat import ConfigParser from pandora.clientbuilder import PydoraConfigFileBuilder from .utils import Screen, Colors diff --git a/pydora/utils.py b/pydora/utils.py index 6c608a7..af353b3 100644 --- a/pydora/utils.py +++ b/pydora/utils.py @@ -4,7 +4,6 @@ import os import sys import getpass import subprocess -from pandora.py2compat import input class TerminalPlatformUnsupported(Exception): diff --git a/setup.cfg b/setup.cfg index faeee10..2c43f4f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,7 +4,6 @@ validate = release [coverage:run] branch = True -omit = pandora/py2compat.py [coverage:report] # Support "no cover" and "nc" to handle long lines diff --git a/tests/test_pandora/test_client.py b/tests/test_pandora/test_client.py index d24ea28..5bd200c 100644 --- a/tests/test_pandora/test_client.py +++ b/tests/test_pandora/test_client.py @@ -1,9 +1,9 @@ from unittest import TestCase +from unittest.mock import Mock, call, patch from pandora import errors from pandora.models.pandora import AdItem, AdditionalAudioUrl from pandora.client import APIClient, BaseAPIClient -from pandora.py2compat import Mock, call, patch from tests.test_pandora.test_models import TestAdItem diff --git a/tests/test_pandora/test_clientbuilder.py b/tests/test_pandora/test_clientbuilder.py index 0105c09..af0e219 100644 --- a/tests/test_pandora/test_clientbuilder.py +++ b/tests/test_pandora/test_clientbuilder.py @@ -1,8 +1,8 @@ import os from unittest import TestCase +from unittest.mock import Mock import pandora.clientbuilder as cb -from pandora.py2compat import Mock from pandora.client import APIClient from pandora.transport import DEFAULT_API_HOST diff --git a/tests/test_pandora/test_models.py b/tests/test_pandora/test_models.py index 410b0de..13ca366 100644 --- a/tests/test_pandora/test_models.py +++ b/tests/test_pandora/test_models.py @@ -1,6 +1,6 @@ from unittest import TestCase from datetime import datetime -from pandora.py2compat import Mock, patch +from unittest.mock import Mock, patch from pandora.client import APIClient from pandora.errors import ParameterMissing @@ -21,7 +21,7 @@ class TestField(TestCase): class TestModelMetaClass(TestCase): - class TestModel(m.with_metaclass(m.ModelMetaClass, object)): + class TestModel(object, 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 ff9c572..862a12f 100644 --- a/tests/test_pandora/test_transport.py +++ b/tests/test_pandora/test_transport.py @@ -4,7 +4,7 @@ import json import random import requests from unittest import TestCase -from pandora.py2compat import Mock, call, patch +from unittest.mock import Mock, call, patch from pandora.errors import InvalidAuthToken, PandoraException from tests.test_pandora.test_clientbuilder import TestSettingsDictBuilder diff --git a/tests/test_pandora/test_util.py b/tests/test_pandora/test_util.py index 2b4ca83..d8c3876 100644 --- a/tests/test_pandora/test_util.py +++ b/tests/test_pandora/test_util.py @@ -1,6 +1,6 @@ import warnings from unittest import TestCase -from pandora.py2compat import patch +from unittest.mock import patch from pandora import util diff --git a/tests/test_pydora/test_utils.py b/tests/test_pydora/test_utils.py index 9900913..5dca83c 100644 --- a/tests/test_pydora/test_utils.py +++ b/tests/test_pydora/test_utils.py @@ -1,9 +1,9 @@ from unittest import TestCase +from unittest.mock import Mock, patch from pandora.client import APIClient from pandora.errors import InvalidAuthToken, ParameterMissing from pandora.models.pandora import Station, AdItem, PlaylistItem -from pandora.py2compat import Mock, patch from pydora.utils import iterate_forever -- cgit v1.2.3