From 5f11ef572abe05736fce4936cd720c6a51e67f20 Mon Sep 17 00:00:00 2001 From: "Marlon (esolitos) Saglia" Date: Wed, 3 Jan 2024 11:18:54 +0100 Subject: [PATCH] fix: C0415: Import outside toplevel --- swa/spotifyoauthredis.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/swa/spotifyoauthredis.py b/swa/spotifyoauthredis.py index 1b49971..27dfbb1 100644 --- a/swa/spotifyoauthredis.py +++ b/swa/spotifyoauthredis.py @@ -2,11 +2,12 @@ This module contains functions for handling Spotify OAuth and cached access tokens. """ -import logging from os import getenv -import spotipy +import hashlib +import logging import redis +import spotipy from swa.utils import http_server_info @@ -36,18 +37,15 @@ def spotify_oauth(email: str) -> spotipy.SpotifyOAuth: cache_handler = None if getenv('REDIS_URL'): - from spotipy.cache_handler import RedisCacheHandler rclient = redis.Redis().from_url(url=getenv('REDIS_URL'), decode_responses=True) - cache_handler = RedisCacheHandler( + cache_handler = spotipy.cache_handler.RedisCacheHandler( rclient, '-'.join(('swa-user', email)), ) else: - from hashlib import sha1 - from spotipy.oauth2 import CacheFileHandler - cache_handler = CacheFileHandler( + cache_handler = spotipy.oauth2.CacheFileHandler( cache_path='.cache/user-%s' % - sha1( + hashlib.sha1( email.encode(), usedforsecurity=False).hexdigest())