pyquoks 2.1.1__py3-none-any.whl → 2.1.3__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.
- pyquoks/data.py +84 -51
- pyquoks/localhost.py +0 -2
- pyquoks/models.py +0 -2
- pyquoks/test.py +8 -2
- pyquoks/utils.py +0 -2
- {pyquoks-2.1.1.dist-info → pyquoks-2.1.3.dist-info}/METADATA +3 -4
- pyquoks-2.1.3.dist-info/RECORD +10 -0
- pyquoks-2.1.1.dist-info/RECORD +0 -10
- {pyquoks-2.1.1.dist-info → pyquoks-2.1.3.dist-info}/WHEEL +0 -0
- {pyquoks-2.1.1.dist-info → pyquoks-2.1.3.dist-info}/licenses/LICENSE +0 -0
pyquoks/data.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
1
|
import configparser
|
|
4
2
|
import datetime
|
|
5
3
|
import io
|
|
@@ -18,49 +16,6 @@ import pyquoks.utils
|
|
|
18
16
|
|
|
19
17
|
# region Providers
|
|
20
18
|
|
|
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
19
|
class AssetsProvider(pyquoks.utils._HasRequiredAttributes):
|
|
65
20
|
"""
|
|
66
21
|
Class for providing various assets data
|
|
@@ -201,9 +156,7 @@ class AssetsProvider(pyquoks.utils._HasRequiredAttributes):
|
|
|
201
156
|
"""
|
|
202
157
|
|
|
203
158
|
return PIL.Image.open(
|
|
204
|
-
fp=io.BytesIO(
|
|
205
|
-
initial_bytes=requests.get(url).content,
|
|
206
|
-
),
|
|
159
|
+
fp=io.BytesIO(requests.get(url).content),
|
|
207
160
|
)
|
|
208
161
|
|
|
209
162
|
|
|
@@ -360,7 +313,8 @@ class ConfigManager(pyquoks.utils._HasRequiredAttributes):
|
|
|
360
313
|
for attribute, value in kwargs.items():
|
|
361
314
|
if attribute not in self._VALUES.keys():
|
|
362
315
|
raise AttributeError(f"{attribute} is not specified!")
|
|
363
|
-
|
|
316
|
+
|
|
317
|
+
if type(value) is not self._VALUES.get(attribute):
|
|
364
318
|
raise AttributeError(
|
|
365
319
|
f"{attribute} has incorrect type! (must be {self._VALUES.get(attribute).__name__})",
|
|
366
320
|
)
|
|
@@ -387,6 +341,82 @@ class ConfigManager(pyquoks.utils._HasRequiredAttributes):
|
|
|
387
341
|
setattr(self, attribute, object_class(self))
|
|
388
342
|
|
|
389
343
|
|
|
344
|
+
class DataManager(pyquoks.utils._HasRequiredAttributes):
|
|
345
|
+
"""
|
|
346
|
+
Class for managing data from JSON-like files
|
|
347
|
+
|
|
348
|
+
**Required attributes**::
|
|
349
|
+
|
|
350
|
+
_OBJECTS = {"users": UsersContainer}
|
|
351
|
+
|
|
352
|
+
# Predefined:
|
|
353
|
+
|
|
354
|
+
_PATH = pyquoks.utils.get_path("data/")
|
|
355
|
+
|
|
356
|
+
_FILENAME = "{0}.json"
|
|
357
|
+
|
|
358
|
+
Attributes:
|
|
359
|
+
_OBJECTS: Dictionary with filenames and containers
|
|
360
|
+
_PATH: Path to the directory with JSON-like files
|
|
361
|
+
_FILENAME: Filename of JSON-like files
|
|
362
|
+
"""
|
|
363
|
+
|
|
364
|
+
_REQUIRED_ATTRIBUTES = {
|
|
365
|
+
"_OBJECTS",
|
|
366
|
+
"_PATH",
|
|
367
|
+
"_FILENAME",
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
_OBJECTS: dict[str, type]
|
|
371
|
+
|
|
372
|
+
_PATH: str = pyquoks.utils.get_path("data/")
|
|
373
|
+
|
|
374
|
+
_FILENAME: str = "{0}.json"
|
|
375
|
+
|
|
376
|
+
def __init__(self) -> None:
|
|
377
|
+
self._check_attributes()
|
|
378
|
+
|
|
379
|
+
for filename, object_class in self._OBJECTS.items():
|
|
380
|
+
try:
|
|
381
|
+
with open(self._PATH + self._FILENAME.format(filename), "rb") as file:
|
|
382
|
+
setattr(self, filename, object_class(json.loads(file.read())))
|
|
383
|
+
except Exception:
|
|
384
|
+
setattr(self, filename, None)
|
|
385
|
+
|
|
386
|
+
def update(self, **kwargs) -> None:
|
|
387
|
+
"""
|
|
388
|
+
Updates provided attributes in object
|
|
389
|
+
"""
|
|
390
|
+
|
|
391
|
+
for attribute, value in kwargs.items():
|
|
392
|
+
if attribute not in self._OBJECTS.keys():
|
|
393
|
+
raise AttributeError(f"{attribute} is not specified!")
|
|
394
|
+
|
|
395
|
+
object_class = self._OBJECTS.get(attribute)
|
|
396
|
+
|
|
397
|
+
try:
|
|
398
|
+
object_class(value)
|
|
399
|
+
except Exception:
|
|
400
|
+
raise AttributeError(
|
|
401
|
+
f"{attribute} cannot be converted to {object_class.__name__}!",
|
|
402
|
+
)
|
|
403
|
+
else:
|
|
404
|
+
setattr(self, attribute, object_class(value))
|
|
405
|
+
|
|
406
|
+
os.makedirs(
|
|
407
|
+
name=self._PATH,
|
|
408
|
+
exist_ok=True,
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
with open(self._PATH + self._FILENAME.format(attribute), "w", encoding="utf-8") as file:
|
|
412
|
+
json.dump(
|
|
413
|
+
value,
|
|
414
|
+
fp=file,
|
|
415
|
+
ensure_ascii=False,
|
|
416
|
+
indent=2,
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
|
|
390
420
|
class DatabaseManager(pyquoks.utils._HasRequiredAttributes):
|
|
391
421
|
"""
|
|
392
422
|
Class for managing database connections
|
|
@@ -526,7 +556,10 @@ class LoggerService(logging.Logger):
|
|
|
526
556
|
self.addHandler(self.stream_handler)
|
|
527
557
|
|
|
528
558
|
if file_handling:
|
|
529
|
-
os.makedirs(
|
|
559
|
+
os.makedirs(
|
|
560
|
+
name=path,
|
|
561
|
+
exist_ok=True
|
|
562
|
+
)
|
|
530
563
|
self._LOG_PATH = path + f"{int(datetime.datetime.now().timestamp())}.{filename}.log"
|
|
531
564
|
|
|
532
565
|
self.file_handler = logging.FileHandler(
|
|
@@ -545,7 +578,7 @@ class LoggerService(logging.Logger):
|
|
|
545
578
|
self._LOG_PATH = None
|
|
546
579
|
|
|
547
580
|
@property
|
|
548
|
-
def file(self) -> typing.
|
|
581
|
+
def file(self) -> typing.IO | None:
|
|
549
582
|
"""
|
|
550
583
|
:return: Opened file-like object of current logs
|
|
551
584
|
"""
|
pyquoks/localhost.py
CHANGED
pyquoks/models.py
CHANGED
pyquoks/test.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
1
|
import types
|
|
4
2
|
import typing
|
|
5
3
|
import unittest
|
|
@@ -45,10 +43,12 @@ class TestCase(unittest.TestCase, pyquoks.utils._HasRequiredAttributes):
|
|
|
45
43
|
func_name: str,
|
|
46
44
|
test_data: object,
|
|
47
45
|
test_expected: object,
|
|
46
|
+
message: str = None,
|
|
48
47
|
) -> None:
|
|
49
48
|
self._logger.info(
|
|
50
49
|
msg=(
|
|
51
50
|
f"{self._get_func_name(func_name)}:\n"
|
|
51
|
+
f"{f"Message: {message}\n" if message else ""}"
|
|
52
52
|
f"Data: {test_data}\n"
|
|
53
53
|
f"Expected: {test_expected}\n"
|
|
54
54
|
),
|
|
@@ -58,6 +58,7 @@ class TestCase(unittest.TestCase, pyquoks.utils._HasRequiredAttributes):
|
|
|
58
58
|
self.assertEqual(
|
|
59
59
|
first=test_data,
|
|
60
60
|
second=test_expected,
|
|
61
|
+
msg=message,
|
|
61
62
|
)
|
|
62
63
|
except Exception as exception:
|
|
63
64
|
self._logger.log_error(
|
|
@@ -70,12 +71,14 @@ class TestCase(unittest.TestCase, pyquoks.utils._HasRequiredAttributes):
|
|
|
70
71
|
func_name: str,
|
|
71
72
|
test_func: typing.Callable,
|
|
72
73
|
test_exception: type[BaseException],
|
|
74
|
+
message: str = None,
|
|
73
75
|
*args,
|
|
74
76
|
**kwargs,
|
|
75
77
|
) -> None:
|
|
76
78
|
self._logger.info(
|
|
77
79
|
msg=(
|
|
78
80
|
f"{self._get_func_name(func_name)}:\n"
|
|
81
|
+
f"{f"Message: {message}\n" if message else ""}"
|
|
79
82
|
f"Function: {test_func.__name__}()\n"
|
|
80
83
|
f"Exception: {test_exception.__name__}\n"
|
|
81
84
|
),
|
|
@@ -99,10 +102,12 @@ class TestCase(unittest.TestCase, pyquoks.utils._HasRequiredAttributes):
|
|
|
99
102
|
func_name: str,
|
|
100
103
|
test_data: object,
|
|
101
104
|
test_type: type | types.UnionType,
|
|
105
|
+
message: str = None,
|
|
102
106
|
) -> None:
|
|
103
107
|
self._logger.info(
|
|
104
108
|
msg=(
|
|
105
109
|
f"{self._get_func_name(func_name)}:\n"
|
|
110
|
+
f"{f"Message: {message}\n" if message else ""}"
|
|
106
111
|
f"Type: {type(test_data).__name__}\n"
|
|
107
112
|
f"Expected: {test_type.__name__}\n"
|
|
108
113
|
),
|
|
@@ -112,6 +117,7 @@ class TestCase(unittest.TestCase, pyquoks.utils._HasRequiredAttributes):
|
|
|
112
117
|
self.assertIsInstance(
|
|
113
118
|
obj=test_data,
|
|
114
119
|
cls=test_type,
|
|
120
|
+
msg=message,
|
|
115
121
|
)
|
|
116
122
|
except Exception as exception:
|
|
117
123
|
self._logger.log_error(
|
pyquoks/utils.py
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyquoks
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.3
|
|
4
4
|
Summary: Пакет PyPI для часто используемых модулей в проектах diquoks
|
|
5
5
|
License: MIT
|
|
6
6
|
License-File: LICENSE
|
|
7
7
|
Author: Denis Titovets
|
|
8
8
|
Author-email: den232titovets@yandex.ru
|
|
9
|
-
Requires-Python: >=3.
|
|
9
|
+
Requires-Python: >=3.14
|
|
10
10
|
Classifier: License :: OSI Approved :: MIT License
|
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
13
12
|
Classifier: Programming Language :: Python :: 3.14
|
|
14
13
|
Requires-Dist: blinker (==1.9.0)
|
|
15
14
|
Requires-Dist: certifi (==2025.11.12)
|
|
@@ -24,7 +23,7 @@ Requires-Dist: markupsafe (==3.0.3)
|
|
|
24
23
|
Requires-Dist: pillow (==12.0.0)
|
|
25
24
|
Requires-Dist: psutil (==7.1.3)
|
|
26
25
|
Requires-Dist: requests (==2.32.5)
|
|
27
|
-
Requires-Dist: urllib3 (==2.
|
|
26
|
+
Requires-Dist: urllib3 (==2.6.1)
|
|
28
27
|
Requires-Dist: waitress (==3.0.2)
|
|
29
28
|
Requires-Dist: werkzeug (==3.1.4)
|
|
30
29
|
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
pyquoks/__init__.py,sha256=axiG3ptbyRzfPKNrEGSGb9ZeQztdwWOq_LNbJhZDHOs,143
|
|
2
|
+
pyquoks/data.py,sha256=2GwkwvYi-sG-WMfnlTXjaoneC22Y-d4EPUqmqRJ5pTQ,17450
|
|
3
|
+
pyquoks/localhost.py,sha256=HPixbz33l4ZkLrk__kbb4mekPjJKA78-Lpi3AjCWvgs,1062
|
|
4
|
+
pyquoks/models.py,sha256=fNL54lamhNXDn9onadAcjqO47T51DnohmlickX_uyiw,4463
|
|
5
|
+
pyquoks/test.py,sha256=Hx3cLng0uDMDVMx-NveLOPlgpX51A00aVELa0sbR5D0,3379
|
|
6
|
+
pyquoks/utils.py,sha256=6uC5QUtPtVt4G5iiP2jog0t-4IUshUQPshJwmsEwmqg,1475
|
|
7
|
+
pyquoks-2.1.3.dist-info/licenses/LICENSE,sha256=eEd8UIYxvKUY7vqrV1XTFo70_FQdiW6o1fznseCXRJs,1095
|
|
8
|
+
pyquoks-2.1.3.dist-info/METADATA,sha256=P17lYaEFxJKDX8z38aCefY4P38jUOXXeOBU2R_Dpipw,1663
|
|
9
|
+
pyquoks-2.1.3.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
10
|
+
pyquoks-2.1.3.dist-info/RECORD,,
|
pyquoks-2.1.1.dist-info/RECORD
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
pyquoks/__init__.py,sha256=axiG3ptbyRzfPKNrEGSGb9ZeQztdwWOq_LNbJhZDHOs,143
|
|
2
|
-
pyquoks/data.py,sha256=WnrgMO04anzi1e5AiVDSL-JxwjDRLIm4UceVp9cv8p0,16389
|
|
3
|
-
pyquoks/localhost.py,sha256=dn9Dwx0wKRIudPxOIql7JgsDomUtf-bOr7SkZozAbqk,1100
|
|
4
|
-
pyquoks/models.py,sha256=NSrwbL1eOEDz1HnYt_4_Lx95Hj8q2OumvsHWxhD_ygE,4501
|
|
5
|
-
pyquoks/test.py,sha256=i7smDot_13Kzu1gONhLGVFEkXz6x9MFi-_8DBNnRXd4,3060
|
|
6
|
-
pyquoks/utils.py,sha256=AQTVexZxn_-XAVBQjHmwdNM2oKZY4W98ZO1VEzMyVxE,1513
|
|
7
|
-
pyquoks-2.1.1.dist-info/licenses/LICENSE,sha256=eEd8UIYxvKUY7vqrV1XTFo70_FQdiW6o1fznseCXRJs,1095
|
|
8
|
-
pyquoks-2.1.1.dist-info/METADATA,sha256=jX9pAEOvQ6A_UoNHpEkg3wUjLxgdO-B9bFxYNpWm6PI,1714
|
|
9
|
-
pyquoks-2.1.1.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
10
|
-
pyquoks-2.1.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|