diff options
author | Mike Crute <mike@crute.us> | 2019-04-02 02:09:49 +0000 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2019-04-02 02:09:49 +0000 |
commit | b9fe16fc341d516b52d282f67be6b2ae791aa84f (patch) | |
tree | 333bccd7b7e61eda3d45ea057f49761ceb01e938 | |
parent | 7b7c0071d2bab85fbf104d66b603782999b904a5 (diff) | |
download | pydora-b9fe16fc341d516b52d282f67be6b2ae791aa84f.tar.bz2 pydora-b9fe16fc341d516b52d282f67be6b2ae791aa84f.tar.xz pydora-b9fe16fc341d516b52d282f67be6b2ae791aa84f.zip |
Remove python 2 compatability
-rw-r--r-- | pandora/clientbuilder.py | 2 | ||||
-rw-r--r-- | pandora/models/__init__.py | 3 | ||||
-rw-r--r-- | pandora/py2compat.py | 89 | ||||
-rw-r--r-- | pydora/audio_backend.py | 2 | ||||
-rw-r--r-- | pydora/configure.py | 2 | ||||
-rw-r--r-- | pydora/utils.py | 1 | ||||
-rw-r--r-- | setup.cfg | 1 | ||||
-rw-r--r-- | tests/test_pandora/test_client.py | 2 | ||||
-rw-r--r-- | tests/test_pandora/test_clientbuilder.py | 2 | ||||
-rw-r--r-- | tests/test_pandora/test_models.py | 4 | ||||
-rw-r--r-- | tests/test_pandora/test_transport.py | 2 | ||||
-rw-r--r-- | tests/test_pandora/test_util.py | 2 | ||||
-rw-r--r-- | tests/test_pydora/test_utils.py | 2 |
13 files changed, 11 insertions, 103 deletions
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. | |||
6 | """ | 6 | """ |
7 | import os.path | 7 | import os.path |
8 | 8 | ||
9 | from .py2compat import ConfigParser | 9 | from configparser import ConfigParser |
10 | from .client import APIClient | 10 | from .client import APIClient |
11 | from .transport import Encryptor, APITransport, DEFAULT_API_HOST | 11 | from .transport import Encryptor, APITransport, DEFAULT_API_HOST |
12 | 12 | ||
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 @@ | |||
1 | from datetime import datetime | 1 | from datetime import datetime |
2 | from collections import namedtuple | 2 | from collections import namedtuple |
3 | from ..py2compat import with_metaclass | ||
4 | 3 | ||
5 | 4 | ||
6 | class Field(namedtuple("Field", ["field", "default", "formatter", "model"])): | 5 | class Field(namedtuple("Field", ["field", "default", "formatter", "model"])): |
@@ -88,7 +87,7 @@ class ModelMetaClass(type): | |||
88 | return super(ModelMetaClass, cls).__new__(cls, name, parents, new_dct) | 87 | return super(ModelMetaClass, cls).__new__(cls, name, parents, new_dct) |
89 | 88 | ||
90 | 89 | ||
91 | class PandoraModel(with_metaclass(ModelMetaClass, object)): | 90 | class PandoraModel(object, metaclass=ModelMetaClass): |
92 | """Pandora API Model | 91 | """Pandora API Model |
93 | 92 | ||
94 | A single object representing a Pandora data object. Subclasses are | 93 | 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 @@ | |||
1 | """ | ||
2 | Python 2 Compatibility Layer | ||
3 | |||
4 | This module exists to work around compatibility issues between Python 2 and | ||
5 | Python 3. The main code-base will use Python 3 idioms and this module will | ||
6 | patch Python 2 code to support those changes. When Python 2 support is | ||
7 | dropped this module can be removed and imports can be updated. | ||
8 | """ | ||
9 | |||
10 | |||
11 | def with_metaclass(meta, *bases): | ||
12 | return meta("NewBase", bases, {}) | ||
13 | |||
14 | |||
15 | try: | ||
16 | from configparser import ConfigParser | ||
17 | except ImportError: | ||
18 | from ConfigParser import SafeConfigParser | ||
19 | |||
20 | class ConfigParser(SafeConfigParser): | ||
21 | |||
22 | def read_file(self, fp): | ||
23 | return self.readfp(fp) | ||
24 | |||
25 | |||
26 | # Used in pydora | ||
27 | def input(prompt): | ||
28 | try: | ||
29 | return raw_input(prompt) | ||
30 | except NameError: | ||
31 | import builtins | ||
32 | return builtins.input(prompt) | ||
33 | |||
34 | |||
35 | # Only used in tests | ||
36 | try: | ||
37 | from unittest.mock import Mock, MagicMock, call, patch # noqa: F401 | ||
38 | except ImportError: | ||
39 | try: | ||
40 | from mock import Mock, MagicMock, call, patch # noqa: F401 | ||
41 | except ImportError: | ||
42 | pass | ||
43 | |||
44 | |||
45 | try: | ||
46 | from shutil import which | ||
47 | except ImportError: | ||
48 | import os | ||
49 | import sys | ||
50 | |||
51 | # Copypasta from Python 3.6, exists in 3.3+ | ||
52 | def which(cmd, mode=os.F_OK | os.X_OK, path=None): | ||
53 | def _access_check(fn, mode): | ||
54 | return (os.path.exists(fn) and os.access(fn, mode) | ||
55 | and not os.path.isdir(fn)) | ||
56 | |||
57 | if os.path.dirname(cmd): | ||
58 | if _access_check(cmd, mode): | ||
59 | return cmd | ||
60 | return None | ||
61 | |||
62 | if path is None: | ||
63 | path = os.environ.get("PATH", os.defpath) | ||
64 | if not path: | ||
65 | return None | ||
66 | path = path.split(os.pathsep) | ||
67 | |||
68 | if sys.platform == "win32": | ||
69 | if os.curdir not in path: | ||
70 | path.insert(0, os.curdir) | ||
71 | |||
72 | pathext = os.environ.get("PATHEXT", "").split(os.pathsep) | ||
73 | if any(cmd.lower().endswith(ext.lower()) for ext in pathext): | ||
74 | files = [cmd] | ||
75 | else: | ||
76 | files = [cmd + ext for ext in pathext] | ||
77 | else: | ||
78 | files = [cmd] | ||
79 | |||
80 | seen = set() | ||
81 | for dir in path: | ||
82 | normdir = os.path.normcase(dir) | ||
83 | if normdir not in seen: | ||
84 | seen.add(normdir) | ||
85 | for thefile in files: | ||
86 | name = os.path.join(dir, thefile) | ||
87 | if _access_check(name, mode): | ||
88 | return name | ||
89 | 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 | |||
4 | import select | 4 | import select |
5 | import socket | 5 | import socket |
6 | import logging | 6 | import logging |
7 | from shutil import which | ||
7 | 8 | ||
8 | from pandora.py2compat import which | ||
9 | from .utils import iterate_forever, SilentPopen | 9 | from .utils import iterate_forever, SilentPopen |
10 | 10 | ||
11 | 11 | ||
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 | |||
2 | import re | 2 | import re |
3 | import sys | 3 | import sys |
4 | import requests | 4 | import requests |
5 | from configparser import ConfigParser | ||
5 | 6 | ||
6 | from pandora.client import APIClient | 7 | from pandora.client import APIClient |
7 | from pandora.py2compat import ConfigParser | ||
8 | from pandora.clientbuilder import PydoraConfigFileBuilder | 8 | from pandora.clientbuilder import PydoraConfigFileBuilder |
9 | 9 | ||
10 | from .utils import Screen, Colors | 10 | 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 | |||
4 | import sys | 4 | import sys |
5 | import getpass | 5 | import getpass |
6 | import subprocess | 6 | import subprocess |
7 | from pandora.py2compat import input | ||
8 | 7 | ||
9 | 8 | ||
10 | class TerminalPlatformUnsupported(Exception): | 9 | class TerminalPlatformUnsupported(Exception): |
@@ -4,7 +4,6 @@ validate = release | |||
4 | 4 | ||
5 | [coverage:run] | 5 | [coverage:run] |
6 | branch = True | 6 | branch = True |
7 | omit = pandora/py2compat.py | ||
8 | 7 | ||
9 | [coverage:report] | 8 | [coverage:report] |
10 | # Support "no cover" and "nc" to handle long lines | 9 | # 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 @@ | |||
1 | from unittest import TestCase | 1 | from unittest import TestCase |
2 | from unittest.mock import Mock, call, patch | ||
2 | 3 | ||
3 | from pandora import errors | 4 | from pandora import errors |
4 | from pandora.models.pandora import AdItem, AdditionalAudioUrl | 5 | from pandora.models.pandora import AdItem, AdditionalAudioUrl |
5 | from pandora.client import APIClient, BaseAPIClient | 6 | from pandora.client import APIClient, BaseAPIClient |
6 | from pandora.py2compat import Mock, call, patch | ||
7 | from tests.test_pandora.test_models import TestAdItem | 7 | from tests.test_pandora.test_models import TestAdItem |
8 | 8 | ||
9 | 9 | ||
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 @@ | |||
1 | import os | 1 | import os |
2 | from unittest import TestCase | 2 | from unittest import TestCase |
3 | from unittest.mock import Mock | ||
3 | 4 | ||
4 | import pandora.clientbuilder as cb | 5 | import pandora.clientbuilder as cb |
5 | from pandora.py2compat import Mock | ||
6 | from pandora.client import APIClient | 6 | from pandora.client import APIClient |
7 | from pandora.transport import DEFAULT_API_HOST | 7 | from pandora.transport import DEFAULT_API_HOST |
8 | 8 | ||
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 @@ | |||
1 | from unittest import TestCase | 1 | from unittest import TestCase |
2 | from datetime import datetime | 2 | from datetime import datetime |
3 | from pandora.py2compat import Mock, patch | 3 | from unittest.mock import Mock, patch |
4 | 4 | ||
5 | from pandora.client import APIClient | 5 | from pandora.client import APIClient |
6 | from pandora.errors import ParameterMissing | 6 | from pandora.errors import ParameterMissing |
@@ -21,7 +21,7 @@ class TestField(TestCase): | |||
21 | 21 | ||
22 | class TestModelMetaClass(TestCase): | 22 | class TestModelMetaClass(TestCase): |
23 | 23 | ||
24 | class TestModel(m.with_metaclass(m.ModelMetaClass, object)): | 24 | class TestModel(object, metaclass=m.ModelMetaClass): |
25 | 25 | ||
26 | foo = "bar" | 26 | foo = "bar" |
27 | a_field = m.Field("testing") | 27 | 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 | |||
4 | import random | 4 | import random |
5 | import requests | 5 | import requests |
6 | from unittest import TestCase | 6 | from unittest import TestCase |
7 | from pandora.py2compat import Mock, call, patch | 7 | from unittest.mock import Mock, call, patch |
8 | 8 | ||
9 | from pandora.errors import InvalidAuthToken, PandoraException | 9 | from pandora.errors import InvalidAuthToken, PandoraException |
10 | from tests.test_pandora.test_clientbuilder import TestSettingsDictBuilder | 10 | 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 @@ | |||
1 | import warnings | 1 | import warnings |
2 | from unittest import TestCase | 2 | from unittest import TestCase |
3 | from pandora.py2compat import patch | 3 | from unittest.mock import patch |
4 | 4 | ||
5 | from pandora import util | 5 | from pandora import util |
6 | 6 | ||
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 @@ | |||
1 | from unittest import TestCase | 1 | from unittest import TestCase |
2 | from unittest.mock import Mock, patch | ||
2 | 3 | ||
3 | from pandora.client import APIClient | 4 | from pandora.client import APIClient |
4 | from pandora.errors import InvalidAuthToken, ParameterMissing | 5 | from pandora.errors import InvalidAuthToken, ParameterMissing |
5 | from pandora.models.pandora import Station, AdItem, PlaylistItem | 6 | from pandora.models.pandora import Station, AdItem, PlaylistItem |
6 | from pandora.py2compat import Mock, patch | ||
7 | from pydora.utils import iterate_forever | 7 | from pydora.utils import iterate_forever |
8 | 8 | ||
9 | 9 | ||