From 56ec5b8a03209ca6b39e64c5340873f5d5fb5eed Mon Sep 17 00:00:00 2001 From: "kuldeep.k@cisinlabs.com" Date: Thu, 25 Nov 2021 21:43:22 +0530 Subject: [PATCH] Created testmode decorator & routed command decorator through it --- src/api.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/api.py b/src/api.py index c5e39055..ad5a142a 100644 --- a/src/api.py +++ b/src/api.py @@ -304,15 +304,27 @@ class CommandHandler(type): return result +class testmode(object): # pylint: disable=too-few-public-methods + """Decorator to check testmode & route to command decorator""" + + def __init__(self, *aliases): + self.aliases = aliases + + def __call__(self, func): + """Testmode call method""" + + if not state.testmode: + return None + return command(self.aliases[0]).__call__(func) + + class command(object): # pylint: disable=too-few-public-methods """Decorator for API command method""" def __init__(self, *aliases): self.aliases = aliases def __call__(self, func): - if func.__name__ in ["HandleclearUISignalQueue", "HandleGetStatusBar"] \ - and not state.testmode: - return None + if BMConfigParser().safeGet( 'bitmessagesettings', 'apivariant') == 'legacy': def wrapper(*args): @@ -1427,7 +1439,7 @@ class BMRPCDispatcher(object): """Test two numeric params""" return a + b - @command('clearUISignalQueue') + @testmode('clearUISignalQueue') def HandleclearUISignalQueue(self): """clear UISignalQueue""" queues.UISignalQueue.queue.clear() @@ -1438,7 +1450,7 @@ class BMRPCDispatcher(object): """Update GUI statusbar message""" queues.UISignalQueue.put(('updateStatusBar', message)) - @command('getStatusBar') + @testmode('getStatusBar') def HandleGetStatusBar(self): """Get GUI statusbar message""" try: