pyquoks 2.1.3__py3-none-any.whl → 2.2.1__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/__init__.py CHANGED
@@ -1,9 +1,8 @@
1
1
  __all__ = [
2
- "models",
3
2
  "data",
4
3
  "utils",
5
4
  "localhost",
6
5
  "test",
7
6
  ]
8
7
 
9
- from . import models, data, utils, localhost, test
8
+ from . import data, utils, localhost, test
pyquoks/data.py CHANGED
@@ -9,6 +9,7 @@ import sys
9
9
  import typing
10
10
 
11
11
  import PIL.Image
12
+ import pydantic
12
13
  import requests
13
14
 
14
15
  import pyquoks.utils
@@ -76,13 +77,13 @@ class AssetsProvider(pyquoks.utils._HasRequiredAttributes):
76
77
 
77
78
  self._PATH = self._parent._PATH + self._PATH
78
79
 
79
- for filename in self._ATTRIBUTES:
80
+ for attribute in self._ATTRIBUTES:
80
81
  try:
81
- setattr(self, filename, self._parent.file_image(
82
- path=self._PATH + self._FILENAME.format(filename),
82
+ setattr(self, attribute, self._parent.file_image(
83
+ path=self._PATH + self._FILENAME.format(attribute),
83
84
  ))
84
85
  except Exception:
85
- setattr(self, filename, None)
86
+ setattr(self, attribute, None)
86
87
 
87
88
  class Network(pyquoks.utils._HasRequiredAttributes):
88
89
  """
@@ -133,8 +134,8 @@ class AssetsProvider(pyquoks.utils._HasRequiredAttributes):
133
134
  def __init__(self) -> None:
134
135
  self._check_attributes()
135
136
 
136
- for attribute, object_class in self._OBJECTS.items():
137
- setattr(self, attribute, object_class(self))
137
+ for attribute, child_class in self._OBJECTS.items():
138
+ setattr(self, attribute, child_class(self))
138
139
 
139
140
  @staticmethod
140
141
  def file_image(path: str) -> PIL.Image.Image:
@@ -190,8 +191,8 @@ class StringsProvider(pyquoks.utils._HasRequiredAttributes):
190
191
  def __init__(self) -> None:
191
192
  self._check_attributes()
192
193
 
193
- for attribute, object_class in self._OBJECTS.items():
194
- setattr(self, attribute, object_class(self))
194
+ for attribute, child_class in self._OBJECTS.items():
195
+ setattr(self, attribute, child_class(self))
195
196
 
196
197
 
197
198
  # endregion
@@ -270,20 +271,20 @@ class ConfigManager(pyquoks.utils._HasRequiredAttributes):
270
271
 
271
272
  for attribute, object_type in self._VALUES.items():
272
273
  try:
273
- match object_type.__name__:
274
- case str.__name__:
275
- pass
276
- case int.__name__:
277
- setattr(self, attribute, int(getattr(self, attribute)))
278
- case float.__name__:
279
- setattr(self, attribute, float(getattr(self, attribute)))
280
- case bool.__name__:
274
+ match object_type():
275
+ case bool():
281
276
  if getattr(self, attribute) not in [str(True), str(False)]:
282
277
  setattr(self, attribute, None)
283
278
  raise self._incorrect_content_exception
284
279
  else:
285
280
  setattr(self, attribute, getattr(self, attribute) == str(True))
286
- case dict.__name__ | list.__name__:
281
+ case int():
282
+ setattr(self, attribute, int(getattr(self, attribute)))
283
+ case float():
284
+ setattr(self, attribute, float(getattr(self, attribute)))
285
+ case str():
286
+ pass
287
+ case dict() | list():
287
288
  setattr(self, attribute, json.loads(getattr(self, attribute)))
288
289
  case _:
289
290
  raise ValueError(f"{object_type.__name__} type is not supported!")
@@ -314,9 +315,11 @@ class ConfigManager(pyquoks.utils._HasRequiredAttributes):
314
315
  if attribute not in self._VALUES.keys():
315
316
  raise AttributeError(f"{attribute} is not specified!")
316
317
 
317
- if type(value) is not self._VALUES.get(attribute):
318
+ object_type = self._VALUES.get(attribute)
319
+
320
+ if type(value) is not object_type:
318
321
  raise AttributeError(
319
- f"{attribute} has incorrect type! (must be {self._VALUES.get(attribute).__name__})",
322
+ f"{attribute} has incorrect type! (must be {object_type.__name__})",
320
323
  )
321
324
 
322
325
  setattr(self, attribute, value)
@@ -337,8 +340,8 @@ class ConfigManager(pyquoks.utils._HasRequiredAttributes):
337
340
  def __init__(self) -> None:
338
341
  self._check_attributes()
339
342
 
340
- for attribute, object_class in self._OBJECTS.items():
341
- setattr(self, attribute, object_class(self))
343
+ for attribute, child_class in self._OBJECTS.items():
344
+ setattr(self, attribute, child_class(self))
342
345
 
343
346
 
344
347
  class DataManager(pyquoks.utils._HasRequiredAttributes):
@@ -347,7 +350,7 @@ class DataManager(pyquoks.utils._HasRequiredAttributes):
347
350
 
348
351
  **Required attributes**::
349
352
 
350
- _OBJECTS = {"users": UsersContainer}
353
+ _OBJECTS = {"users": list[UserModel]}
351
354
 
352
355
  # Predefined:
353
356
 
@@ -356,7 +359,7 @@ class DataManager(pyquoks.utils._HasRequiredAttributes):
356
359
  _FILENAME = "{0}.json"
357
360
 
358
361
  Attributes:
359
- _OBJECTS: Dictionary with filenames and containers
362
+ _OBJECTS: Dictionary with filenames and types of models
360
363
  _PATH: Path to the directory with JSON-like files
361
364
  _FILENAME: Filename of JSON-like files
362
365
  """
@@ -367,7 +370,7 @@ class DataManager(pyquoks.utils._HasRequiredAttributes):
367
370
  "_FILENAME",
368
371
  }
369
372
 
370
- _OBJECTS: dict[str, type]
373
+ _OBJECTS: dict[str, type[pydantic.BaseModel] | list[type[pydantic.BaseModel]]]
371
374
 
372
375
  _PATH: str = pyquoks.utils.get_path("data/")
373
376
 
@@ -376,12 +379,17 @@ class DataManager(pyquoks.utils._HasRequiredAttributes):
376
379
  def __init__(self) -> None:
377
380
  self._check_attributes()
378
381
 
379
- for filename, object_class in self._OBJECTS.items():
382
+ for attribute, object_type in self._OBJECTS.items():
380
383
  try:
381
- with open(self._PATH + self._FILENAME.format(filename), "rb") as file:
382
- setattr(self, filename, object_class(json.loads(file.read())))
384
+ with open(self._PATH + self._FILENAME.format(attribute), "rb") as file:
385
+ data = json.loads(file.read())
386
+
387
+ if typing.get_origin(object_type) == list:
388
+ setattr(self, attribute, [typing.get_args(object_type)[0](**model) for model in data])
389
+ else:
390
+ setattr(self, attribute, object_type(**data))
383
391
  except Exception:
384
- setattr(self, filename, None)
392
+ setattr(self, attribute, None)
385
393
 
386
394
  def update(self, **kwargs) -> None:
387
395
  """
@@ -392,29 +400,29 @@ class DataManager(pyquoks.utils._HasRequiredAttributes):
392
400
  if attribute not in self._OBJECTS.keys():
393
401
  raise AttributeError(f"{attribute} is not specified!")
394
402
 
395
- object_class = self._OBJECTS.get(attribute)
403
+ object_type = self._OBJECTS.get(attribute)
396
404
 
397
- try:
398
- object_class(value)
399
- except Exception:
405
+ if type(value) is not object_type:
400
406
  raise AttributeError(
401
- f"{attribute} cannot be converted to {object_class.__name__}!",
407
+ f"{attribute} has incorrect type! (must be {object_type.__name__})",
402
408
  )
403
- else:
404
- setattr(self, attribute, object_class(value))
405
409
 
406
- os.makedirs(
407
- name=self._PATH,
408
- exist_ok=True,
409
- )
410
+ setattr(self, attribute, value)
410
411
 
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
- )
412
+ os.makedirs(
413
+ name=self._PATH,
414
+ exist_ok=True,
415
+ )
416
+
417
+ with open(self._PATH + self._FILENAME.format(attribute), "w", encoding="utf-8") as file:
418
+ json.dump(
419
+ [model.model_dump() for model in value] if typing.get_origin(
420
+ object_type,
421
+ ) == list else value.model_dump(),
422
+ fp=file,
423
+ ensure_ascii=False,
424
+ indent=2,
425
+ )
418
426
 
419
427
 
420
428
  class DatabaseManager(pyquoks.utils._HasRequiredAttributes):
@@ -510,16 +518,16 @@ class DatabaseManager(pyquoks.utils._HasRequiredAttributes):
510
518
  exist_ok=True,
511
519
  )
512
520
 
513
- for attribute, object_class in self._OBJECTS.items():
514
- setattr(self, attribute, object_class(self))
521
+ for attribute, child_class in self._OBJECTS.items():
522
+ setattr(self, attribute, child_class(self))
515
523
 
516
524
  def close_all(self) -> None:
517
525
  """
518
526
  Closes all database connections
519
527
  """
520
528
 
521
- for database in self._OBJECTS.keys():
522
- getattr(self, database).close()
529
+ for attribute in self._OBJECTS.keys():
530
+ getattr(self, attribute).close()
523
531
 
524
532
 
525
533
  # endregion
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyquoks
3
- Version: 2.1.3
3
+ Version: 2.2.1
4
4
  Summary: Пакет PyPI для часто используемых модулей в проектах diquoks
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -10,6 +10,7 @@ Requires-Python: >=3.14
10
10
  Classifier: License :: OSI Approved :: MIT License
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Classifier: Programming Language :: Python :: 3.14
13
+ Requires-Dist: annotated-types (==0.7.0)
13
14
  Requires-Dist: blinker (==1.9.0)
14
15
  Requires-Dist: certifi (==2025.11.12)
15
16
  Requires-Dist: charset-normalizer (==3.4.4)
@@ -22,8 +23,12 @@ Requires-Dist: jinja2 (==3.1.6)
22
23
  Requires-Dist: markupsafe (==3.0.3)
23
24
  Requires-Dist: pillow (==12.0.0)
24
25
  Requires-Dist: psutil (==7.1.3)
26
+ Requires-Dist: pydantic (==2.12.5)
27
+ Requires-Dist: pydantic-core (==2.41.5)
25
28
  Requires-Dist: requests (==2.32.5)
26
- Requires-Dist: urllib3 (==2.6.1)
29
+ Requires-Dist: typing-extensions (==4.15.0)
30
+ Requires-Dist: typing-inspection (==0.4.2)
31
+ Requires-Dist: urllib3 (==2.6.2)
27
32
  Requires-Dist: waitress (==3.0.2)
28
33
  Requires-Dist: werkzeug (==3.1.4)
29
34
  Description-Content-Type: text/markdown
@@ -0,0 +1,9 @@
1
+ pyquoks/__init__.py,sha256=u62PPaulBuYAxCYvLzsPkJb9hezXHCg6ZONHmnCJf-I,120
2
+ pyquoks/data.py,sha256=p9ieX1Uh-ke24WtdOTGhg9jm4-zG55zFwXpvXHX5fwk,17786
3
+ pyquoks/localhost.py,sha256=HPixbz33l4ZkLrk__kbb4mekPjJKA78-Lpi3AjCWvgs,1062
4
+ pyquoks/test.py,sha256=Hx3cLng0uDMDVMx-NveLOPlgpX51A00aVELa0sbR5D0,3379
5
+ pyquoks/utils.py,sha256=6uC5QUtPtVt4G5iiP2jog0t-4IUshUQPshJwmsEwmqg,1475
6
+ pyquoks-2.2.1.dist-info/licenses/LICENSE,sha256=eEd8UIYxvKUY7vqrV1XTFo70_FQdiW6o1fznseCXRJs,1095
7
+ pyquoks-2.2.1.dist-info/METADATA,sha256=zI1GGBVSsdrRTwSA0HhuLKrQ2qNKwtSIBq1aCNuUz6s,1866
8
+ pyquoks-2.2.1.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
9
+ pyquoks-2.2.1.dist-info/RECORD,,
pyquoks/models.py DELETED
@@ -1,164 +0,0 @@
1
- import typing
2
-
3
- import pyquoks.utils
4
-
5
-
6
- class _HasInitialData:
7
- """
8
- Assistive class for providing initial data
9
-
10
- Attributes:
11
- _data: Initial data that was passed into object
12
- """
13
-
14
- _data: typing.Any
15
-
16
- def __init__(self, data: typing.Any) -> None:
17
- self._data = data
18
-
19
-
20
- class Model(_HasInitialData):
21
- """
22
- Class for storing parameters and models
23
-
24
- **Optional attributes**::
25
-
26
- _ATTRIBUTES = {"beatmap_id", "score_id"}
27
-
28
- _OBJECTS = {"beatmap": BeatmapModel}
29
-
30
- Attributes:
31
- _ATTRIBUTES: Set of parameters that stored in this model
32
- _OBJECTS: Dictionary with attributes and their models
33
- _data: Initial data that was passed into object
34
- """
35
-
36
- _ATTRIBUTES: set[str] | None
37
-
38
- _OBJECTS: dict[str, type] | None
39
-
40
- _data: dict
41
-
42
- def __init__(self, data: dict) -> None:
43
- super().__init__(data)
44
-
45
- if hasattr(self, "_ATTRIBUTES"):
46
- if isinstance(self._ATTRIBUTES, set):
47
- for attribute in self._ATTRIBUTES:
48
- setattr(self, attribute, self._data.get(attribute, None))
49
- else:
50
- self._ATTRIBUTES = None
51
-
52
- if hasattr(self, "_OBJECTS"):
53
- if isinstance(self._OBJECTS, dict):
54
- for attribute, object_class in self._OBJECTS.items():
55
- try:
56
- setattr(self, attribute, object_class(self._data.get(attribute)))
57
- except Exception:
58
- setattr(self, attribute, None)
59
- else:
60
- self._OBJECTS = None
61
-
62
-
63
- class Container(Model, _HasInitialData):
64
- """
65
- Class for storing lists of models and another parameters
66
-
67
- **Optional attributes**::
68
-
69
- _ATTRIBUTES = {"beatmap_id", "score_id"}
70
-
71
- _OBJECTS = {"beatmap": BeatmapModel}
72
-
73
- _DATA = {"scores": ScoreModel}
74
-
75
- Attributes:
76
- _ATTRIBUTES: Set of parameters that stored in this container
77
- _OBJECTS: Dictionary with attributes and their models
78
- _DATA: Dictionary with attributes and models stored in their lists
79
- _data: Initial data that was passed into object
80
- """
81
-
82
- _ATTRIBUTES: set[str] | None
83
-
84
- _OBJECTS: dict[str, type] | None
85
-
86
- _DATA: dict[str, type] | None
87
-
88
- _data: dict
89
-
90
- def __init__(self, data: dict) -> None:
91
- super().__init__(data)
92
-
93
- if hasattr(self, "_DATA"):
94
- if isinstance(self._DATA, dict):
95
- for attribute, object_class in self._DATA.items():
96
- try:
97
- setattr(self, attribute, [object_class(data) for data in self._data.get(attribute)])
98
- except Exception:
99
- setattr(self, attribute, None)
100
- else:
101
- self._DATA = None
102
-
103
-
104
- class Listing(_HasInitialData):
105
- """
106
- Class for storing list of models
107
-
108
- **Optional attributes**::
109
-
110
- _DATA = {"scores": ScoreModel}
111
-
112
- Attributes:
113
- _DATA: Dictionary with attribute and model stored in list
114
- _data: Initial data that was passed into object
115
- """
116
-
117
- _DATA: dict[str, type] | None
118
-
119
- _data: list
120
-
121
- def __init__(self, data: list) -> None:
122
- super().__init__(data)
123
-
124
- if hasattr(self, "_DATA"):
125
- if isinstance(self._DATA, dict):
126
- for attribute, object_class in self._DATA.items():
127
- try:
128
- setattr(self, attribute, [object_class(data) for data in self._data])
129
- except Exception:
130
- setattr(self, attribute, None)
131
- else:
132
- self._DATA = None
133
-
134
-
135
- class Values(pyquoks.utils._HasRequiredAttributes):
136
- """
137
- Class for storing various parameters and values
138
-
139
- **Required attributes**::
140
-
141
- _ATTRIBUTES = {"settings", "path"}
142
-
143
- Attributes:
144
- _ATTRIBUTES: Attributes that can be stored in this class
145
- """
146
-
147
- _REQUIRED_ATTRIBUTES = {
148
- "_ATTRIBUTES",
149
- }
150
-
151
- _ATTRIBUTES: set[str]
152
-
153
- def __init__(self, **kwargs) -> None:
154
- self._check_attributes()
155
-
156
- for attribute in self._ATTRIBUTES:
157
- setattr(self, attribute, kwargs.get(attribute, getattr(self, attribute, None)))
158
-
159
- def update(self, **kwargs) -> None:
160
- """
161
- Updates provided attributes in object
162
- """
163
-
164
- self.__init__(**kwargs)
@@ -1,10 +0,0 @@
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,,