Skip to content

Commit

Permalink
rolling back, this makes no sense to me
Browse files Browse the repository at this point in the history
  • Loading branch information
JackDyre committed Aug 9, 2024
1 parent e4ba2b5 commit 6814ab1
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions spotipy/cache_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import os
from abc import ABC, abstractmethod
from json import JSONEncoder
from pathlib import Path
from typing import Dict, Optional, Type, Union

from redis import RedisError
Expand Down Expand Up @@ -62,7 +61,6 @@ def __init__(
:param encoder_cls: (Optional) JSON encoder class to override default.
"""
self.encoder_cls = encoder_cls

if cache_path:
self.cache_path = cache_path
else:
Expand All @@ -77,8 +75,11 @@ def get_cached_token(self) -> Optional[TokenInfoType]:
token_info: Optional[TokenInfoType] = None

try:
with Path(self.cache_path).open("r") as f:
token_info = json.load(f)
f = open(self.cache_path)
token_info_string = f.read()
f.close()
token_info = json.loads(token_info_string)

except OSError as error:
if error.errno == errno.ENOENT:
logger.debug("cache does not exist at: %s", self.cache_path)
Expand All @@ -90,13 +91,15 @@ def get_cached_token(self) -> Optional[TokenInfoType]:
def save_token_to_cache(self, token_info: TokenInfoType) -> None:
"""Save token cache to file."""
try:
with Path(self.cache_path).open("r") as f:
json.dump(token_info, f, cls=self.encoder_cls)
f = open(self.cache_path, "w")
f.write(json.dumps(token_info, cls=self.encoder_cls))
f.close()
except OSError:
logger.warning("Couldn't write token to cache at: %s", self.cache_path)




class MemoryCacheHandler(CacheHandler):
"""
A cache handler that simply stores the token info in memory as an
Expand Down

0 comments on commit 6814ab1

Please sign in to comment.