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