Remove redundant _get_cache_backend and add some typing

This commit is contained in:
Hugo van Kemenade 2022-01-24 17:34:20 +02:00
parent 83aeaddc43
commit 5f8d150652

View file

@ -409,44 +409,37 @@ class _Network:
"""Returns True if web proxy is enabled.""" """Returns True if web proxy is enabled."""
return self.proxy is not None return self.proxy is not None
def enable_rate_limit(self): def enable_rate_limit(self) -> None:
"""Enables rate limiting for this network""" """Enables rate limiting for this network"""
self.limit_rate = True self.limit_rate = True
def disable_rate_limit(self): def disable_rate_limit(self) -> None:
"""Disables rate limiting for this network""" """Disables rate limiting for this network"""
self.limit_rate = False self.limit_rate = False
def is_rate_limited(self): def is_rate_limited(self) -> bool:
"""Return True if web service calls are rate limited""" """Return True if web service calls are rate limited"""
return self.limit_rate return self.limit_rate
def enable_caching(self, file_path=None): def enable_caching(self, file_path=None) -> None:
"""Enables caching request-wide for all cacheable calls. """Enables caching request-wide for all cacheable calls.
* file_path: A file path for the backend storage file. If * file_path: A file path for the backend storage file. If
None set, a temp file would probably be created, according the backend. None set, a temp file would probably be created, according the backend.
""" """
if not file_path: if not file_path:
self.cache_backend = _ShelfCacheBackend.create_shelf() self.cache_backend = _ShelfCacheBackend.create_shelf()
return return
self.cache_backend = _ShelfCacheBackend(file_path) self.cache_backend = _ShelfCacheBackend(file_path)
def disable_caching(self): def disable_caching(self) -> None:
"""Disables all caching features.""" """Disables all caching features."""
self.cache_backend = None self.cache_backend = None
def is_caching_enabled(self): def is_caching_enabled(self) -> bool:
"""Returns True if caching is enabled.""" """Returns True if caching is enabled."""
return self.cache_backend is not None
return not (self.cache_backend is None)
def _get_cache_backend(self):
return self.cache_backend
def search_for_album(self, album_name): def search_for_album(self, album_name):
"""Searches for an album by its name. Returns a AlbumSearch object. """Searches for an album by its name. Returns a AlbumSearch object.
@ -839,7 +832,7 @@ class _Request:
self.params["method"] = method_name self.params["method"] = method_name
if network.is_caching_enabled(): if network.is_caching_enabled():
self.cache = network._get_cache_backend() self.cache = network.cache_backend
if self.session_key: if self.session_key:
self.params["sk"] = self.session_key self.params["sk"] = self.session_key