diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-02-10 13:36:09 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-04-05 12:26:10 +0200 |
| commit | 53b31fa9f103d8262b7c1d28c5714238902e5081 (patch) | |
| tree | 5aa56e5e756f33f3753f5b5b4decdefe4782db61 /wrappers/python/eduvpncommon/__init__.py | |
| parent | 23e63807085b13a9b221c3374d05099559583011 (diff) | |
Move python library load to init and fix build
Signed-off-by: jwijenbergh <jeroenwijenbergh@protonmail.com>
Diffstat (limited to 'wrappers/python/eduvpncommon/__init__.py')
| -rw-r--r-- | wrappers/python/eduvpncommon/__init__.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/wrappers/python/eduvpncommon/__init__.py b/wrappers/python/eduvpncommon/__init__.py index e69de29..e9d0284 100644 --- a/wrappers/python/eduvpncommon/__init__.py +++ b/wrappers/python/eduvpncommon/__init__.py @@ -0,0 +1,30 @@ +from ctypes import * +from collections import defaultdict +import pathlib +import platform + +_lib_prefixes = defaultdict(lambda: "lib", { + "windows": "", +}) + +_lib_suffixes = defaultdict(lambda: ".so", { + "windows": ".dll", + "darwin": ".dylib", +}) + +_os = platform.system().lower() + +_libname = "eduvpn_common" +_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 GoSlice(Structure): + _fields_ = [("data", POINTER(c_char)), ("len", c_int64), ("cap", c_int64)] + + @staticmethod + def make(bs: bytes) -> "GoSlice": + return GoSlice((c_char * len(bs))(*bs), len(bs), len(bs)) + + |
