web-framework-api 1.0.0__py2.py3-none-any.whl

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.
@@ -0,0 +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().free(self.__implementation)
File without changes
@@ -0,0 +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().free(self.__implementation)
@@ -0,0 +1,316 @@
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.free(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.free(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.free(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()
@@ -0,0 +1,79 @@
1
+ import ctypes
2
+ import sys
3
+ import os
4
+
5
+ from pathlib import Path
6
+
7
+ from web_framework_api.utility.Utils import get_libraries
8
+
9
+
10
+ def initialize_web_framework(path_to_dll: str = ""):
11
+ """
12
+ Load WebFramework shared library
13
+ :param path_to_dll: Path to shared library without prefixes(lib for Linux) and file extensions(.dll, .so). By default, take path to WebFramework library from pip package
14
+ :return:
15
+ """
16
+ if DLLHandler.instance is not None:
17
+ return
18
+
19
+ shared_libraries_dir = os.path.abspath(
20
+ os.path.join(Path(__file__).parent.parent, "dll" if sys.platform == "win32" else "lib"))
21
+ download = False
22
+ empty_path_to_dll = len(path_to_dll) == 0
23
+
24
+ if len(path_to_dll) == 0:
25
+ path_to_dll = os.path.join(shared_libraries_dir, "WebFramework")
26
+ download = True
27
+
28
+ path_to_dll = os.path.abspath(path_to_dll)
29
+
30
+ if sys.platform == "win32":
31
+ path_to_dll = f"{path_to_dll}.dll"
32
+
33
+ os.environ["PATH"] += os.pathsep + f"{shared_libraries_dir}"
34
+ else:
35
+ path = Path(path_to_dll)
36
+ path_to_dll = f"{path.parent}/lib{path.name}.so"
37
+
38
+ if empty_path_to_dll and ("LD_LIBRARY_PATH" in os.environ and shared_libraries_dir not in os.environ[
39
+ "LD_LIBRARY_PATH"]) or "LD_LIBRARY_PATH" not in os.environ:
40
+ raise Exception(f"{shared_libraries_dir} not in LD_LIBRARY_PATH")
41
+
42
+ if not os.path.exists(path_to_dll):
43
+ if not download:
44
+ raise FileNotFoundError(f"Path {path_to_dll} doesn't exist")
45
+ else:
46
+ get_libraries(shared_libraries_dir)
47
+
48
+ DLLHandler.instance = DLLHandler(path_to_dll)
49
+
50
+
51
+ class DLLHandler:
52
+ instance = None
53
+
54
+ def __init__(self, path_to_dll: str):
55
+ self.__handle = ctypes.CDLL(path_to_dll)
56
+
57
+ @classmethod
58
+ def get_instance(cls):
59
+ if cls.instance is None:
60
+ raise Exception("WebFramework must be initialized with initialize_web_framework function")
61
+
62
+ return cls.instance
63
+
64
+ def call_function(self, function_name: str, return_type, *args):
65
+ function = self.__handle[function_name]
66
+
67
+ function.restype = return_type
68
+
69
+ return function(*args)
70
+
71
+ def call_class_member_function(self, function_name: str, return_type, implementation: ctypes.c_void_p, *args):
72
+ function = self.__handle[function_name]
73
+
74
+ function.restype = return_type
75
+
76
+ return function(ctypes.c_uint64(implementation), *args)
77
+
78
+ def free(self, implementation: ctypes.c_void_p):
79
+ self.call_function("deleteWebFrameworkObject", None, ctypes.c_uint64(implementation))
@@ -0,0 +1,86 @@
1
+ import os.path
2
+ import shutil
3
+ import sys
4
+ import zipfile
5
+
6
+ import requests
7
+
8
+ from tqdm import tqdm
9
+
10
+ WEB_FRAMEWORK_MAJOR_VERSION = "0"
11
+ WEB_FRAMEWORK_MINOR_VERSION = "5"
12
+ WEB_FRAMEWORK_LIBRARIES_FILE_NAME = "libraries.zip"
13
+ WEB_FRAMEWORK_DOWNLOAD_BLOCK_SIZE = 1024
14
+
15
+
16
+ def download_libraries(download_path: str):
17
+ url = get_url()
18
+ response = requests.get(url, stream=True)
19
+
20
+ total_size = int(response.headers.get("content-length", 0))
21
+
22
+ with tqdm(total=total_size, unit="B", unit_scale=True) as progress_bar:
23
+ progress_bar.set_description(f"Downloading {url}")
24
+
25
+ with open(f"{download_path}/{WEB_FRAMEWORK_LIBRARIES_FILE_NAME}", "wb") as file:
26
+ for data in response.iter_content(WEB_FRAMEWORK_DOWNLOAD_BLOCK_SIZE):
27
+ progress_bar.update(len(data))
28
+ file.write(data)
29
+
30
+ if total_size != 0 and progress_bar.n != total_size:
31
+ raise RuntimeError("Could not download file")
32
+
33
+ return f"{download_path}/{WEB_FRAMEWORK_LIBRARIES_FILE_NAME}"
34
+
35
+
36
+ def unzip_libraries(path_to_zip: str, output_path: str):
37
+ with zipfile.ZipFile(path_to_zip, "r") as zip_file:
38
+ zip_file.extractall(output_path)
39
+
40
+
41
+ def copy_libraries(libraries_directory: str):
42
+ if sys.platform == "win32":
43
+ directory_path = os.path.join(libraries_directory, "ReleaseDLL_Windows", "dll")
44
+
45
+ for file in os.listdir(directory_path):
46
+ shutil.copy(os.path.join(directory_path, file), libraries_directory)
47
+
48
+ else:
49
+ directory_path = os.path.join(libraries_directory, "ReleaseDLL_Linux", "lib")
50
+
51
+ for file in os.listdir(directory_path):
52
+ if file.endswith(".so"):
53
+ shutil.copy(os.path.join(directory_path, file), libraries_directory)
54
+
55
+
56
+ def remove_files(libraries_directory: str):
57
+ for file in os.listdir(libraries_directory):
58
+ if os.path.isdir(os.path.join(libraries_directory, file)):
59
+ shutil.rmtree(os.path.join(libraries_directory, file))
60
+
61
+ os.remove(os.path.join(libraries_directory, WEB_FRAMEWORK_LIBRARIES_FILE_NAME))
62
+
63
+
64
+ def create_directories(libraries_directory: str):
65
+ if sys.platform == "win32":
66
+ os.makedirs(os.path.join(libraries_directory, "dll"))
67
+ else:
68
+ os.makedirs(os.path.join(libraries_directory, "lib"))
69
+
70
+ def get_url():
71
+ if sys.platform == "win32":
72
+ return f"https://github.com/LazyPanda07/WebFramework/releases/download/v3.{WEB_FRAMEWORK_MAJOR_VERSION}.{WEB_FRAMEWORK_MINOR_VERSION}/windows.zip"
73
+ else:
74
+ return f"https://github.com/LazyPanda07/WebFramework/releases/download/v3.{WEB_FRAMEWORK_MAJOR_VERSION}.{WEB_FRAMEWORK_MINOR_VERSION}/linux.zip"
75
+
76
+
77
+ def get_libraries(libraries_directory: str):
78
+ create_directories(libraries_directory)
79
+
80
+ zip_path = download_libraries(libraries_directory)
81
+
82
+ unzip_libraries(zip_path, libraries_directory)
83
+
84
+ copy_libraries(libraries_directory)
85
+
86
+ remove_files(libraries_directory)
@@ -0,0 +1,165 @@
1
+ Metadata-Version: 2.3
2
+ Name: web_framework_api
3
+ Version: 1.0.0
4
+ Summary: Python API for WebFramework
5
+ Project-URL: Repository, http://github.com/LazyPanda07/WebFramework
6
+ Project-URL: Wiki, http://github.com/LazyPanda07/WebFramework/wiki
7
+ Author-email: LazyPanda07 <semengricenko@gmail.com>
8
+ Maintainer-email: LazyPanda07 <semengricenko@gmail.com>
9
+ License: MIT License
10
+ Keywords: Web
11
+ Requires-Dist: multipledispatch
12
+ Requires-Dist: requests
13
+ Requires-Dist: tqdm
14
+ Description-Content-Type: text/markdown
15
+
16
+ C++ HTTP/HTTPS server with Python API
17
+
18
+
19
+ * [Quick start](#quick-start)
20
+ * [main.py](#mainpy)
21
+ * [Settings](#settings)
22
+ * [Config](#config)
23
+ * [Run sample](#run-sample)
24
+ * [Executors](#executors)
25
+
26
+
27
+ ## Quick start
28
+ Server needs few files to run:
29
+ * [web.json](#settings) with routes
30
+ * [Executors](#executors)
31
+ * [Windows](https://github.com/LazyPanda07/WebFramework/releases/download/Assets/windows.zip)
32
+ * [Linux](https://github.com/LazyPanda07/WebFramework/releases/download/Assets/linux.zip)
33
+ * [config.json](#config) with server settings
34
+ All these files must be in the same directory as ```main.py```
35
+
36
+
37
+ ### main.py
38
+ ```python
39
+ from web_framework_api.WebFramework import WebFramework # Server
40
+ from web_framework_api.utility.DLLHandler import initialize_web_framework # WebFramework initialization
41
+ from web_framework_api.exceptions.WebFrameworkException import WebFrameworkException # Exception
42
+
43
+ def on_start():
44
+ print("Server is running")
45
+
46
+ if __name__ == '__main__':
47
+ try:
48
+ initialize_web_framework() # Load WebFramework shared library
49
+
50
+ server = WebFramework.from_path("config.json") # Create server
51
+
52
+ server.start(True, on_start) # Start server and wait
53
+ except WebFrameworkException as exception:
54
+ print(exception)
55
+
56
+ exit(-1)
57
+ ```
58
+
59
+
60
+ ### Settings
61
+ ```web.json```
62
+ ```json
63
+ {
64
+ "HelloExecutor": {
65
+ "route": "",
66
+ "loadType": "initialization"
67
+ }
68
+ }
69
+ ```
70
+
71
+
72
+ ### Config
73
+ ```config.json```
74
+ ```json
75
+ {
76
+ "WebServer": {
77
+ "ip": "0.0.0.0",
78
+ "port": 8080,
79
+ "timeout": 0
80
+ },
81
+ "WebFramework": {
82
+ "settingsPaths": [
83
+ "web.json"
84
+ ],
85
+ "loadSources": [
86
+ "hello_executor"
87
+ ],
88
+ "assetsPath": "assets",
89
+ "templatesPath": "templates",
90
+ "cachingSize": 536870912,
91
+ "webServerType": "multiThreaded",
92
+ "HTTPS": {
93
+ "useHTTPS": false,
94
+ "pathToCertificate": "certificates/cert.pem",
95
+ "pathToKey": "certificates/key.pem"
96
+ },
97
+ "defaultAssetsPath": "WebFrameworkAssets"
98
+ },
99
+ "Logging": {
100
+ "usingLogging": false,
101
+ "dateFormat": "DMY",
102
+ "logFileSize": 134217728
103
+ },
104
+ "ThreadPoolServer": {
105
+ "threadCount": 0
106
+ }
107
+ }
108
+ ```
109
+
110
+
111
+ ### Run sample
112
+ After running server open url [127.0.0.1:8080](http://127.0.0.1:8080).
113
+ You will see response from server
114
+ ```json
115
+ {
116
+ "message": "Hello, World!"
117
+ }
118
+ ```
119
+
120
+
121
+ ## Executors
122
+ Executors are C++ classes that responsible for giving responses for their route(url).
123
+ Source code of HelloExecutor from example
124
+ ```HelloExecutor.h```
125
+ ```cpp
126
+ #pragma once
127
+
128
+ #include "Executors/BaseStatelessExecutor.h"
129
+
130
+ namespace executors
131
+ {
132
+ class HelloExecutor : public framework::BaseStatelessExecutor
133
+ {
134
+ public:
135
+ HelloExecutor() = default;
136
+
137
+ void doGet(framework::HTTPRequest& request, framework::HTTPResponse& response) override;
138
+
139
+ ~HelloExecutor() = default;
140
+ };
141
+ }
142
+ ```
143
+ ```HelloExecutor.cpp```
144
+ ```cpp
145
+ #include "HelloExecutor.h"
146
+
147
+ #include "JSONBuilder.h"
148
+
149
+ namespace executors
150
+ {
151
+ void HelloExecutor::doGet(framework::HTTPRequest& request, framework::HTTPResponse& response)
152
+ {
153
+ response.addBody(json::JSONBuilder(CP_UTF8).appendString("message", "Hello, World!"));
154
+ }
155
+
156
+ DECLARE_EXECUTOR(HelloExecutor);
157
+ }
158
+ ```
159
+ More information you can find in [wiki](https://github.com/LazyPanda07/WebFramework/wiki/Executors).
160
+
161
+
162
+ ### Hello executor
163
+ * Links
164
+ * [Windows](https://github.com/LazyPanda07/WebFramework/releases/download/Assets/windows.zip)
165
+ * [Linux](https://github.com/LazyPanda07/WebFramework/releases/download/Assets/linux.zip)
@@ -0,0 +1,9 @@
1
+ web_framework_api/WebFramework.py,sha256=G4KemXk2P8xl66v_zZGQelbSiSBp2u_czGa3qtbgbyk,4895
2
+ web_framework_api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ web_framework_api/exceptions/WebFrameworkException.py,sha256=ObFOGfBZmLtzg6TBg5N0iaZRvjW6CZSUpxRhL4lkq20,597
4
+ web_framework_api/utility/Config.py,sha256=bqicvmhqBWLTG2hLCWTGRJTumBHJG59C5fjF8Sqt1Mo,12207
5
+ web_framework_api/utility/DLLHandler.py,sha256=79vZJnebMZxyjXBrlkMtXpOirw59IkH38yzvgSMtrBI,2642
6
+ web_framework_api/utility/Utils.py,sha256=itgwHSyL9HHYe3jZBAr5E3OqIPRkdAoUsdJxxc4zkSA,2986
7
+ web_framework_api-1.0.0.dist-info/METADATA,sha256=8JpDkBi_mwyPhEPtnZeSzX-gB9jDBu558fw-Z0GNwzY,3908
8
+ web_framework_api-1.0.0.dist-info/WHEEL,sha256=fl6v0VwpzfGBVsGtkAkhILUlJxROXbA3HvRL6Fe3140,105
9
+ web_framework_api-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.25.0
3
+ Root-Is-Purelib: true
4
+ Tag: py2-none-any
5
+ Tag: py3-none-any