pyquoks 2.1.1__tar.gz → 2.1.2__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.
- {pyquoks-2.1.1 → pyquoks-2.1.2}/PKG-INFO +2 -2
- {pyquoks-2.1.1 → pyquoks-2.1.2}/pyproject.toml +2 -2
- {pyquoks-2.1.1 → pyquoks-2.1.2}/src/pyquoks/data.py +84 -49
- {pyquoks-2.1.1 → pyquoks-2.1.2}/src/pyquoks/test.py +8 -0
- {pyquoks-2.1.1 → pyquoks-2.1.2}/LICENSE +0 -0
- {pyquoks-2.1.1 → pyquoks-2.1.2}/README.md +0 -0
- {pyquoks-2.1.1 → pyquoks-2.1.2}/src/pyquoks/__init__.py +0 -0
- {pyquoks-2.1.1 → pyquoks-2.1.2}/src/pyquoks/localhost.py +0 -0
- {pyquoks-2.1.1 → pyquoks-2.1.2}/src/pyquoks/models.py +0 -0
- {pyquoks-2.1.1 → pyquoks-2.1.2}/src/pyquoks/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyquoks
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.2
|
|
4
4
|
Summary: Пакет PyPI для часто используемых модулей в проектах diquoks
|
|
5
5
|
License: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -24,7 +24,7 @@ Requires-Dist: markupsafe (==3.0.3)
|
|
|
24
24
|
Requires-Dist: pillow (==12.0.0)
|
|
25
25
|
Requires-Dist: psutil (==7.1.3)
|
|
26
26
|
Requires-Dist: requests (==2.32.5)
|
|
27
|
-
Requires-Dist: urllib3 (==2.
|
|
27
|
+
Requires-Dist: urllib3 (==2.6.0)
|
|
28
28
|
Requires-Dist: waitress (==3.0.2)
|
|
29
29
|
Requires-Dist: werkzeug (==3.1.4)
|
|
30
30
|
Description-Content-Type: text/markdown
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pyquoks"
|
|
3
|
-
version = "2.1.
|
|
3
|
+
version = "2.1.2"
|
|
4
4
|
description = "Пакет PyPI для часто используемых модулей в проектах diquoks"
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "Denis Titovets <den232titovets@yandex.ru>" }
|
|
@@ -22,7 +22,7 @@ dependencies = [
|
|
|
22
22
|
"pillow (==12.0.0)",
|
|
23
23
|
"psutil (==7.1.3)",
|
|
24
24
|
"requests (==2.32.5)",
|
|
25
|
-
"urllib3 (==2.
|
|
25
|
+
"urllib3 (==2.6.0)",
|
|
26
26
|
"waitress (==3.0.2)",
|
|
27
27
|
"werkzeug (==3.1.4)"
|
|
28
28
|
]
|
|
@@ -18,49 +18,6 @@ import pyquoks.utils
|
|
|
18
18
|
|
|
19
19
|
# region Providers
|
|
20
20
|
|
|
21
|
-
class DataProvider(pyquoks.utils._HasRequiredAttributes):
|
|
22
|
-
"""
|
|
23
|
-
Class for providing data from JSON-like files
|
|
24
|
-
|
|
25
|
-
**Required attributes**::
|
|
26
|
-
|
|
27
|
-
_OBJECTS = {"users": UsersContainer}
|
|
28
|
-
|
|
29
|
-
# Predefined:
|
|
30
|
-
|
|
31
|
-
_PATH = pyquoks.utils.get_path("data/")
|
|
32
|
-
|
|
33
|
-
_FILENAME = "{0}.json"
|
|
34
|
-
|
|
35
|
-
Attributes:
|
|
36
|
-
_OBJECTS: Dictionary with filenames and containers
|
|
37
|
-
_PATH: Path to the directory with JSON-like files
|
|
38
|
-
_FILENAME: Filename of JSON-like files
|
|
39
|
-
"""
|
|
40
|
-
|
|
41
|
-
_REQUIRED_ATTRIBUTES = {
|
|
42
|
-
"_OBJECTS",
|
|
43
|
-
"_PATH",
|
|
44
|
-
"_FILENAME",
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
_OBJECTS: dict[str, type]
|
|
48
|
-
|
|
49
|
-
_PATH: str = pyquoks.utils.get_path("data/")
|
|
50
|
-
|
|
51
|
-
_FILENAME: str = "{0}.json"
|
|
52
|
-
|
|
53
|
-
def __init__(self) -> None:
|
|
54
|
-
self._check_attributes()
|
|
55
|
-
|
|
56
|
-
for filename, object_class in self._OBJECTS.items():
|
|
57
|
-
try:
|
|
58
|
-
with open(self._PATH + self._FILENAME.format(filename), "rb") as file:
|
|
59
|
-
setattr(self, filename, object_class(json.loads(file.read())))
|
|
60
|
-
except Exception:
|
|
61
|
-
setattr(self, filename, None)
|
|
62
|
-
|
|
63
|
-
|
|
64
21
|
class AssetsProvider(pyquoks.utils._HasRequiredAttributes):
|
|
65
22
|
"""
|
|
66
23
|
Class for providing various assets data
|
|
@@ -201,9 +158,7 @@ class AssetsProvider(pyquoks.utils._HasRequiredAttributes):
|
|
|
201
158
|
"""
|
|
202
159
|
|
|
203
160
|
return PIL.Image.open(
|
|
204
|
-
fp=io.BytesIO(
|
|
205
|
-
initial_bytes=requests.get(url).content,
|
|
206
|
-
),
|
|
161
|
+
fp=io.BytesIO(requests.get(url).content),
|
|
207
162
|
)
|
|
208
163
|
|
|
209
164
|
|
|
@@ -360,7 +315,8 @@ class ConfigManager(pyquoks.utils._HasRequiredAttributes):
|
|
|
360
315
|
for attribute, value in kwargs.items():
|
|
361
316
|
if attribute not in self._VALUES.keys():
|
|
362
317
|
raise AttributeError(f"{attribute} is not specified!")
|
|
363
|
-
|
|
318
|
+
|
|
319
|
+
if type(value) is not self._VALUES.get(attribute):
|
|
364
320
|
raise AttributeError(
|
|
365
321
|
f"{attribute} has incorrect type! (must be {self._VALUES.get(attribute).__name__})",
|
|
366
322
|
)
|
|
@@ -387,6 +343,82 @@ class ConfigManager(pyquoks.utils._HasRequiredAttributes):
|
|
|
387
343
|
setattr(self, attribute, object_class(self))
|
|
388
344
|
|
|
389
345
|
|
|
346
|
+
class DataManager(pyquoks.utils._HasRequiredAttributes):
|
|
347
|
+
"""
|
|
348
|
+
Class for managing data from JSON-like files
|
|
349
|
+
|
|
350
|
+
**Required attributes**::
|
|
351
|
+
|
|
352
|
+
_OBJECTS = {"users": UsersContainer}
|
|
353
|
+
|
|
354
|
+
# Predefined:
|
|
355
|
+
|
|
356
|
+
_PATH = pyquoks.utils.get_path("data/")
|
|
357
|
+
|
|
358
|
+
_FILENAME = "{0}.json"
|
|
359
|
+
|
|
360
|
+
Attributes:
|
|
361
|
+
_OBJECTS: Dictionary with filenames and containers
|
|
362
|
+
_PATH: Path to the directory with JSON-like files
|
|
363
|
+
_FILENAME: Filename of JSON-like files
|
|
364
|
+
"""
|
|
365
|
+
|
|
366
|
+
_REQUIRED_ATTRIBUTES = {
|
|
367
|
+
"_OBJECTS",
|
|
368
|
+
"_PATH",
|
|
369
|
+
"_FILENAME",
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
_OBJECTS: dict[str, type]
|
|
373
|
+
|
|
374
|
+
_PATH: str = pyquoks.utils.get_path("data/")
|
|
375
|
+
|
|
376
|
+
_FILENAME: str = "{0}.json"
|
|
377
|
+
|
|
378
|
+
def __init__(self) -> None:
|
|
379
|
+
self._check_attributes()
|
|
380
|
+
|
|
381
|
+
for filename, object_class in self._OBJECTS.items():
|
|
382
|
+
try:
|
|
383
|
+
with open(self._PATH + self._FILENAME.format(filename), "rb") as file:
|
|
384
|
+
setattr(self, filename, object_class(json.loads(file.read())))
|
|
385
|
+
except Exception:
|
|
386
|
+
setattr(self, filename, None)
|
|
387
|
+
|
|
388
|
+
def update(self, **kwargs) -> None:
|
|
389
|
+
"""
|
|
390
|
+
Updates provided attributes in object
|
|
391
|
+
"""
|
|
392
|
+
|
|
393
|
+
for attribute, value in kwargs.items():
|
|
394
|
+
if attribute not in self._OBJECTS.keys():
|
|
395
|
+
raise AttributeError(f"{attribute} is not specified!")
|
|
396
|
+
|
|
397
|
+
object_class = self._OBJECTS.get(attribute)
|
|
398
|
+
|
|
399
|
+
try:
|
|
400
|
+
object_class(value)
|
|
401
|
+
except Exception:
|
|
402
|
+
raise AttributeError(
|
|
403
|
+
f"{attribute} cannot be converted to {object_class.__name__}!",
|
|
404
|
+
)
|
|
405
|
+
else:
|
|
406
|
+
setattr(self, attribute, object_class(value))
|
|
407
|
+
|
|
408
|
+
os.makedirs(
|
|
409
|
+
name=self._PATH,
|
|
410
|
+
exist_ok=True,
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
with open(self._PATH + self._FILENAME.format(attribute), "w", encoding="utf-8") as file:
|
|
414
|
+
json.dump(
|
|
415
|
+
value,
|
|
416
|
+
fp=file,
|
|
417
|
+
ensure_ascii=False,
|
|
418
|
+
indent=2,
|
|
419
|
+
)
|
|
420
|
+
|
|
421
|
+
|
|
390
422
|
class DatabaseManager(pyquoks.utils._HasRequiredAttributes):
|
|
391
423
|
"""
|
|
392
424
|
Class for managing database connections
|
|
@@ -526,7 +558,10 @@ class LoggerService(logging.Logger):
|
|
|
526
558
|
self.addHandler(self.stream_handler)
|
|
527
559
|
|
|
528
560
|
if file_handling:
|
|
529
|
-
os.makedirs(
|
|
561
|
+
os.makedirs(
|
|
562
|
+
name=path,
|
|
563
|
+
exist_ok=True
|
|
564
|
+
)
|
|
530
565
|
self._LOG_PATH = path + f"{int(datetime.datetime.now().timestamp())}.{filename}.log"
|
|
531
566
|
|
|
532
567
|
self.file_handler = logging.FileHandler(
|
|
@@ -545,7 +580,7 @@ class LoggerService(logging.Logger):
|
|
|
545
580
|
self._LOG_PATH = None
|
|
546
581
|
|
|
547
582
|
@property
|
|
548
|
-
def file(self) -> typing.
|
|
583
|
+
def file(self) -> typing.IO | None:
|
|
549
584
|
"""
|
|
550
585
|
:return: Opened file-like object of current logs
|
|
551
586
|
"""
|
|
@@ -45,10 +45,12 @@ class TestCase(unittest.TestCase, pyquoks.utils._HasRequiredAttributes):
|
|
|
45
45
|
func_name: str,
|
|
46
46
|
test_data: object,
|
|
47
47
|
test_expected: object,
|
|
48
|
+
message: str = None,
|
|
48
49
|
) -> None:
|
|
49
50
|
self._logger.info(
|
|
50
51
|
msg=(
|
|
51
52
|
f"{self._get_func_name(func_name)}:\n"
|
|
53
|
+
f"{f"Message: {message}\n" if message else ""}"
|
|
52
54
|
f"Data: {test_data}\n"
|
|
53
55
|
f"Expected: {test_expected}\n"
|
|
54
56
|
),
|
|
@@ -58,6 +60,7 @@ class TestCase(unittest.TestCase, pyquoks.utils._HasRequiredAttributes):
|
|
|
58
60
|
self.assertEqual(
|
|
59
61
|
first=test_data,
|
|
60
62
|
second=test_expected,
|
|
63
|
+
msg=message,
|
|
61
64
|
)
|
|
62
65
|
except Exception as exception:
|
|
63
66
|
self._logger.log_error(
|
|
@@ -70,12 +73,14 @@ class TestCase(unittest.TestCase, pyquoks.utils._HasRequiredAttributes):
|
|
|
70
73
|
func_name: str,
|
|
71
74
|
test_func: typing.Callable,
|
|
72
75
|
test_exception: type[BaseException],
|
|
76
|
+
message: str = None,
|
|
73
77
|
*args,
|
|
74
78
|
**kwargs,
|
|
75
79
|
) -> None:
|
|
76
80
|
self._logger.info(
|
|
77
81
|
msg=(
|
|
78
82
|
f"{self._get_func_name(func_name)}:\n"
|
|
83
|
+
f"{f"Message: {message}\n" if message else ""}"
|
|
79
84
|
f"Function: {test_func.__name__}()\n"
|
|
80
85
|
f"Exception: {test_exception.__name__}\n"
|
|
81
86
|
),
|
|
@@ -99,10 +104,12 @@ class TestCase(unittest.TestCase, pyquoks.utils._HasRequiredAttributes):
|
|
|
99
104
|
func_name: str,
|
|
100
105
|
test_data: object,
|
|
101
106
|
test_type: type | types.UnionType,
|
|
107
|
+
message: str = None,
|
|
102
108
|
) -> None:
|
|
103
109
|
self._logger.info(
|
|
104
110
|
msg=(
|
|
105
111
|
f"{self._get_func_name(func_name)}:\n"
|
|
112
|
+
f"{f"Message: {message}\n" if message else ""}"
|
|
106
113
|
f"Type: {type(test_data).__name__}\n"
|
|
107
114
|
f"Expected: {test_type.__name__}\n"
|
|
108
115
|
),
|
|
@@ -112,6 +119,7 @@ class TestCase(unittest.TestCase, pyquoks.utils._HasRequiredAttributes):
|
|
|
112
119
|
self.assertIsInstance(
|
|
113
120
|
obj=test_data,
|
|
114
121
|
cls=test_type,
|
|
122
|
+
msg=message,
|
|
115
123
|
)
|
|
116
124
|
except Exception as exception:
|
|
117
125
|
self._logger.log_error(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|