summaryrefslogtreecommitdiff
path: root/wrappers/python/eduvpncommon/__init__.py
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-03-23 10:42:49 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-03-23 10:42:49 +0100
commited6073f2c2c6600063f2e5062937b7a2a1162eb2 (patch)
treed43109bb55546fc4815824579c4879b51e4c3605 /wrappers/python/eduvpncommon/__init__.py
parente9597dc652e8ca99141b0d66bfca3e24f233d430 (diff)
Python: Implement state callbacks using decorators
Diffstat (limited to 'wrappers/python/eduvpncommon/__init__.py')
-rw-r--r--wrappers/python/eduvpncommon/__init__.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/wrappers/python/eduvpncommon/__init__.py b/wrappers/python/eduvpncommon/__init__.py
index ff329a0..073af39 100644
--- a/wrappers/python/eduvpncommon/__init__.py
+++ b/wrappers/python/eduvpncommon/__init__.py
@@ -3,14 +3,20 @@ from collections import defaultdict
import pathlib
import platform
-_lib_prefixes = defaultdict(lambda: "lib", {
- "windows": "",
-})
-
-_lib_suffixes = defaultdict(lambda: ".so", {
- "windows": ".dll",
- "darwin": ".dylib",
-})
+_lib_prefixes = defaultdict(
+ lambda: "lib",
+ {
+ "windows": "",
+ },
+)
+
+_lib_suffixes = defaultdict(
+ lambda: ".so",
+ {
+ "windows": ".dll",
+ "darwin": ".dylib",
+ },
+)
_os = platform.system().lower()
@@ -19,9 +25,10 @@ _libfile = f"{_lib_prefixes[_os]}{_libname}{_lib_suffixes[_os]}"
# Library should have been copied to the lib/ folder
lib = cdll.LoadLibrary(str(pathlib.Path(__file__).parent / "lib" / _libfile))
+
class DataError(Structure):
- _fields_ = [('data', c_void_p),
- ('error', c_void_p)]
+ _fields_ = [("data", c_void_p), ("error", c_void_p)]
+
VPNStateChange = CFUNCTYPE(None, c_char_p, c_char_p, c_char_p)
@@ -33,6 +40,7 @@ lib.GetServersList.argtypes, lib.GetServersList.restype = [], DataError
# See https://stackoverflow.com/questions/13445568/python-ctypes-how-to-free-memory-getting-invalid-pointer-error
lib.FreeString.argtypes, lib.FreeString.restype = [c_void_p], None
+
def GetPtrString(ptr):
if ptr:
string = cast(ptr, c_char_p).value