diff options
author | Mike Crute <mcrute@gmail.com> | 2016-06-11 20:38:27 -0700 |
---|---|---|
committer | Mike Crute <mcrute@gmail.com> | 2016-06-11 20:48:28 -0700 |
commit | 8fe17e28ec673587c72b30eed38d713a0cffe3b6 (patch) | |
tree | dbe2346366411319f8c5e760c190469b0a726a77 | |
parent | a61dba18d255112c4f9285362dd8c2452506a76c (diff) | |
download | pydora-8fe17e28ec673587c72b30eed38d713a0cffe3b6.tar.bz2 pydora-8fe17e28ec673587c72b30eed38d713a0cffe3b6.tar.xz pydora-8fe17e28ec673587c72b30eed38d713a0cffe3b6.zip |
Cleanup pylint nitpicks
-rw-r--r-- | pandora/clientbuilder.py | 12 | ||||
-rw-r--r-- | pandora/errors.py | 4 | ||||
-rw-r--r-- | pandora/models/pandora.py | 5 | ||||
-rw-r--r-- | pandora/transport.py | 16 | ||||
-rw-r--r-- | pandora/util.py | 9 | ||||
-rw-r--r-- | pydora/configure.py | 12 | ||||
-rw-r--r-- | pydora/mpg123.py | 6 | ||||
-rwxr-xr-x | pydora/player.py | 8 | ||||
-rw-r--r-- | pydora/utils.py | 30 |
9 files changed, 50 insertions, 52 deletions
diff --git a/pandora/clientbuilder.py b/pandora/clientbuilder.py index 1464d5c..6c29678 100644 --- a/pandora/clientbuilder.py +++ b/pandora/clientbuilder.py | |||
@@ -129,7 +129,6 @@ class SettingsDict(TranslatingDict): | |||
129 | VALUE_TRANSLATIONS = {} | 129 | VALUE_TRANSLATIONS = {} |
130 | 130 | ||
131 | def was_translated(self, from_key, to_key): | 131 | def was_translated(self, from_key, to_key): |
132 | # TODO: Notify of deprecations | ||
133 | pass | 132 | pass |
134 | 133 | ||
135 | 134 | ||
@@ -174,6 +173,9 @@ class FileBasedClientBuilder(APIClientBuilder): | |||
174 | def path(self, path): | 173 | def path(self, path): |
175 | self._path = os.path.expanduser(path) | 174 | self._path = os.path.expanduser(path) |
176 | 175 | ||
176 | def parse_config(self): | ||
177 | raise NotImplementedError | ||
178 | |||
177 | def build(self): | 179 | def build(self): |
178 | if not self.file_exists: | 180 | if not self.file_exists: |
179 | raise IOError("File not found: {}".format(self.path)) | 181 | raise IOError("File not found: {}".format(self.path)) |
@@ -204,8 +206,8 @@ class PydoraConfigFileBuilder(FileBasedClientBuilder): | |||
204 | def parse_config(self): | 206 | def parse_config(self): |
205 | cfg = ConfigParser() | 207 | cfg = ConfigParser() |
206 | 208 | ||
207 | with open(self.path) as fp: | 209 | with open(self.path) as file: |
208 | cfg.read_file(fp) | 210 | cfg.read_file(file) |
209 | 211 | ||
210 | settings = PydoraConfigFileBuilder.cfg_to_dict(cfg, "api") | 212 | settings = PydoraConfigFileBuilder.cfg_to_dict(cfg, "api") |
211 | settings["user"] = PydoraConfigFileBuilder.cfg_to_dict( | 213 | settings["user"] = PydoraConfigFileBuilder.cfg_to_dict( |
@@ -242,8 +244,8 @@ class PianobarConfigFileBuilder(FileBasedClientBuilder): | |||
242 | def parse_config(self): | 244 | def parse_config(self): |
243 | settings = PianobarSettingsDict() | 245 | settings = PianobarSettingsDict() |
244 | 246 | ||
245 | with open(self.path, "r") as fp: | 247 | with open(self.path, "r") as file: |
246 | for line in fp.readlines(): | 248 | for line in file.readlines(): |
247 | line = line.strip() | 249 | line = line.strip() |
248 | 250 | ||
249 | if line and not line.startswith("#"): | 251 | if line and not line.startswith("#"): |
diff --git a/pandora/errors.py b/pandora/errors.py index 9fbd00e..d28a60f 100644 --- a/pandora/errors.py +++ b/pandora/errors.py | |||
@@ -82,7 +82,7 @@ class PandoraException(Exception): | |||
82 | return "".join(output) | 82 | return "".join(output) |
83 | 83 | ||
84 | @staticmethod | 84 | @staticmethod |
85 | def _export_exceptions(export_to): | 85 | def export_exceptions(export_to): |
86 | for code, api_message in __API_EXCEPTIONS__.items(): | 86 | for code, api_message in __API_EXCEPTIONS__.items(): |
87 | name = PandoraException._format_name(api_message) | 87 | name = PandoraException._format_name(api_message) |
88 | 88 | ||
@@ -94,7 +94,7 @@ class PandoraException(Exception): | |||
94 | export_to[name] = __API_EXCEPTIONS__[code] = exception | 94 | export_to[name] = __API_EXCEPTIONS__[code] = exception |
95 | 95 | ||
96 | 96 | ||
97 | PandoraException._export_exceptions(locals()) | 97 | PandoraException.export_exceptions(locals()) |
98 | 98 | ||
99 | 99 | ||
100 | class InvalidUserLogin(InvalidPartnerLogin): | 100 | class InvalidUserLogin(InvalidPartnerLogin): |
diff --git a/pandora/models/pandora.py b/pandora/models/pandora.py index 8fa8e21..0b138b3 100644 --- a/pandora/models/pandora.py +++ b/pandora/models/pandora.py | |||
@@ -1,5 +1,4 @@ | |||
1 | from .. import BaseAPIClient | 1 | from .. import BaseAPIClient |
2 | from . import with_metaclass, ModelMetaClass | ||
3 | from . import Field, PandoraModel, PandoraListModel, PandoraDictListModel | 2 | from . import Field, PandoraModel, PandoraListModel, PandoraDictListModel |
4 | from ..errors import ParameterMissing | 3 | from ..errors import ParameterMissing |
5 | 4 | ||
@@ -239,9 +238,9 @@ class AdItem(PlaylistModel): | |||
239 | def prepare_playback(self): | 238 | def prepare_playback(self): |
240 | try: | 239 | try: |
241 | self.register_ad(self.station_id) | 240 | self.register_ad(self.station_id) |
242 | except ParameterMissing as e: | 241 | except ParameterMissing as exc: |
243 | if self.tracking_tokens: | 242 | if self.tracking_tokens: |
244 | raise e | 243 | raise exc |
245 | return super(AdItem, self).prepare_playback() | 244 | return super(AdItem, self).prepare_playback() |
246 | 245 | ||
247 | 246 | ||
diff --git a/pandora/transport.py b/pandora/transport.py index 58d4097..a8f885e 100644 --- a/pandora/transport.py +++ b/pandora/transport.py | |||
@@ -23,6 +23,9 @@ from .errors import PandoraException | |||
23 | DEFAULT_API_HOST = "tuner.pandora.com/services/json/" | 23 | DEFAULT_API_HOST = "tuner.pandora.com/services/json/" |
24 | 24 | ||
25 | 25 | ||
26 | # This decorator is a temporary workaround for handling SysCallErrors, see: | ||
27 | # https://github.com/shazow/urllib3/issues/367. Should be removed once a fix is | ||
28 | # applied in urllib3. | ||
26 | def retries(max_tries, exceptions=(Exception,)): | 29 | def retries(max_tries, exceptions=(Exception,)): |
27 | """Function decorator implementing retrying logic. | 30 | """Function decorator implementing retrying logic. |
28 | 31 | ||
@@ -46,10 +49,10 @@ def retries(max_tries, exceptions=(Exception,)): | |||
46 | retries_left -= 1 | 49 | retries_left -= 1 |
47 | return func(*args, **kwargs) | 50 | return func(*args, **kwargs) |
48 | 51 | ||
49 | except exceptions as e: | 52 | except exceptions as exc: |
50 | # Don't retry for PandoraExceptions - unlikely that result | 53 | # Don't retry for PandoraExceptions - unlikely that result |
51 | # will change for same set of input parameters. | 54 | # will change for same set of input parameters. |
52 | if isinstance(e, PandoraException): | 55 | if isinstance(exc, PandoraException): |
53 | raise | 56 | raise |
54 | if retries_left > 0: | 57 | if retries_left > 0: |
55 | time.sleep(delay_exponential( | 58 | time.sleep(delay_exponential( |
@@ -179,9 +182,9 @@ class APITransport(object): | |||
179 | 182 | ||
180 | params = self.remove_empty_values(params) | 183 | params = self.remove_empty_values(params) |
181 | 184 | ||
182 | r = self._http.post(url, data=data, params=params) | 185 | result = self._http.post(url, data=data, params=params) |
183 | r.raise_for_status() | 186 | result.raise_for_status() |
184 | return r.content | 187 | return result.content |
185 | 188 | ||
186 | def test_url(self, url): | 189 | def test_url(self, url): |
187 | return self._http.head(url).status_code == requests.codes.OK | 190 | return self._http.head(url).status_code == requests.codes.OK |
@@ -221,9 +224,6 @@ class APITransport(object): | |||
221 | else: | 224 | else: |
222 | raise PandoraException.from_code(result["code"], result["message"]) | 225 | raise PandoraException.from_code(result["code"], result["message"]) |
223 | 226 | ||
224 | # TODO: This decorator is a temporary workaround for handling | ||
225 | # SysCallErrors, see: https://github.com/shazow/urllib3/issues/367. | ||
226 | # Should be removed once a fix is applied in urllib3. | ||
227 | @retries(3) | 227 | @retries(3) |
228 | def __call__(self, method, **data): | 228 | def __call__(self, method, **data): |
229 | self._start_request(method) | 229 | self._start_request(method) |
diff --git a/pandora/util.py b/pandora/util.py index 3a1bc5f..5cbc774 100644 --- a/pandora/util.py +++ b/pandora/util.py | |||
@@ -25,10 +25,11 @@ def deprecated(in_version, remove_version, message): | |||
25 | Decorator to warn that a function is deprecated and what version it will be | 25 | Decorator to warn that a function is deprecated and what version it will be |
26 | removed in. | 26 | removed in. |
27 | """ | 27 | """ |
28 | def wrapper(f): | 28 | def wrapper(wrapped): |
29 | @wraps(f) | 29 | @wraps(wrapped) |
30 | def inner_wrapper(self, *args, **kwargs): | 30 | def inner_wrapper(self, *args, **kwargs): |
31 | warn_deprecated(in_version, remove_version, f.func_name, message) | 31 | warn_deprecated( |
32 | return f(self, *args, **kwargs) | 32 | in_version, remove_version, wrapped.func_name, message) |
33 | return wrapped(self, *args, **kwargs) | ||
33 | return inner_wrapper | 34 | return inner_wrapper |
34 | return wrapper | 35 | return wrapper |
diff --git a/pydora/configure.py b/pydora/configure.py index 21ea3c3..824ab03 100644 --- a/pydora/configure.py +++ b/pydora/configure.py | |||
@@ -10,7 +10,7 @@ from pandora.clientbuilder import PydoraConfigFileBuilder | |||
10 | from .utils import Screen, Colors | 10 | from .utils import Screen, Colors |
11 | 11 | ||
12 | 12 | ||
13 | class umask(object): | 13 | class Umask(object): |
14 | """Set/Restore Umask Context Manager | 14 | """Set/Restore Umask Context Manager |
15 | """ | 15 | """ |
16 | 16 | ||
@@ -36,7 +36,7 @@ class PandoraKeysConfigParser(object): | |||
36 | "plain/json/partners.rst") | 36 | "plain/json/partners.rst") |
37 | 37 | ||
38 | FIELD_RE = re.compile( | 38 | FIELD_RE = re.compile( |
39 | ":(?P<key>[^:]+): (?:`{2})?(?P<value>[^`\n]+)(?:`{2})?$") | 39 | ":(?P<key>[^:]+): (?:`{2})?(?P<value>[^`\n]+)(?:`{2})?$") |
40 | 40 | ||
41 | def _fixup_key(self, key): | 41 | def _fixup_key(self, key): |
42 | key = key.lower() | 42 | key = key.lower() |
@@ -89,8 +89,8 @@ class PandoraKeysConfigParser(object): | |||
89 | elif self._is_device_terminator(line): | 89 | elif self._is_device_terminator(line): |
90 | key = self._clean_device_name(buffer.pop()) | 90 | key = self._clean_device_name(buffer.pop()) |
91 | current_partner = partners[key] = { | 91 | current_partner = partners[key] = { |
92 | "api_host": self._format_api_host(api_host) | 92 | "api_host": self._format_api_host(api_host) |
93 | } | 93 | } |
94 | 94 | ||
95 | buffer.append(line.strip().lower()) | 95 | buffer.append(line.strip().lower()) |
96 | 96 | ||
@@ -142,8 +142,8 @@ class Configurator(object): | |||
142 | self.cfg.set("api", key, value) | 142 | self.cfg.set("api", key, value) |
143 | 143 | ||
144 | def write_config(self): | 144 | def write_config(self): |
145 | with umask(0o077), open(self.builder.path, "w") as fp: | 145 | with Umask(0o077), open(self.builder.path, "w") as file: |
146 | self.cfg.write(fp) | 146 | self.cfg.write(file) |
147 | 147 | ||
148 | def configure(self): | 148 | def configure(self): |
149 | if self.builder.file_exists: | 149 | if self.builder.file_exists: |
diff --git a/pydora/mpg123.py b/pydora/mpg123.py index e60ab43..796a8ab 100644 --- a/pydora/mpg123.py +++ b/pydora/mpg123.py | |||
@@ -70,10 +70,10 @@ class Player(object): | |||
70 | readers, _, _ = select.select( | 70 | readers, _, _ = select.select( |
71 | [self._control_channel, self._process.stdout], [], [], 1) | 71 | [self._control_channel, self._process.stdout], [], [], 1) |
72 | 72 | ||
73 | for fd in readers: | 73 | for handle in readers: |
74 | value = fd.readline().strip() | 74 | value = handle.readline().strip() |
75 | 75 | ||
76 | if fd.fileno() == self._control_fd: | 76 | if handle.fileno() == self._control_fd: |
77 | self._callbacks.input(value, song) | 77 | self._callbacks.input(value, song) |
78 | else: | 78 | else: |
79 | if self._player_stopped(value): | 79 | if self._player_stopped(value): |
diff --git a/pydora/player.py b/pydora/player.py index 4561442..6e93df5 100755 --- a/pydora/player.py +++ b/pydora/player.py | |||
@@ -10,7 +10,7 @@ from __future__ import print_function | |||
10 | 10 | ||
11 | import os | 11 | import os |
12 | import sys | 12 | import sys |
13 | from pandora import APIClient, clientbuilder | 13 | from pandora import clientbuilder |
14 | 14 | ||
15 | from .mpg123 import Player | 15 | from .mpg123 import Player |
16 | from .utils import Colors, Screen | 16 | from .utils import Colors, Screen |
@@ -82,9 +82,9 @@ class PlayerApp(object): | |||
82 | """ | 82 | """ |
83 | Screen.clear() | 83 | Screen.clear() |
84 | 84 | ||
85 | for i, s in enumerate(self.stations): | 85 | for i, station in enumerate(self.stations): |
86 | i = "{:>3}".format(i) | 86 | i = "{:>3}".format(i) |
87 | print("{}: {}".format(Colors.yellow(i), s.name)) | 87 | print("{}: {}".format(Colors.yellow(i), station.name)) |
88 | 88 | ||
89 | return self.stations[Screen.get_integer("Station: ")] | 89 | return self.stations[Screen.get_integer("Station: ")] |
90 | 90 | ||
@@ -95,7 +95,7 @@ class PlayerApp(object): | |||
95 | print("{} ".format(Colors.cyan("Advertisement"))) | 95 | print("{} ".format(Colors.cyan("Advertisement"))) |
96 | else: | 96 | else: |
97 | print("{} by {}".format(Colors.cyan(song.song_name), | 97 | print("{} by {}".format(Colors.cyan(song.song_name), |
98 | Colors.yellow(song.artist_name))) | 98 | Colors.yellow(song.artist_name))) |
99 | 99 | ||
100 | def skip_song(self, song): | 100 | def skip_song(self, song): |
101 | if song.is_ad: | 101 | if song.is_ad: |
diff --git a/pydora/utils.py b/pydora/utils.py index 275c386..3c3aa39 100644 --- a/pydora/utils.py +++ b/pydora/utils.py | |||
@@ -5,8 +5,6 @@ import sys | |||
5 | import termios | 5 | import termios |
6 | import getpass | 6 | import getpass |
7 | import subprocess | 7 | import subprocess |
8 | from pandora.models.pandora import AdItem | ||
9 | from pandora import errors | ||
10 | 8 | ||
11 | 9 | ||
12 | def input(prompt): | 10 | def input(prompt): |
@@ -19,13 +17,13 @@ def input(prompt): | |||
19 | 17 | ||
20 | class Colors(object): | 18 | class Colors(object): |
21 | 19 | ||
22 | def __wrap_with(code): | 20 | def __wrap_with(raw_code): |
23 | @staticmethod | 21 | @staticmethod |
24 | def inner(text, bold=False): | 22 | def inner(text, bold=False): |
25 | c = code | 23 | code = raw_code |
26 | if bold: | 24 | if bold: |
27 | c = "1;{}".format(c) | 25 | code = "1;{}".format(code) |
28 | return "\033[{}m{}\033[0m".format(c, text) | 26 | return "\033[{}m{}\033[0m".format(code, text) |
29 | return inner | 27 | return inner |
30 | 28 | ||
31 | red = __wrap_with("31") | 29 | red = __wrap_with("31") |
@@ -41,20 +39,18 @@ class Screen(object): | |||
41 | 39 | ||
42 | @staticmethod | 40 | @staticmethod |
43 | def set_echo(enabled): | 41 | def set_echo(enabled): |
44 | fd = sys.stdin.fileno() | 42 | handle = sys.stdin.fileno() |
45 | if not os.isatty(fd): | 43 | if not os.isatty(handle): |
46 | return | 44 | return |
47 | 45 | ||
48 | (iflag, oflag, cflag, | 46 | attrs = termios.tcgetattr(handle) |
49 | lflag, ispeed, ospeed, cc) = termios.tcgetattr(fd) | ||
50 | 47 | ||
51 | if enabled: | 48 | if enabled: |
52 | lflag |= termios.ECHO | 49 | attrs[3] |= termios.ECHO |
53 | else: | 50 | else: |
54 | lflag &= ~termios.ECHO | 51 | attrs[3] &= ~termios.ECHO |
55 | 52 | ||
56 | termios.tcsetattr(fd, termios.TCSANOW, | 53 | termios.tcsetattr(handle, termios.TCSANOW, attrs) |
57 | [iflag, oflag, cflag, lflag, ispeed, ospeed, cc]) | ||
58 | 54 | ||
59 | @staticmethod | 55 | @staticmethod |
60 | def clear(): | 56 | def clear(): |
@@ -120,9 +116,9 @@ def iterate_forever(func, *args, **kwargs): | |||
120 | 116 | ||
121 | while True: | 117 | while True: |
122 | try: | 118 | try: |
123 | playlistItem = next(output) | 119 | playlist_item = next(output) |
124 | playlistItem.prepare_playback() | 120 | playlist_item.prepare_playback() |
125 | yield playlistItem | 121 | yield playlist_item |
126 | except StopIteration: | 122 | except StopIteration: |
127 | output = func(*args, **kwargs) | 123 | output = func(*args, **kwargs) |
128 | 124 | ||