summaryrefslogtreecommitdiff
path: root/wrappers
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-09-21 11:37:32 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-09-21 11:37:32 +0200
commit448c51d2142c186f0490b9d51c0d73beb3c76863 (patch)
tree4553269be84b58072a11645221649bcccd85c73f /wrappers
parent7dbc3bbe2ca65fb7ec200ab7aa713855b0bdc11d (diff)
Exports + Python: Do not panic on error for getting disco + servers
Diffstat (limited to 'wrappers')
-rw-r--r--wrappers/python/src/__init__.py10
-rw-r--r--wrappers/python/src/main.py21
2 files changed, 16 insertions, 15 deletions
diff --git a/wrappers/python/src/__init__.py b/wrappers/python/src/__init__.py
index ca07143..3bafc0e 100644
--- a/wrappers/python/src/__init__.py
+++ b/wrappers/python/src/__init__.py
@@ -169,8 +169,8 @@ lib.Register.argtypes, lib.Register.restype = [
], c_void_p
lib.GetDiscoOrganizations.argtypes, lib.GetDiscoOrganizations.restype = [
c_char_p
-], c_void_p
-lib.GetDiscoServers.argtypes, lib.GetDiscoServers.restype = [c_char_p], c_void_p
+], DataError
+lib.GetDiscoServers.argtypes, lib.GetDiscoServers.restype = [c_char_p], DataError
lib.GoBack.argtypes, lib.GoBack.restype = [c_char_p], None
lib.CancelOAuth.argtypes, lib.CancelOAuth.restype = [c_char_p], c_void_p
lib.SetProfileID.argtypes, lib.SetProfileID.restype = [c_char_p, c_char_p], c_void_p
@@ -198,7 +198,7 @@ lib.FreeDiscoServers.argtypes, lib.FreeDiscoServers.restype = [c_void_p], None
lib.FreeServer.argtypes, lib.FreeServer.restype = [c_void_p], None
lib.FreeServers.argtypes, lib.FreeServers.restype = [c_void_p], None
lib.InFSMState.argtypes, lib.InFSMState.restype = [c_void_p, c_int], int
-lib.GetSavedServers.argtypes, lib.GetSavedServers.restype = [c_char_p], c_void_p
+lib.GetSavedServers.argtypes, lib.GetSavedServers.restype = [c_char_p], DataError
class WrappedError:
@@ -269,8 +269,8 @@ def get_error(ptr: c_void_p) -> str:
return error.cause
-def get_data_error(data_error: DataError) -> Tuple[str, str]:
- data = get_ptr_string(data_error.data)
+def get_data_error(data_error: DataError, data_conv=get_ptr_string) -> Tuple[str, str]:
+ data = data_conv(data_error.data)
error = get_error(data_error.error)
return data, error
diff --git a/wrappers/python/src/main.py b/wrappers/python/src/main.py
index eaf81e8..1ee9dd7 100644
--- a/wrappers/python/src/main.py
+++ b/wrappers/python/src/main.py
@@ -1,4 +1,4 @@
-from . import lib, VPNStateChange, encode_args, decode_res
+from . import lib, VPNStateChange, encode_args, decode_res, get_data_error
from typing import Optional, Tuple
import threading
from .discovery import get_disco_organizations, get_disco_servers
@@ -88,21 +88,22 @@ class EduVPN(object):
raise Exception(register_err)
def get_disco_servers(self) -> str:
- servers = self.go_function_custom_decode(
- lib.GetDiscoServers, decode_func=get_disco_servers
+ servers, servers_err = self.go_function_custom_decode(
+ lib.GetDiscoServers, decode_func=lambda x: get_data_error(x, get_disco_servers)
)
- # if servers_err:
- # raise Exception(servers_err)
+ if servers_err:
+ raise Exception(servers_err)
return servers
def get_disco_organizations(self) -> str:
- organizations = self.go_function_custom_decode(
- lib.GetDiscoOrganizations, decode_func=get_disco_organizations
+ organizations, organizations_err = self.go_function_custom_decode(
+ lib.GetDiscoOrganizations, decode_func=lambda x: get_data_error(x, get_disco_organizations)
)
- # if organizations_err:
- # raise Exception(organizations_err)
+
+ if organizations_err:
+ raise Exception(organizations_err)
return organizations
@@ -253,5 +254,5 @@ class EduVPN(object):
def get_saved_servers(self) -> str:
return self.go_function_custom_decode(
- lib.GetSavedServers, decode_func=get_servers
+ lib.GetSavedServers, decode_func=lambda x: get_data_error(x, get_servers)
)