diff options
author | Pierre Ossman <ossman@cendio.se> | 2019-05-24 12:56:23 +0200 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2019-05-24 12:56:23 +0200 |
commit | 01a184f4a986b5001551e5e89c271b0a78f6c832 (patch) | |
tree | 4044ffcd67e417da0a0ce145926620c72f014752 /websockify/token_plugins.py | |
parent | 70911c6d6ed7d05d2e8ffaba464efa18d045e582 (diff) | |
download | websockify-01a184f4a986b5001551e5e89c271b0a78f6c832.tar.gz |
Make TokenRedis optional
Most installations will not have redis or simplejson installed, so
avoid having them as a hard requirement unless actually using the
TokenRedis plugin.
Diffstat (limited to 'websockify/token_plugins.py')
-rw-r--r-- | websockify/token_plugins.py | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/websockify/token_plugins.py b/websockify/token_plugins.py index 92aec98..84bda93 100644 --- a/websockify/token_plugins.py +++ b/websockify/token_plugins.py @@ -135,22 +135,23 @@ class JWTTokenApi(BasePlugin): print("package jwcrypto not found, are you sure you've installed it correctly?", file=sys.stderr) return None -import sys - -if sys.version_info >= (2, 7): - import redis - import simplejson +class TokenRedis(object): + def __init__(self, src): + self._server, self._port = src.split(":") - class TokenRedis(object): - def __init__(self, src): - self._server, self._port = src.split(":") + def lookup(self, token): + try: + import redis + import simplejson + except ImportError as e: + print("package redis or simplejson not found, are you sure you've installed them correctly?", file=sys.stderr) + return None - def lookup(self, token): - client = redis.Redis(host=self._server,port=self._port) - stuff = client.get(token) - if stuff is None: - return None - else: - combo = simplejson.loads(stuff.decode("utf-8")) - pair = combo["host"] - return pair.split(':') + client = redis.Redis(host=self._server,port=self._port) + stuff = client.get(token) + if stuff is None: + return None + else: + combo = simplejson.loads(stuff.decode("utf-8")) + pair = combo["host"] + return pair.split(':') |