pyquoks 2.1.0__py3-none-any.whl → 2.1.2__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 -49
- pyquoks/models.py +23 -24
- pyquoks/test.py +8 -0
- pyquoks/utils.py +1 -1
- {pyquoks-2.1.0.dist-info → pyquoks-2.1.2.dist-info}/METADATA +2 -2
- pyquoks-2.1.2.dist-info/RECORD +10 -0
- pyquoks-2.1.0.dist-info/RECORD +0 -10
- {pyquoks-2.1.0.dist-info → pyquoks-2.1.2.dist-info}/WHEEL +0 -0
- {pyquoks-2.1.0.dist-info → pyquoks-2.1.2.dist-info}/licenses/LICENSE +0 -0
pyquoks/data.py
CHANGED
|
@@ -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
|
"""
|
pyquoks/models.py
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import typing
|
|
4
|
+
|
|
3
5
|
import pyquoks.utils
|
|
4
6
|
|
|
5
7
|
|
|
6
|
-
class
|
|
8
|
+
class _HasInitialData:
|
|
9
|
+
"""
|
|
10
|
+
Assistive class for providing initial data
|
|
11
|
+
|
|
12
|
+
Attributes:
|
|
13
|
+
_data: Initial data that was passed into object
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
_data: typing.Any
|
|
17
|
+
|
|
18
|
+
def __init__(self, data: typing.Any) -> None:
|
|
19
|
+
self._data = data
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Model(_HasInitialData):
|
|
7
23
|
"""
|
|
8
24
|
Class for storing parameters and models
|
|
9
25
|
|
|
@@ -11,7 +27,7 @@ class Model:
|
|
|
11
27
|
|
|
12
28
|
_ATTRIBUTES = {"beatmap_id", "score_id"}
|
|
13
29
|
|
|
14
|
-
_OBJECTS = {"
|
|
30
|
+
_OBJECTS = {"beatmap": BeatmapModel}
|
|
15
31
|
|
|
16
32
|
Attributes:
|
|
17
33
|
_ATTRIBUTES: Set of parameters that stored in this model
|
|
@@ -26,7 +42,7 @@ class Model:
|
|
|
26
42
|
_data: dict
|
|
27
43
|
|
|
28
44
|
def __init__(self, data: dict) -> None:
|
|
29
|
-
|
|
45
|
+
super().__init__(data)
|
|
30
46
|
|
|
31
47
|
if hasattr(self, "_ATTRIBUTES"):
|
|
32
48
|
if isinstance(self._ATTRIBUTES, set):
|
|
@@ -46,7 +62,7 @@ class Model:
|
|
|
46
62
|
self._OBJECTS = None
|
|
47
63
|
|
|
48
64
|
|
|
49
|
-
class Container:
|
|
65
|
+
class Container(Model, _HasInitialData):
|
|
50
66
|
"""
|
|
51
67
|
Class for storing lists of models and another parameters
|
|
52
68
|
|
|
@@ -74,24 +90,7 @@ class Container:
|
|
|
74
90
|
_data: dict
|
|
75
91
|
|
|
76
92
|
def __init__(self, data: dict) -> None:
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if hasattr(self, "_ATTRIBUTES"):
|
|
80
|
-
if isinstance(self._ATTRIBUTES, set):
|
|
81
|
-
for attribute in self._ATTRIBUTES:
|
|
82
|
-
setattr(self, attribute, self._data.get(attribute, None))
|
|
83
|
-
else:
|
|
84
|
-
self._ATTRIBUTES = None
|
|
85
|
-
|
|
86
|
-
if hasattr(self, "_OBJECTS"):
|
|
87
|
-
if isinstance(self._OBJECTS, dict):
|
|
88
|
-
for attribute, object_class in self._OBJECTS.items():
|
|
89
|
-
try:
|
|
90
|
-
setattr(self, attribute, object_class(self._data.get(attribute)))
|
|
91
|
-
except Exception:
|
|
92
|
-
setattr(self, attribute, None)
|
|
93
|
-
else:
|
|
94
|
-
self._OBJECTS = None
|
|
93
|
+
super().__init__(data)
|
|
95
94
|
|
|
96
95
|
if hasattr(self, "_DATA"):
|
|
97
96
|
if isinstance(self._DATA, dict):
|
|
@@ -104,7 +103,7 @@ class Container:
|
|
|
104
103
|
self._DATA = None
|
|
105
104
|
|
|
106
105
|
|
|
107
|
-
class Listing:
|
|
106
|
+
class Listing(_HasInitialData):
|
|
108
107
|
"""
|
|
109
108
|
Class for storing list of models
|
|
110
109
|
|
|
@@ -122,7 +121,7 @@ class Listing:
|
|
|
122
121
|
_data: list
|
|
123
122
|
|
|
124
123
|
def __init__(self, data: list) -> None:
|
|
125
|
-
|
|
124
|
+
super().__init__(data)
|
|
126
125
|
|
|
127
126
|
if hasattr(self, "_DATA"):
|
|
128
127
|
if isinstance(self._DATA, dict):
|
pyquoks/test.py
CHANGED
|
@@ -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(
|
pyquoks/utils.py
CHANGED
|
@@ -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
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
pyquoks/__init__.py,sha256=axiG3ptbyRzfPKNrEGSGb9ZeQztdwWOq_LNbJhZDHOs,143
|
|
2
|
+
pyquoks/data.py,sha256=Vz7b_b5dZD-EnhyVLqScjFqCvju6esWPkOKmXEBgiiE,17488
|
|
3
|
+
pyquoks/localhost.py,sha256=dn9Dwx0wKRIudPxOIql7JgsDomUtf-bOr7SkZozAbqk,1100
|
|
4
|
+
pyquoks/models.py,sha256=NSrwbL1eOEDz1HnYt_4_Lx95Hj8q2OumvsHWxhD_ygE,4501
|
|
5
|
+
pyquoks/test.py,sha256=7s_RdzuTq90hv-QyPVrlr2_H_7KiMkkFMQEbpskO8Ss,3417
|
|
6
|
+
pyquoks/utils.py,sha256=AQTVexZxn_-XAVBQjHmwdNM2oKZY4W98ZO1VEzMyVxE,1513
|
|
7
|
+
pyquoks-2.1.2.dist-info/licenses/LICENSE,sha256=eEd8UIYxvKUY7vqrV1XTFo70_FQdiW6o1fznseCXRJs,1095
|
|
8
|
+
pyquoks-2.1.2.dist-info/METADATA,sha256=b2ZFqwqNtCYKjUPgbZWcD3oOahlNzPmpuFaDQ63K6nA,1714
|
|
9
|
+
pyquoks-2.1.2.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
10
|
+
pyquoks-2.1.2.dist-info/RECORD,,
|
pyquoks-2.1.0.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=XXBWKvGgWvMxSIn6EYoAZ_vx7vct2gyMA7bBO4nwSps,4833
|
|
5
|
-
pyquoks/test.py,sha256=i7smDot_13Kzu1gONhLGVFEkXz6x9MFi-_8DBNnRXd4,3060
|
|
6
|
-
pyquoks/utils.py,sha256=iAYG56cZ3xjBnR3wzeF-B5ELcx7UTkQi8H1x3W4vCvk,1517
|
|
7
|
-
pyquoks-2.1.0.dist-info/licenses/LICENSE,sha256=eEd8UIYxvKUY7vqrV1XTFo70_FQdiW6o1fznseCXRJs,1095
|
|
8
|
-
pyquoks-2.1.0.dist-info/METADATA,sha256=OPFRa6UFDe055Pi8QyQMyE3UiEoVaPWkRdtLFNroIUI,1714
|
|
9
|
-
pyquoks-2.1.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
10
|
-
pyquoks-2.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|