From cfc6b0d012060bd6506a818338877795259096b0 Mon Sep 17 00:00:00 2001 From: oakkitten Date: Wed, 30 Mar 2022 20:02:41 +0100 Subject: [PATCH] Move configuration defaults dict to module level So that it is importable by tests --- plugin/util.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/plugin/util.py b/plugin/util.py index e2d6741..0646cd8 100644 --- a/plugin/util.py +++ b/plugin/util.py @@ -65,22 +65,22 @@ def cardAnswer(card): return card.answer() -def setting(key): - defaults = { - 'apiKey': None, - 'apiLogPath': None, - 'apiPollInterval': 25, - 'apiVersion': 6, - 'webBacklog': 5, - 'webBindAddress': os.getenv('ANKICONNECT_BIND_ADDRESS', '127.0.0.1'), - 'webBindPort': 8765, - 'webCorsOrigin': os.getenv('ANKICONNECT_CORS_ORIGIN', None), - 'webCorsOriginList': ['http://localhost'], - 'ignoreOriginList': [], - 'webTimeout': 10000, - } +DEFAULT_CONFIG = { + 'apiKey': None, + 'apiLogPath': None, + 'apiPollInterval': 25, + 'apiVersion': 6, + 'webBacklog': 5, + 'webBindAddress': os.getenv('ANKICONNECT_BIND_ADDRESS', '127.0.0.1'), + 'webBindPort': 8765, + 'webCorsOrigin': os.getenv('ANKICONNECT_CORS_ORIGIN', None), + 'webCorsOriginList': ['http://localhost'], + 'ignoreOriginList': [], + 'webTimeout': 10000, +} +def setting(key): try: - return aqt.mw.addonManager.getConfig(__name__).get(key, defaults[key]) + return aqt.mw.addonManager.getConfig(__name__).get(key, DEFAULT_CONFIG[key]) except: raise Exception('setting {} not found'.format(key))