From cdba2c47ee748c2acb12bd8ff7ef8fbae6c2e50f Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 4 Jul 2017 11:29:09 -0700 Subject: [PATCH] improvements to python interop --- AnkiConnect.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/AnkiConnect.py b/AnkiConnect.py index 7de771b..a24a1db 100644 --- a/AnkiConnect.py +++ b/AnkiConnect.py @@ -567,12 +567,25 @@ class AnkiConnect: def handler(self, request): action = 'api_' + request.get('action', '') - params = request.get('params', {}) if hasattr(self, action): - try: - return getattr(self, action)(**params) - except TypeError: - return None + handler = getattr(self, action) + if callable(handler): + argsAll = handler.__code__.co_varnames[1:] + argsReq = argsAll + + argsDef = handler.__defaults__ + if argsDef is not None: + argsReq = argsAll[:-len(argsDef)] + + params = request.get('params', {}) + for argReq in argsReq: + if argReq not in params: + return + for param in params: + if param not in argsAll: + return + + handler(**params) def api_deckNames(self):