aboutsummaryrefslogtreecommitdiff
path: root/pandora
diff options
context:
space:
mode:
authorMike Crute <mcrute@gmail.com>2016-06-11 20:38:27 -0700
committerMike Crute <mcrute@gmail.com>2016-06-11 20:48:28 -0700
commit8fe17e28ec673587c72b30eed38d713a0cffe3b6 (patch)
treedbe2346366411319f8c5e760c190469b0a726a77 /pandora
parenta61dba18d255112c4f9285362dd8c2452506a76c (diff)
downloadpydora-8fe17e28ec673587c72b30eed38d713a0cffe3b6.tar.bz2
pydora-8fe17e28ec673587c72b30eed38d713a0cffe3b6.tar.xz
pydora-8fe17e28ec673587c72b30eed38d713a0cffe3b6.zip
Cleanup pylint nitpicks
Diffstat (limited to 'pandora')
-rw-r--r--pandora/clientbuilder.py12
-rw-r--r--pandora/errors.py4
-rw-r--r--pandora/models/pandora.py5
-rw-r--r--pandora/transport.py16
-rw-r--r--pandora/util.py9
5 files changed, 24 insertions, 22 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
97PandoraException._export_exceptions(locals()) 97PandoraException.export_exceptions(locals())
98 98
99 99
100class InvalidUserLogin(InvalidPartnerLogin): 100class 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 @@
1from .. import BaseAPIClient 1from .. import BaseAPIClient
2from . import with_metaclass, ModelMetaClass
3from . import Field, PandoraModel, PandoraListModel, PandoraDictListModel 2from . import Field, PandoraModel, PandoraListModel, PandoraDictListModel
4from ..errors import ParameterMissing 3from ..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
23DEFAULT_API_HOST = "tuner.pandora.com/services/json/" 23DEFAULT_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.
26def retries(max_tries, exceptions=(Exception,)): 29def 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