Avoid nested import
... to get rid of F401 error by flake8.
This commit is contained in:
parent
9a38c0ce17
commit
c00cfc735a
|
|
@ -7,6 +7,11 @@ import unittest
|
|||
from unittest.mock import patch, MagicMock
|
||||
from jwcrypto import jwt, jwk
|
||||
|
||||
try:
|
||||
import redis
|
||||
except ImportError:
|
||||
redis = None
|
||||
|
||||
from websockify.token_plugins import parse_source_args, ReadOnlyTokenFile, JWTTokenApi, TokenRedis
|
||||
|
||||
|
||||
|
|
@ -206,9 +211,7 @@ class JWSTokenTestCase(unittest.TestCase):
|
|||
|
||||
class TokenRedisTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
try:
|
||||
import redis
|
||||
except ImportError:
|
||||
if redis is None:
|
||||
patcher = patch.dict(sys.modules, {'redis': MagicMock()})
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@ import re
|
|||
import json
|
||||
from pathlib import Path
|
||||
|
||||
try:
|
||||
import redis
|
||||
except ImportError:
|
||||
redis = None
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_SOURCE_SPLIT_REGEX = re.compile(
|
||||
|
|
@ -256,9 +261,7 @@ class TokenRedis(BasePlugin):
|
|||
pip install redis
|
||||
"""
|
||||
def __init__(self, src):
|
||||
try:
|
||||
import redis
|
||||
except ImportError:
|
||||
if redis is None:
|
||||
logger.error("Unable to load redis module")
|
||||
sys.exit()
|
||||
# Default values
|
||||
|
|
@ -314,9 +317,7 @@ class TokenRedis(BasePlugin):
|
|||
sys.exit()
|
||||
|
||||
def lookup(self, token):
|
||||
try:
|
||||
import redis
|
||||
except ImportError:
|
||||
if redis is None:
|
||||
logger.error("package redis not found, are you sure you've installed them correctly?")
|
||||
sys.exit()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue