web-framework-api 1.0.1__tar.gz → 1.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {web_framework_api-1.0.1 → web_framework_api-1.0.3}/PKG-INFO +1 -1
- {web_framework_api-1.0.1 → web_framework_api-1.0.3}/pyproject.toml +1 -1
- {web_framework_api-1.0.1 → web_framework_api-1.0.3}/web_framework_api/WebFramework.py +133 -133
- {web_framework_api-1.0.1 → web_framework_api-1.0.3}/web_framework_api/exceptions/WebFrameworkException.py +18 -18
- {web_framework_api-1.0.1 → web_framework_api-1.0.3}/web_framework_api/utility/Config.py +319 -316
- {web_framework_api-1.0.1 → web_framework_api-1.0.3}/web_framework_api/utility/DLLHandler.py +11 -2
- {web_framework_api-1.0.1 → web_framework_api-1.0.3}/web_framework_api/utility/Utils.py +1 -1
- {web_framework_api-1.0.1 → web_framework_api-1.0.3}/README.md +0 -0
- {web_framework_api-1.0.1 → web_framework_api-1.0.3}/web_framework_api/__init__.py +0 -0
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
import ctypes
|
|
2
|
-
import os
|
|
3
|
-
from typing import Callable
|
|
4
|
-
|
|
5
|
-
from .utility import Config
|
|
6
|
-
from web_framework_api.utility.DLLHandler import DLLHandler
|
|
7
|
-
from web_framework_api.exceptions.WebFrameworkException import WebFrameworkException
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class WebFramework:
|
|
11
|
-
"""
|
|
12
|
-
Web server
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
def __init__(self, implementation: ctypes.c_void_p):
|
|
16
|
-
self.__implementation = implementation
|
|
17
|
-
self.__function_signature = ctypes.CFUNCTYPE(None)
|
|
18
|
-
self.__on_start_server = None
|
|
19
|
-
|
|
20
|
-
@classmethod
|
|
21
|
-
def from_path(cls, config_path: str) -> "WebFramework":
|
|
22
|
-
"""
|
|
23
|
-
|
|
24
|
-
:param config_path: Path to *.json config
|
|
25
|
-
:return:
|
|
26
|
-
"""
|
|
27
|
-
config_path = os.path.abspath(config_path)
|
|
28
|
-
|
|
29
|
-
if not os.path.exists(config_path):
|
|
30
|
-
raise FileNotFoundError(f"Path {config_path} doesn't exist")
|
|
31
|
-
|
|
32
|
-
exception = ctypes.c_void_p(0)
|
|
33
|
-
implementation = DLLHandler.get_instance().call_function("createWebFrameworkFromPath", ctypes.c_void_p,
|
|
34
|
-
ctypes.c_char_p(config_path.encode()),
|
|
35
|
-
ctypes.byref(exception))
|
|
36
|
-
|
|
37
|
-
if exception:
|
|
38
|
-
raise WebFrameworkException(exception.value)
|
|
39
|
-
|
|
40
|
-
return cls(implementation)
|
|
41
|
-
|
|
42
|
-
@classmethod
|
|
43
|
-
def from_string(cls, server_configuration: str, application_directory: str) -> "WebFramework":
|
|
44
|
-
"""
|
|
45
|
-
|
|
46
|
-
:param server_configuration: *.json config file content
|
|
47
|
-
:param application_directory: Working directory
|
|
48
|
-
:return:
|
|
49
|
-
"""
|
|
50
|
-
exception = ctypes.c_void_p(0)
|
|
51
|
-
implementation = DLLHandler.get_instance().call_function("createWebFrameworkFromString", ctypes.c_void_p,
|
|
52
|
-
ctypes.c_char_p(server_configuration.encode()),
|
|
53
|
-
ctypes.c_char_p(application_directory.encode()),
|
|
54
|
-
ctypes.byref(exception))
|
|
55
|
-
|
|
56
|
-
if exception:
|
|
57
|
-
raise WebFrameworkException(exception.value)
|
|
58
|
-
|
|
59
|
-
return cls(implementation)
|
|
60
|
-
|
|
61
|
-
@classmethod
|
|
62
|
-
def from_config(cls, config: Config) -> "WebFramework":
|
|
63
|
-
"""
|
|
64
|
-
|
|
65
|
-
:param config: Config instance
|
|
66
|
-
:return:
|
|
67
|
-
"""
|
|
68
|
-
exception = ctypes.c_void_p(0)
|
|
69
|
-
implementation = DLLHandler.get_instance().call_function("createWebFrameworkFromConfig", ctypes.c_void_p,
|
|
70
|
-
ctypes.c_uint64(config.implementation),
|
|
71
|
-
ctypes.byref(exception))
|
|
72
|
-
|
|
73
|
-
if exception:
|
|
74
|
-
raise WebFrameworkException(exception.value)
|
|
75
|
-
|
|
76
|
-
return cls(implementation)
|
|
77
|
-
|
|
78
|
-
def start(self, wait: bool = False, on_start_server: Callable[[], None] = None):
|
|
79
|
-
"""
|
|
80
|
-
Start server
|
|
81
|
-
:param wait: Wait until server stop(False doesn't work)
|
|
82
|
-
:param on_start_server: On start server callback
|
|
83
|
-
:return:
|
|
84
|
-
"""
|
|
85
|
-
if on_start_server is None:
|
|
86
|
-
def default_function():
|
|
87
|
-
pass
|
|
88
|
-
|
|
89
|
-
on_start_server = default_function
|
|
90
|
-
|
|
91
|
-
self.__on_start_server = on_start_server
|
|
92
|
-
exception = ctypes.c_void_p(0)
|
|
93
|
-
|
|
94
|
-
DLLHandler.get_instance().call_class_member_function("startWebFrameworkServer", None, self.__implementation,
|
|
95
|
-
wait,
|
|
96
|
-
self.__function_signature(self.__on_start_server),
|
|
97
|
-
ctypes.byref(exception))
|
|
98
|
-
|
|
99
|
-
if exception:
|
|
100
|
-
raise WebFrameworkException(exception.value)
|
|
101
|
-
|
|
102
|
-
def stop(self, wait: bool = True):
|
|
103
|
-
"""
|
|
104
|
-
Stop server
|
|
105
|
-
:param wait: Wait until server stop
|
|
106
|
-
:return:
|
|
107
|
-
"""
|
|
108
|
-
exception = ctypes.c_void_p(0)
|
|
109
|
-
DLLHandler.get_instance().call_class_member_function("stopWebFrameworkServer", None, self.__implementation,
|
|
110
|
-
wait,
|
|
111
|
-
ctypes.byref(exception))
|
|
112
|
-
|
|
113
|
-
if exception:
|
|
114
|
-
raise WebFrameworkException(exception.value)
|
|
115
|
-
|
|
116
|
-
def is_server_running(self) -> bool:
|
|
117
|
-
"""
|
|
118
|
-
Is server running
|
|
119
|
-
:return:
|
|
120
|
-
"""
|
|
121
|
-
|
|
122
|
-
exception = ctypes.c_void_p(0)
|
|
123
|
-
result = DLLHandler.get_instance().call_class_member_function("isServerRunning", ctypes.c_bool,
|
|
124
|
-
self.__implementation,
|
|
125
|
-
ctypes.byref(exception))
|
|
126
|
-
|
|
127
|
-
if exception:
|
|
128
|
-
raise WebFrameworkException(exception.value)
|
|
129
|
-
|
|
130
|
-
return result
|
|
131
|
-
|
|
132
|
-
def __del__(self):
|
|
133
|
-
DLLHandler.get_instance().
|
|
1
|
+
import ctypes
|
|
2
|
+
import os
|
|
3
|
+
from typing import Callable
|
|
4
|
+
|
|
5
|
+
from .utility import Config
|
|
6
|
+
from web_framework_api.utility.DLLHandler import DLLHandler
|
|
7
|
+
from web_framework_api.exceptions.WebFrameworkException import WebFrameworkException
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class WebFramework:
|
|
11
|
+
"""
|
|
12
|
+
Web server
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def __init__(self, implementation: ctypes.c_void_p):
|
|
16
|
+
self.__implementation = implementation
|
|
17
|
+
self.__function_signature = ctypes.CFUNCTYPE(None)
|
|
18
|
+
self.__on_start_server = None
|
|
19
|
+
|
|
20
|
+
@classmethod
|
|
21
|
+
def from_path(cls, config_path: str) -> "WebFramework":
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
:param config_path: Path to *.json config
|
|
25
|
+
:return:
|
|
26
|
+
"""
|
|
27
|
+
config_path = os.path.abspath(config_path)
|
|
28
|
+
|
|
29
|
+
if not os.path.exists(config_path):
|
|
30
|
+
raise FileNotFoundError(f"Path {config_path} doesn't exist")
|
|
31
|
+
|
|
32
|
+
exception = ctypes.c_void_p(0)
|
|
33
|
+
implementation = DLLHandler.get_instance().call_function("createWebFrameworkFromPath", ctypes.c_void_p,
|
|
34
|
+
ctypes.c_char_p(config_path.encode()),
|
|
35
|
+
ctypes.byref(exception))
|
|
36
|
+
|
|
37
|
+
if exception:
|
|
38
|
+
raise WebFrameworkException(exception.value)
|
|
39
|
+
|
|
40
|
+
return cls(implementation)
|
|
41
|
+
|
|
42
|
+
@classmethod
|
|
43
|
+
def from_string(cls, server_configuration: str, application_directory: str) -> "WebFramework":
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
:param server_configuration: *.json config file content
|
|
47
|
+
:param application_directory: Working directory
|
|
48
|
+
:return:
|
|
49
|
+
"""
|
|
50
|
+
exception = ctypes.c_void_p(0)
|
|
51
|
+
implementation = DLLHandler.get_instance().call_function("createWebFrameworkFromString", ctypes.c_void_p,
|
|
52
|
+
ctypes.c_char_p(server_configuration.encode()),
|
|
53
|
+
ctypes.c_char_p(application_directory.encode()),
|
|
54
|
+
ctypes.byref(exception))
|
|
55
|
+
|
|
56
|
+
if exception:
|
|
57
|
+
raise WebFrameworkException(exception.value)
|
|
58
|
+
|
|
59
|
+
return cls(implementation)
|
|
60
|
+
|
|
61
|
+
@classmethod
|
|
62
|
+
def from_config(cls, config: Config) -> "WebFramework":
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
:param config: Config instance
|
|
66
|
+
:return:
|
|
67
|
+
"""
|
|
68
|
+
exception = ctypes.c_void_p(0)
|
|
69
|
+
implementation = DLLHandler.get_instance().call_function("createWebFrameworkFromConfig", ctypes.c_void_p,
|
|
70
|
+
ctypes.c_uint64(config.implementation),
|
|
71
|
+
ctypes.byref(exception))
|
|
72
|
+
|
|
73
|
+
if exception:
|
|
74
|
+
raise WebFrameworkException(exception.value)
|
|
75
|
+
|
|
76
|
+
return cls(implementation)
|
|
77
|
+
|
|
78
|
+
def start(self, wait: bool = False, on_start_server: Callable[[], None] = None):
|
|
79
|
+
"""
|
|
80
|
+
Start server
|
|
81
|
+
:param wait: Wait until server stop(False doesn't work)
|
|
82
|
+
:param on_start_server: On start server callback
|
|
83
|
+
:return:
|
|
84
|
+
"""
|
|
85
|
+
if on_start_server is None:
|
|
86
|
+
def default_function():
|
|
87
|
+
pass
|
|
88
|
+
|
|
89
|
+
on_start_server = default_function
|
|
90
|
+
|
|
91
|
+
self.__on_start_server = on_start_server
|
|
92
|
+
exception = ctypes.c_void_p(0)
|
|
93
|
+
|
|
94
|
+
DLLHandler.get_instance().call_class_member_function("startWebFrameworkServer", None, self.__implementation,
|
|
95
|
+
wait,
|
|
96
|
+
self.__function_signature(self.__on_start_server),
|
|
97
|
+
ctypes.byref(exception))
|
|
98
|
+
|
|
99
|
+
if exception:
|
|
100
|
+
raise WebFrameworkException(exception.value)
|
|
101
|
+
|
|
102
|
+
def stop(self, wait: bool = True):
|
|
103
|
+
"""
|
|
104
|
+
Stop server
|
|
105
|
+
:param wait: Wait until server stop
|
|
106
|
+
:return:
|
|
107
|
+
"""
|
|
108
|
+
exception = ctypes.c_void_p(0)
|
|
109
|
+
DLLHandler.get_instance().call_class_member_function("stopWebFrameworkServer", None, self.__implementation,
|
|
110
|
+
wait,
|
|
111
|
+
ctypes.byref(exception))
|
|
112
|
+
|
|
113
|
+
if exception:
|
|
114
|
+
raise WebFrameworkException(exception.value)
|
|
115
|
+
|
|
116
|
+
def is_server_running(self) -> bool:
|
|
117
|
+
"""
|
|
118
|
+
Is server running
|
|
119
|
+
:return:
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
exception = ctypes.c_void_p(0)
|
|
123
|
+
result = DLLHandler.get_instance().call_class_member_function("isServerRunning", ctypes.c_bool,
|
|
124
|
+
self.__implementation,
|
|
125
|
+
ctypes.byref(exception))
|
|
126
|
+
|
|
127
|
+
if exception:
|
|
128
|
+
raise WebFrameworkException(exception.value)
|
|
129
|
+
|
|
130
|
+
return result
|
|
131
|
+
|
|
132
|
+
def __del__(self):
|
|
133
|
+
DLLHandler.get_instance().delete_web_framework(self.__implementation)
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import ctypes
|
|
2
|
-
|
|
3
|
-
from web_framework_api.utility.DLLHandler import DLLHandler
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class WebFrameworkException(Exception):
|
|
7
|
-
"""
|
|
8
|
-
Exception class for WebFramework exceptions
|
|
9
|
-
"""
|
|
10
|
-
def __init__(self, implementation: ctypes.c_void_p):
|
|
11
|
-
self.__implementation = implementation
|
|
12
|
-
|
|
13
|
-
def __str__(self) -> str:
|
|
14
|
-
return DLLHandler.get_instance().call_function("getErrorMessage", ctypes.c_char_p,
|
|
15
|
-
ctypes.c_uint64(self.__implementation)).decode()
|
|
16
|
-
|
|
17
|
-
def __del__(self):
|
|
18
|
-
DLLHandler.get_instance().
|
|
1
|
+
import ctypes
|
|
2
|
+
|
|
3
|
+
from web_framework_api.utility.DLLHandler import DLLHandler
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class WebFrameworkException(Exception):
|
|
7
|
+
"""
|
|
8
|
+
Exception class for WebFramework exceptions
|
|
9
|
+
"""
|
|
10
|
+
def __init__(self, implementation: ctypes.c_void_p):
|
|
11
|
+
self.__implementation = implementation
|
|
12
|
+
|
|
13
|
+
def __str__(self) -> str:
|
|
14
|
+
return DLLHandler.get_instance().call_function("getErrorMessage", ctypes.c_char_p,
|
|
15
|
+
ctypes.c_uint64(self.__implementation)).decode()
|
|
16
|
+
|
|
17
|
+
def __del__(self):
|
|
18
|
+
DLLHandler.get_instance().delete_web_framework_exception(self.__implementation)
|
|
@@ -1,316 +1,319 @@
|
|
|
1
|
-
import ctypes
|
|
2
|
-
from typing import List
|
|
3
|
-
|
|
4
|
-
from multipledispatch import dispatch
|
|
5
|
-
|
|
6
|
-
from web_framework_api.utility.DLLHandler import DLLHandler
|
|
7
|
-
from web_framework_api.exceptions.WebFrameworkException import WebFrameworkException
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class Config:
|
|
11
|
-
"""
|
|
12
|
-
Config file representation
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
def __init__(self, implementation: ctypes.c_void_p):
|
|
16
|
-
self.implementation = implementation
|
|
17
|
-
|
|
18
|
-
@classmethod
|
|
19
|
-
def from_path(cls, config_path: str) -> "Config":
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
:param config_path: Path to *.json config file
|
|
23
|
-
:return:
|
|
24
|
-
"""
|
|
25
|
-
exception = ctypes.c_void_p(0)
|
|
26
|
-
implementation = DLLHandler.get_instance().call_function("createConfigFromPath", ctypes.c_void_p,
|
|
27
|
-
ctypes.c_char_p(config_path.encode()),
|
|
28
|
-
ctypes.byref(exception))
|
|
29
|
-
|
|
30
|
-
if exception:
|
|
31
|
-
raise WebFrameworkException(exception.value)
|
|
32
|
-
|
|
33
|
-
return cls(implementation)
|
|
34
|
-
|
|
35
|
-
@classmethod
|
|
36
|
-
def from_string(cls, server_configuration: str, application_directory: str) -> "Config":
|
|
37
|
-
"""
|
|
38
|
-
|
|
39
|
-
:param server_configuration: *.json config file content
|
|
40
|
-
:param application_directory: Working directory
|
|
41
|
-
:return:
|
|
42
|
-
"""
|
|
43
|
-
exception = ctypes.c_void_p(0)
|
|
44
|
-
implementation = DLLHandler.get_instance().call_function("createConfigFromString", ctypes.c_void_p,
|
|
45
|
-
ctypes.c_char_p(server_configuration.encode()),
|
|
46
|
-
ctypes.c_char_p(application_directory.encode()),
|
|
47
|
-
ctypes.byref(exception))
|
|
48
|
-
|
|
49
|
-
if exception:
|
|
50
|
-
raise WebFrameworkException(exception.value)
|
|
51
|
-
|
|
52
|
-
return cls(implementation)
|
|
53
|
-
|
|
54
|
-
@dispatch(str, str, bool)
|
|
55
|
-
def override_configuration(self, key: str, value: str, recursive: bool = True) -> "Config":
|
|
56
|
-
"""
|
|
57
|
-
Override string
|
|
58
|
-
:param key: JSON key
|
|
59
|
-
:param value: New string value
|
|
60
|
-
:param recursive: Recursive search for key
|
|
61
|
-
:return: self
|
|
62
|
-
"""
|
|
63
|
-
exception = ctypes.c_void_p(0)
|
|
64
|
-
|
|
65
|
-
DLLHandler.get_instance().call_class_member_function("overrideConfigurationString", None, self.implementation,
|
|
66
|
-
ctypes.c_char_p(key.encode()),
|
|
67
|
-
ctypes.c_char_p(value.encode()),
|
|
68
|
-
recursive, ctypes.byref(exception))
|
|
69
|
-
|
|
70
|
-
if exception:
|
|
71
|
-
raise WebFrameworkException(exception.value)
|
|
72
|
-
|
|
73
|
-
return self
|
|
74
|
-
|
|
75
|
-
@dispatch(str, int, bool)
|
|
76
|
-
def override_configuration(self, key: str, value: int, recursive: bool = True) -> "Config":
|
|
77
|
-
"""
|
|
78
|
-
Override integer
|
|
79
|
-
:param key: JSON key
|
|
80
|
-
:param value: New integer value
|
|
81
|
-
:param recursive: Recursive search for key
|
|
82
|
-
:return: self
|
|
83
|
-
"""
|
|
84
|
-
exception = ctypes.c_void_p(0)
|
|
85
|
-
|
|
86
|
-
DLLHandler.get_instance().call_class_member_function("overrideConfigurationInteger", None, self.implementation,
|
|
87
|
-
ctypes.c_char_p(key.encode()), ctypes.c_int64(value),
|
|
88
|
-
recursive, ctypes.byref(exception))
|
|
89
|
-
|
|
90
|
-
if exception:
|
|
91
|
-
raise WebFrameworkException(exception.value)
|
|
92
|
-
|
|
93
|
-
return self
|
|
94
|
-
|
|
95
|
-
@dispatch(str, bool, bool)
|
|
96
|
-
def override_configuration(self, key: str, value: bool, recursive: bool = True) -> "Config":
|
|
97
|
-
"""
|
|
98
|
-
Override bool
|
|
99
|
-
:param key: JSON key
|
|
100
|
-
:param value: New bool value
|
|
101
|
-
:param recursive: Recursive search for key
|
|
102
|
-
:return: self
|
|
103
|
-
"""
|
|
104
|
-
exception = ctypes.c_void_p(0)
|
|
105
|
-
|
|
106
|
-
DLLHandler.get_instance().call_class_member_function("overrideConfigurationBoolean", None, self.implementation,
|
|
107
|
-
ctypes.c_char_p(key.encode()), value,
|
|
108
|
-
recursive, ctypes.byref(exception))
|
|
109
|
-
|
|
110
|
-
if exception:
|
|
111
|
-
raise WebFrameworkException(exception.value)
|
|
112
|
-
|
|
113
|
-
return self
|
|
114
|
-
|
|
115
|
-
def override_configuration_string_array(self, key: str, value: List[str], recursive: bool = True) -> "Config":
|
|
116
|
-
"""
|
|
117
|
-
Override string array
|
|
118
|
-
:param key: JSON key
|
|
119
|
-
:param value: New string array value
|
|
120
|
-
:param recursive: Recursive search for key
|
|
121
|
-
:return: self
|
|
122
|
-
"""
|
|
123
|
-
exception = ctypes.c_void_p(0)
|
|
124
|
-
|
|
125
|
-
data = (ctypes.c_char_p * len(value))()
|
|
126
|
-
|
|
127
|
-
for i in range(len(value)):
|
|
128
|
-
data[i] = value[i].encode()
|
|
129
|
-
|
|
130
|
-
DLLHandler.get_instance().call_class_member_function("overrideConfigurationStringArray", None,
|
|
131
|
-
self.implementation,
|
|
132
|
-
ctypes.c_char_p(key.encode()), ctypes.pointer(data),
|
|
133
|
-
recursive, ctypes.c_int64(len(value)),
|
|
134
|
-
ctypes.byref(exception))
|
|
135
|
-
|
|
136
|
-
if exception:
|
|
137
|
-
raise WebFrameworkException(exception.value)
|
|
138
|
-
|
|
139
|
-
return self
|
|
140
|
-
|
|
141
|
-
def override_configuration_integer_array(self, key: str, value: List[int], recursive: bool = True) -> "Config":
|
|
142
|
-
"""
|
|
143
|
-
Override integer array
|
|
144
|
-
:param key: JSON key
|
|
145
|
-
:param value: New integer array value
|
|
146
|
-
:param recursive: Recursive search for key
|
|
147
|
-
:return: self
|
|
148
|
-
"""
|
|
149
|
-
exception = ctypes.c_void_p(0)
|
|
150
|
-
|
|
151
|
-
data = (ctypes.c_int64 * len(value))()
|
|
152
|
-
|
|
153
|
-
for i in range(len(value)):
|
|
154
|
-
data[i] = value[i]
|
|
155
|
-
|
|
156
|
-
DLLHandler.get_instance().call_class_member_function("overrideConfigurationIntegerArray", None,
|
|
157
|
-
self.implementation,
|
|
158
|
-
ctypes.c_char_p(key.encode()), ctypes.pointer(data),
|
|
159
|
-
recursive, ctypes.c_int64(len(value)),
|
|
160
|
-
ctypes.byref(exception))
|
|
161
|
-
|
|
162
|
-
if exception:
|
|
163
|
-
raise WebFrameworkException(exception.value)
|
|
164
|
-
|
|
165
|
-
return self
|
|
166
|
-
|
|
167
|
-
def override_base_path(self, base_path: str) -> "Config":
|
|
168
|
-
"""
|
|
169
|
-
Override config file directory
|
|
170
|
-
:param base_path: New base path
|
|
171
|
-
:return: self
|
|
172
|
-
"""
|
|
173
|
-
|
|
174
|
-
exception = ctypes.c_void_p(0)
|
|
175
|
-
|
|
176
|
-
DLLHandler.get_instance().call_class_member_function("overrideBasePath", None, self.implementation,
|
|
177
|
-
ctypes.c_char_p(base_path.encode()),
|
|
178
|
-
ctypes.byref(exception))
|
|
179
|
-
|
|
180
|
-
if exception:
|
|
181
|
-
raise WebFrameworkException(exception.value)
|
|
182
|
-
|
|
183
|
-
return self
|
|
184
|
-
|
|
185
|
-
def get_configuration_string(self, key: str, recursive: bool = True) -> str:
|
|
186
|
-
"""
|
|
187
|
-
Get string from config
|
|
188
|
-
:param key: Config key
|
|
189
|
-
:param recursive: Search recursively
|
|
190
|
-
:return: Config string value
|
|
191
|
-
"""
|
|
192
|
-
|
|
193
|
-
exception = ctypes.c_void_p(0)
|
|
194
|
-
|
|
195
|
-
handler = DLLHandler.get_instance()
|
|
196
|
-
string_implementation = handler.call_class_member_function("getConfigurationString",
|
|
197
|
-
ctypes.c_void_p,
|
|
198
|
-
self.implementation,
|
|
199
|
-
ctypes.c_char_p(key.encode()),
|
|
200
|
-
recursive, ctypes.byref(exception))
|
|
201
|
-
|
|
202
|
-
if exception:
|
|
203
|
-
raise WebFrameworkException(exception.value)
|
|
204
|
-
|
|
205
|
-
result_ptr = handler.call_function("getDataFromString", ctypes.c_char_p,
|
|
206
|
-
ctypes.c_uint64(string_implementation))
|
|
207
|
-
|
|
208
|
-
result = str(result_ptr.decode())
|
|
209
|
-
|
|
210
|
-
handler.
|
|
211
|
-
|
|
212
|
-
return result
|
|
213
|
-
|
|
214
|
-
def get_configuration_integer(self, key: str, recursive: bool = True) -> int:
|
|
215
|
-
"""
|
|
216
|
-
Get integer from config
|
|
217
|
-
:param key: Config key
|
|
218
|
-
:param recursive: Search recursively
|
|
219
|
-
:return: Config integer value
|
|
220
|
-
"""
|
|
221
|
-
|
|
222
|
-
exception = ctypes.c_void_p(0)
|
|
223
|
-
|
|
224
|
-
result = DLLHandler.get_instance().call_class_member_function("getConfigurationInteger",
|
|
225
|
-
ctypes.c_int64,
|
|
226
|
-
self.implementation,
|
|
227
|
-
ctypes.c_char_p(key.encode()),
|
|
228
|
-
recursive, ctypes.byref(exception))
|
|
229
|
-
if exception:
|
|
230
|
-
raise WebFrameworkException(exception.value)
|
|
231
|
-
|
|
232
|
-
return result
|
|
233
|
-
|
|
234
|
-
def get_configuration_boolean(self, key: str, recursive: bool = True) -> bool:
|
|
235
|
-
"""
|
|
236
|
-
Get boolean from config
|
|
237
|
-
:param key: Config key
|
|
238
|
-
:param recursive: Search recursively
|
|
239
|
-
:return: Config boolean value
|
|
240
|
-
"""
|
|
241
|
-
|
|
242
|
-
exception = ctypes.c_void_p(0)
|
|
243
|
-
|
|
244
|
-
result = DLLHandler.get_instance().call_class_member_function("getConfigurationBoolean",
|
|
245
|
-
ctypes.c_bool,
|
|
246
|
-
self.implementation,
|
|
247
|
-
ctypes.c_char_p(key.encode()),
|
|
248
|
-
recursive, ctypes.byref(exception))
|
|
249
|
-
if exception:
|
|
250
|
-
raise WebFrameworkException(exception.value)
|
|
251
|
-
|
|
252
|
-
return result
|
|
253
|
-
|
|
254
|
-
def get_configuration(self) -> str:
|
|
255
|
-
"""
|
|
256
|
-
Get current config JSON string data
|
|
257
|
-
:return:
|
|
258
|
-
"""
|
|
259
|
-
exception = ctypes.c_void_p(0)
|
|
260
|
-
|
|
261
|
-
handler = DLLHandler.get_instance()
|
|
262
|
-
string_implementation = handler.call_class_member_function("getConfiguration", ctypes.c_void_p,
|
|
263
|
-
self.implementation,
|
|
264
|
-
ctypes.byref(exception))
|
|
265
|
-
|
|
266
|
-
if exception:
|
|
267
|
-
raise WebFrameworkException(exception.value)
|
|
268
|
-
|
|
269
|
-
result_ptr = handler.call_function("getDataFromString", ctypes.c_char_p,
|
|
270
|
-
ctypes.c_uint64(string_implementation))
|
|
271
|
-
|
|
272
|
-
result = str(result_ptr.decode())
|
|
273
|
-
|
|
274
|
-
handler.
|
|
275
|
-
|
|
276
|
-
return result
|
|
277
|
-
|
|
278
|
-
def get_base_path(self) -> str:
|
|
279
|
-
"""
|
|
280
|
-
Get config file directory
|
|
281
|
-
:return:
|
|
282
|
-
"""
|
|
283
|
-
exception = ctypes.c_void_p(0)
|
|
284
|
-
|
|
285
|
-
handler = DLLHandler.get_instance()
|
|
286
|
-
string_implementation = handler.call_class_member_function("getBasePath", ctypes.c_void_p,
|
|
287
|
-
self.implementation,
|
|
288
|
-
ctypes.byref(exception))
|
|
289
|
-
|
|
290
|
-
if exception:
|
|
291
|
-
raise WebFrameworkException(exception.value)
|
|
292
|
-
|
|
293
|
-
result_ptr = handler.call_function("getDataFromString", ctypes.c_char_p,
|
|
294
|
-
ctypes.c_uint64(string_implementation))
|
|
295
|
-
|
|
296
|
-
result = str(result_ptr.decode())
|
|
297
|
-
|
|
298
|
-
handler.
|
|
299
|
-
|
|
300
|
-
return result
|
|
301
|
-
|
|
302
|
-
def get_raw_configuration(self) -> str:
|
|
303
|
-
"""
|
|
304
|
-
Get raw config JSON string data
|
|
305
|
-
:return:
|
|
306
|
-
"""
|
|
307
|
-
exception = ctypes.c_void_p(0)
|
|
308
|
-
|
|
309
|
-
result = DLLHandler.get_instance().call_class_member_function("getRawConfiguration", ctypes.c_char_p,
|
|
310
|
-
self.implementation,
|
|
311
|
-
ctypes.byref(exception))
|
|
312
|
-
|
|
313
|
-
if exception:
|
|
314
|
-
raise WebFrameworkException(exception.value)
|
|
315
|
-
|
|
316
|
-
return result.decode()
|
|
1
|
+
import ctypes
|
|
2
|
+
from typing import List
|
|
3
|
+
|
|
4
|
+
from multipledispatch import dispatch
|
|
5
|
+
|
|
6
|
+
from web_framework_api.utility.DLLHandler import DLLHandler
|
|
7
|
+
from web_framework_api.exceptions.WebFrameworkException import WebFrameworkException
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Config:
|
|
11
|
+
"""
|
|
12
|
+
Config file representation
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def __init__(self, implementation: ctypes.c_void_p):
|
|
16
|
+
self.implementation = implementation
|
|
17
|
+
|
|
18
|
+
@classmethod
|
|
19
|
+
def from_path(cls, config_path: str) -> "Config":
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
:param config_path: Path to *.json config file
|
|
23
|
+
:return:
|
|
24
|
+
"""
|
|
25
|
+
exception = ctypes.c_void_p(0)
|
|
26
|
+
implementation = DLLHandler.get_instance().call_function("createConfigFromPath", ctypes.c_void_p,
|
|
27
|
+
ctypes.c_char_p(config_path.encode()),
|
|
28
|
+
ctypes.byref(exception))
|
|
29
|
+
|
|
30
|
+
if exception:
|
|
31
|
+
raise WebFrameworkException(exception.value)
|
|
32
|
+
|
|
33
|
+
return cls(implementation)
|
|
34
|
+
|
|
35
|
+
@classmethod
|
|
36
|
+
def from_string(cls, server_configuration: str, application_directory: str) -> "Config":
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
:param server_configuration: *.json config file content
|
|
40
|
+
:param application_directory: Working directory
|
|
41
|
+
:return:
|
|
42
|
+
"""
|
|
43
|
+
exception = ctypes.c_void_p(0)
|
|
44
|
+
implementation = DLLHandler.get_instance().call_function("createConfigFromString", ctypes.c_void_p,
|
|
45
|
+
ctypes.c_char_p(server_configuration.encode()),
|
|
46
|
+
ctypes.c_char_p(application_directory.encode()),
|
|
47
|
+
ctypes.byref(exception))
|
|
48
|
+
|
|
49
|
+
if exception:
|
|
50
|
+
raise WebFrameworkException(exception.value)
|
|
51
|
+
|
|
52
|
+
return cls(implementation)
|
|
53
|
+
|
|
54
|
+
@dispatch(str, str, bool)
|
|
55
|
+
def override_configuration(self, key: str, value: str, recursive: bool = True) -> "Config":
|
|
56
|
+
"""
|
|
57
|
+
Override string
|
|
58
|
+
:param key: JSON key
|
|
59
|
+
:param value: New string value
|
|
60
|
+
:param recursive: Recursive search for key
|
|
61
|
+
:return: self
|
|
62
|
+
"""
|
|
63
|
+
exception = ctypes.c_void_p(0)
|
|
64
|
+
|
|
65
|
+
DLLHandler.get_instance().call_class_member_function("overrideConfigurationString", None, self.implementation,
|
|
66
|
+
ctypes.c_char_p(key.encode()),
|
|
67
|
+
ctypes.c_char_p(value.encode()),
|
|
68
|
+
recursive, ctypes.byref(exception))
|
|
69
|
+
|
|
70
|
+
if exception:
|
|
71
|
+
raise WebFrameworkException(exception.value)
|
|
72
|
+
|
|
73
|
+
return self
|
|
74
|
+
|
|
75
|
+
@dispatch(str, int, bool)
|
|
76
|
+
def override_configuration(self, key: str, value: int, recursive: bool = True) -> "Config":
|
|
77
|
+
"""
|
|
78
|
+
Override integer
|
|
79
|
+
:param key: JSON key
|
|
80
|
+
:param value: New integer value
|
|
81
|
+
:param recursive: Recursive search for key
|
|
82
|
+
:return: self
|
|
83
|
+
"""
|
|
84
|
+
exception = ctypes.c_void_p(0)
|
|
85
|
+
|
|
86
|
+
DLLHandler.get_instance().call_class_member_function("overrideConfigurationInteger", None, self.implementation,
|
|
87
|
+
ctypes.c_char_p(key.encode()), ctypes.c_int64(value),
|
|
88
|
+
recursive, ctypes.byref(exception))
|
|
89
|
+
|
|
90
|
+
if exception:
|
|
91
|
+
raise WebFrameworkException(exception.value)
|
|
92
|
+
|
|
93
|
+
return self
|
|
94
|
+
|
|
95
|
+
@dispatch(str, bool, bool)
|
|
96
|
+
def override_configuration(self, key: str, value: bool, recursive: bool = True) -> "Config":
|
|
97
|
+
"""
|
|
98
|
+
Override bool
|
|
99
|
+
:param key: JSON key
|
|
100
|
+
:param value: New bool value
|
|
101
|
+
:param recursive: Recursive search for key
|
|
102
|
+
:return: self
|
|
103
|
+
"""
|
|
104
|
+
exception = ctypes.c_void_p(0)
|
|
105
|
+
|
|
106
|
+
DLLHandler.get_instance().call_class_member_function("overrideConfigurationBoolean", None, self.implementation,
|
|
107
|
+
ctypes.c_char_p(key.encode()), value,
|
|
108
|
+
recursive, ctypes.byref(exception))
|
|
109
|
+
|
|
110
|
+
if exception:
|
|
111
|
+
raise WebFrameworkException(exception.value)
|
|
112
|
+
|
|
113
|
+
return self
|
|
114
|
+
|
|
115
|
+
def override_configuration_string_array(self, key: str, value: List[str], recursive: bool = True) -> "Config":
|
|
116
|
+
"""
|
|
117
|
+
Override string array
|
|
118
|
+
:param key: JSON key
|
|
119
|
+
:param value: New string array value
|
|
120
|
+
:param recursive: Recursive search for key
|
|
121
|
+
:return: self
|
|
122
|
+
"""
|
|
123
|
+
exception = ctypes.c_void_p(0)
|
|
124
|
+
|
|
125
|
+
data = (ctypes.c_char_p * len(value))()
|
|
126
|
+
|
|
127
|
+
for i in range(len(value)):
|
|
128
|
+
data[i] = value[i].encode()
|
|
129
|
+
|
|
130
|
+
DLLHandler.get_instance().call_class_member_function("overrideConfigurationStringArray", None,
|
|
131
|
+
self.implementation,
|
|
132
|
+
ctypes.c_char_p(key.encode()), ctypes.pointer(data),
|
|
133
|
+
recursive, ctypes.c_int64(len(value)),
|
|
134
|
+
ctypes.byref(exception))
|
|
135
|
+
|
|
136
|
+
if exception:
|
|
137
|
+
raise WebFrameworkException(exception.value)
|
|
138
|
+
|
|
139
|
+
return self
|
|
140
|
+
|
|
141
|
+
def override_configuration_integer_array(self, key: str, value: List[int], recursive: bool = True) -> "Config":
|
|
142
|
+
"""
|
|
143
|
+
Override integer array
|
|
144
|
+
:param key: JSON key
|
|
145
|
+
:param value: New integer array value
|
|
146
|
+
:param recursive: Recursive search for key
|
|
147
|
+
:return: self
|
|
148
|
+
"""
|
|
149
|
+
exception = ctypes.c_void_p(0)
|
|
150
|
+
|
|
151
|
+
data = (ctypes.c_int64 * len(value))()
|
|
152
|
+
|
|
153
|
+
for i in range(len(value)):
|
|
154
|
+
data[i] = value[i]
|
|
155
|
+
|
|
156
|
+
DLLHandler.get_instance().call_class_member_function("overrideConfigurationIntegerArray", None,
|
|
157
|
+
self.implementation,
|
|
158
|
+
ctypes.c_char_p(key.encode()), ctypes.pointer(data),
|
|
159
|
+
recursive, ctypes.c_int64(len(value)),
|
|
160
|
+
ctypes.byref(exception))
|
|
161
|
+
|
|
162
|
+
if exception:
|
|
163
|
+
raise WebFrameworkException(exception.value)
|
|
164
|
+
|
|
165
|
+
return self
|
|
166
|
+
|
|
167
|
+
def override_base_path(self, base_path: str) -> "Config":
|
|
168
|
+
"""
|
|
169
|
+
Override config file directory
|
|
170
|
+
:param base_path: New base path
|
|
171
|
+
:return: self
|
|
172
|
+
"""
|
|
173
|
+
|
|
174
|
+
exception = ctypes.c_void_p(0)
|
|
175
|
+
|
|
176
|
+
DLLHandler.get_instance().call_class_member_function("overrideBasePath", None, self.implementation,
|
|
177
|
+
ctypes.c_char_p(base_path.encode()),
|
|
178
|
+
ctypes.byref(exception))
|
|
179
|
+
|
|
180
|
+
if exception:
|
|
181
|
+
raise WebFrameworkException(exception.value)
|
|
182
|
+
|
|
183
|
+
return self
|
|
184
|
+
|
|
185
|
+
def get_configuration_string(self, key: str, recursive: bool = True) -> str:
|
|
186
|
+
"""
|
|
187
|
+
Get string from config
|
|
188
|
+
:param key: Config key
|
|
189
|
+
:param recursive: Search recursively
|
|
190
|
+
:return: Config string value
|
|
191
|
+
"""
|
|
192
|
+
|
|
193
|
+
exception = ctypes.c_void_p(0)
|
|
194
|
+
|
|
195
|
+
handler = DLLHandler.get_instance()
|
|
196
|
+
string_implementation = handler.call_class_member_function("getConfigurationString",
|
|
197
|
+
ctypes.c_void_p,
|
|
198
|
+
self.implementation,
|
|
199
|
+
ctypes.c_char_p(key.encode()),
|
|
200
|
+
recursive, ctypes.byref(exception))
|
|
201
|
+
|
|
202
|
+
if exception:
|
|
203
|
+
raise WebFrameworkException(exception.value)
|
|
204
|
+
|
|
205
|
+
result_ptr = handler.call_function("getDataFromString", ctypes.c_char_p,
|
|
206
|
+
ctypes.c_uint64(string_implementation))
|
|
207
|
+
|
|
208
|
+
result = str(result_ptr.decode())
|
|
209
|
+
|
|
210
|
+
handler.delete_web_framework_string(string_implementation)
|
|
211
|
+
|
|
212
|
+
return result
|
|
213
|
+
|
|
214
|
+
def get_configuration_integer(self, key: str, recursive: bool = True) -> int:
|
|
215
|
+
"""
|
|
216
|
+
Get integer from config
|
|
217
|
+
:param key: Config key
|
|
218
|
+
:param recursive: Search recursively
|
|
219
|
+
:return: Config integer value
|
|
220
|
+
"""
|
|
221
|
+
|
|
222
|
+
exception = ctypes.c_void_p(0)
|
|
223
|
+
|
|
224
|
+
result = DLLHandler.get_instance().call_class_member_function("getConfigurationInteger",
|
|
225
|
+
ctypes.c_int64,
|
|
226
|
+
self.implementation,
|
|
227
|
+
ctypes.c_char_p(key.encode()),
|
|
228
|
+
recursive, ctypes.byref(exception))
|
|
229
|
+
if exception:
|
|
230
|
+
raise WebFrameworkException(exception.value)
|
|
231
|
+
|
|
232
|
+
return result
|
|
233
|
+
|
|
234
|
+
def get_configuration_boolean(self, key: str, recursive: bool = True) -> bool:
|
|
235
|
+
"""
|
|
236
|
+
Get boolean from config
|
|
237
|
+
:param key: Config key
|
|
238
|
+
:param recursive: Search recursively
|
|
239
|
+
:return: Config boolean value
|
|
240
|
+
"""
|
|
241
|
+
|
|
242
|
+
exception = ctypes.c_void_p(0)
|
|
243
|
+
|
|
244
|
+
result = DLLHandler.get_instance().call_class_member_function("getConfigurationBoolean",
|
|
245
|
+
ctypes.c_bool,
|
|
246
|
+
self.implementation,
|
|
247
|
+
ctypes.c_char_p(key.encode()),
|
|
248
|
+
recursive, ctypes.byref(exception))
|
|
249
|
+
if exception:
|
|
250
|
+
raise WebFrameworkException(exception.value)
|
|
251
|
+
|
|
252
|
+
return result
|
|
253
|
+
|
|
254
|
+
def get_configuration(self) -> str:
|
|
255
|
+
"""
|
|
256
|
+
Get current config JSON string data
|
|
257
|
+
:return:
|
|
258
|
+
"""
|
|
259
|
+
exception = ctypes.c_void_p(0)
|
|
260
|
+
|
|
261
|
+
handler = DLLHandler.get_instance()
|
|
262
|
+
string_implementation = handler.call_class_member_function("getConfiguration", ctypes.c_void_p,
|
|
263
|
+
self.implementation,
|
|
264
|
+
ctypes.byref(exception))
|
|
265
|
+
|
|
266
|
+
if exception:
|
|
267
|
+
raise WebFrameworkException(exception.value)
|
|
268
|
+
|
|
269
|
+
result_ptr = handler.call_function("getDataFromString", ctypes.c_char_p,
|
|
270
|
+
ctypes.c_uint64(string_implementation))
|
|
271
|
+
|
|
272
|
+
result = str(result_ptr.decode())
|
|
273
|
+
|
|
274
|
+
handler.delete_web_framework_string(string_implementation)
|
|
275
|
+
|
|
276
|
+
return result
|
|
277
|
+
|
|
278
|
+
def get_base_path(self) -> str:
|
|
279
|
+
"""
|
|
280
|
+
Get config file directory
|
|
281
|
+
:return:
|
|
282
|
+
"""
|
|
283
|
+
exception = ctypes.c_void_p(0)
|
|
284
|
+
|
|
285
|
+
handler = DLLHandler.get_instance()
|
|
286
|
+
string_implementation = handler.call_class_member_function("getBasePath", ctypes.c_void_p,
|
|
287
|
+
self.implementation,
|
|
288
|
+
ctypes.byref(exception))
|
|
289
|
+
|
|
290
|
+
if exception:
|
|
291
|
+
raise WebFrameworkException(exception.value)
|
|
292
|
+
|
|
293
|
+
result_ptr = handler.call_function("getDataFromString", ctypes.c_char_p,
|
|
294
|
+
ctypes.c_uint64(string_implementation))
|
|
295
|
+
|
|
296
|
+
result = str(result_ptr.decode())
|
|
297
|
+
|
|
298
|
+
handler.delete_web_framework_string(string_implementation)
|
|
299
|
+
|
|
300
|
+
return result
|
|
301
|
+
|
|
302
|
+
def get_raw_configuration(self) -> str:
|
|
303
|
+
"""
|
|
304
|
+
Get raw config JSON string data
|
|
305
|
+
:return:
|
|
306
|
+
"""
|
|
307
|
+
exception = ctypes.c_void_p(0)
|
|
308
|
+
|
|
309
|
+
result = DLLHandler.get_instance().call_class_member_function("getRawConfiguration", ctypes.c_char_p,
|
|
310
|
+
self.implementation,
|
|
311
|
+
ctypes.byref(exception))
|
|
312
|
+
|
|
313
|
+
if exception:
|
|
314
|
+
raise WebFrameworkException(exception.value)
|
|
315
|
+
|
|
316
|
+
return result.decode()
|
|
317
|
+
|
|
318
|
+
def __del__(self):
|
|
319
|
+
DLLHandler.get_instance().delete_web_framework_config(self.implementation)
|
|
@@ -75,5 +75,14 @@ class DLLHandler:
|
|
|
75
75
|
|
|
76
76
|
return function(ctypes.c_uint64(implementation), *args)
|
|
77
77
|
|
|
78
|
-
def
|
|
79
|
-
self.call_function("
|
|
78
|
+
def delete_web_framework_string(self, implementation: ctypes.c_void_p):
|
|
79
|
+
self.call_function("deleteWebFrameworkString", None, ctypes.c_uint64(implementation))
|
|
80
|
+
|
|
81
|
+
def delete_web_framework_config(self, implementation: ctypes.c_void_p):
|
|
82
|
+
self.call_function("deleteWebFrameworkConfig", None, ctypes.c_uint64(implementation))
|
|
83
|
+
|
|
84
|
+
def delete_web_framework(self, implementation: ctypes.c_void_p):
|
|
85
|
+
self.call_function("deleteWebFramework", None, ctypes.c_uint64(implementation))
|
|
86
|
+
|
|
87
|
+
def delete_web_framework_exception(self, implementation: ctypes.c_void_p):
|
|
88
|
+
self.call_function("deleteWebFrameworkException", None, ctypes.c_uint64(implementation))
|
|
File without changes
|
|
File without changes
|