add decorator for versioning
This commit is contained in:
parent
4c0f211dac
commit
074177e90b
@ -67,6 +67,16 @@ else:
|
|||||||
# Helpers
|
# Helpers
|
||||||
#
|
#
|
||||||
|
|
||||||
|
def webapi(*versions):
|
||||||
|
def decorator(func):
|
||||||
|
def method(*args, **kwargs):
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
setattr(method, 'versions', versions)
|
||||||
|
setattr(method, 'api', True)
|
||||||
|
return method
|
||||||
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
def webApi(func):
|
def webApi(func):
|
||||||
func.webApi = True
|
func.webApi = True
|
||||||
return func
|
return func
|
||||||
@ -901,6 +911,24 @@ class AnkiConnect:
|
|||||||
return handler(**params)
|
return handler(**params)
|
||||||
|
|
||||||
|
|
||||||
|
def invoke(self, version, name, *args, **kwargs):
|
||||||
|
for method_name, method_body in inspect.getmembers(self, predicate=inspect.ismethod):
|
||||||
|
api_version_last = 0
|
||||||
|
api_name_last = None
|
||||||
|
|
||||||
|
if getattr(method_body, 'api', False):
|
||||||
|
for api_version, api_name in getattr(method_body, 'versions', []):
|
||||||
|
if api_version_last < api_version <= version:
|
||||||
|
api_version_last = api_version
|
||||||
|
api_name_last = api_name
|
||||||
|
|
||||||
|
if api_name_last is None and api_version_last == 0:
|
||||||
|
api_name_last = method_name
|
||||||
|
|
||||||
|
if api_name_last is not None and api_name_last == name:
|
||||||
|
method_body(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
@webApi
|
@webApi
|
||||||
def multi(self, actions):
|
def multi(self, actions):
|
||||||
return self.anki.multi(actions)
|
return self.anki.multi(actions)
|
||||||
|
Loading…
Reference in New Issue
Block a user