pyquoks 2.2.1.1__py3-none-any.whl → 2.3.0__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 CHANGED
@@ -23,14 +23,11 @@ class AssetsProvider(pyquoks.utils._HasRequiredAttributes):
23
23
 
24
24
  **Required attributes**::
25
25
 
26
- _OBJECTS = {"images": ImagesDirectory, "example": ExampleNetwork}
27
-
28
26
  # Predefined:
29
27
 
30
28
  _PATH = pyquoks.utils.get_path("assets/")
31
29
 
32
30
  Attributes:
33
- _OBJECTS: Dictionary with names of attributes and child objects
34
31
  _PATH: Path to the directory with assets folders
35
32
  """
36
33
 
@@ -123,19 +120,21 @@ class AssetsProvider(pyquoks.utils._HasRequiredAttributes):
123
120
  setattr(self, attribute, None)
124
121
 
125
122
  _REQUIRED_ATTRIBUTES = {
126
- "_OBJECTS",
127
123
  "_PATH",
128
124
  }
129
125
 
130
- _OBJECTS: dict[str, type]
131
-
132
126
  _PATH: str = pyquoks.utils.get_path("assets/")
133
127
 
134
128
  def __init__(self) -> None:
135
129
  self._check_attributes()
136
130
 
137
- for attribute, child_class in self._OBJECTS.items():
138
- setattr(self, attribute, child_class(self))
131
+ for attribute, child_class in self.__class__.__annotations__.items():
132
+ if issubclass(child_class, AssetsProvider.Directory | AssetsProvider.Network):
133
+ setattr(self, attribute, child_class(self))
134
+ else:
135
+ raise AttributeError(
136
+ f"{attribute} has incorrect type! (must be subclass of {AssetsProvider.Directory.__name__} or {AssetsProvider.Network.__name__})",
137
+ )
139
138
 
140
139
  @staticmethod
141
140
  def file_image(path: str) -> PIL.Image.Image:
@@ -161,16 +160,9 @@ class AssetsProvider(pyquoks.utils._HasRequiredAttributes):
161
160
  )
162
161
 
163
162
 
164
- class StringsProvider(pyquoks.utils._HasRequiredAttributes):
163
+ class StringsProvider:
165
164
  """
166
165
  Class for providing various strings data
167
-
168
- **Required attributes**::
169
-
170
- _OBJECTS = {"menu": MenuStrings}
171
-
172
- Attributes:
173
- _OBJECTS: Dictionary with names of attributes and child objects
174
166
  """
175
167
 
176
168
  class Strings:
@@ -182,17 +174,14 @@ class StringsProvider(pyquoks.utils._HasRequiredAttributes):
182
174
  def __init__(self, parent: StringsProvider) -> None:
183
175
  ... # TODO
184
176
 
185
- _REQUIRED_ATTRIBUTES = {
186
- "_OBJECTS",
187
- }
188
-
189
- _OBJECTS: dict[str, type]
190
-
191
177
  def __init__(self) -> None:
192
- self._check_attributes()
193
-
194
- for attribute, child_class in self._OBJECTS.items():
195
- setattr(self, attribute, child_class(self))
178
+ for attribute, child_class in self.__class__.__annotations__.items():
179
+ if issubclass(child_class, StringsProvider.Strings):
180
+ setattr(self, attribute, child_class(self))
181
+ else:
182
+ raise AttributeError(
183
+ f"{attribute} has incorrect type! (must be subclass of {StringsProvider.Strings.__name__})",
184
+ )
196
185
 
197
186
 
198
187
  # endregion
@@ -205,14 +194,11 @@ class ConfigManager(pyquoks.utils._HasRequiredAttributes):
205
194
 
206
195
  **Required attributes**::
207
196
 
208
- _OBJECTS = {"settings": SettingsConfig}
209
-
210
197
  # Predefined
211
198
 
212
199
  _PATH = pyquoks.utils.get_path("config.ini")
213
200
 
214
201
  Attributes:
215
- _OBJECTS: Dictionary with names of attributes and child objects
216
202
  _PATH: Path to the configuration file
217
203
  """
218
204
 
@@ -333,19 +319,21 @@ class ConfigManager(pyquoks.utils._HasRequiredAttributes):
333
319
  self._config.write(file)
334
320
 
335
321
  _REQUIRED_ATTRIBUTES = {
336
- "_OBJECTS",
337
322
  "_PATH",
338
323
  }
339
324
 
340
- _OBJECTS: dict[str, type]
341
-
342
325
  _PATH: str = pyquoks.utils.get_path("config.ini")
343
326
 
344
327
  def __init__(self) -> None:
345
328
  self._check_attributes()
346
329
 
347
- for attribute, child_class in self._OBJECTS.items():
348
- setattr(self, attribute, child_class(self))
330
+ for attribute, child_class in self.__class__.__annotations__.items():
331
+ if issubclass(child_class, ConfigManager.Config):
332
+ setattr(self, attribute, child_class(self))
333
+ else:
334
+ raise AttributeError(
335
+ f"{attribute} has incorrect type! (must be subclass of {ConfigManager.Config.__name__})",
336
+ )
349
337
 
350
338
 
351
339
  class DataManager(pyquoks.utils._HasRequiredAttributes):
@@ -354,8 +342,6 @@ class DataManager(pyquoks.utils._HasRequiredAttributes):
354
342
 
355
343
  **Required attributes**::
356
344
 
357
- _OBJECTS = {"users": list[UserModel]}
358
-
359
345
  # Predefined:
360
346
 
361
347
  _PATH = pyquoks.utils.get_path("data/")
@@ -363,19 +349,15 @@ class DataManager(pyquoks.utils._HasRequiredAttributes):
363
349
  _FILENAME = "{0}.json"
364
350
 
365
351
  Attributes:
366
- _OBJECTS: Dictionary with filenames and types of models
367
352
  _PATH: Path to the directory with JSON-like files
368
353
  _FILENAME: Filename of JSON-like files
369
354
  """
370
355
 
371
356
  _REQUIRED_ATTRIBUTES = {
372
- "_OBJECTS",
373
357
  "_PATH",
374
358
  "_FILENAME",
375
359
  }
376
360
 
377
- _OBJECTS: dict[str, type[pydantic.BaseModel] | list[type[pydantic.BaseModel]]]
378
-
379
361
  _PATH: str = pyquoks.utils.get_path("data/")
380
362
 
381
363
  _FILENAME: str = "{0}.json"
@@ -383,17 +365,28 @@ class DataManager(pyquoks.utils._HasRequiredAttributes):
383
365
  def __init__(self) -> None:
384
366
  self._check_attributes()
385
367
 
386
- for attribute, object_type in self._OBJECTS.items():
387
- try:
388
- with open(self._PATH + self._FILENAME.format(attribute), "rb") as file:
389
- data = json.loads(file.read())
368
+ for attribute, object_type in self.__class__.__annotations__.items():
369
+ if issubclass(
370
+ typing.get_args(object_type)[0],
371
+ pydantic.BaseModel,
372
+ ) if typing.get_origin(object_type) else issubclass(
373
+ object_type,
374
+ pydantic.BaseModel,
375
+ ):
376
+ try:
377
+ with open(self._PATH + self._FILENAME.format(attribute), "rb") as file:
378
+ data = json.loads(file.read())
390
379
 
391
- if typing.get_origin(object_type) == list:
392
- setattr(self, attribute, [typing.get_args(object_type)[0](**model) for model in data])
393
- else:
394
- setattr(self, attribute, object_type(**data))
395
- except Exception:
396
- setattr(self, attribute, None)
380
+ if typing.get_origin(object_type) == list:
381
+ setattr(self, attribute, [typing.get_args(object_type)[0](**model) for model in data])
382
+ else:
383
+ setattr(self, attribute, object_type(**data))
384
+ except Exception:
385
+ setattr(self, attribute, None)
386
+ else:
387
+ raise AttributeError(
388
+ f"{attribute} has incorrect type! (must be subclass of {pydantic.BaseModel.__name__} or {list.__name__} of its subclasses)",
389
+ )
397
390
 
398
391
  def update(self, **kwargs) -> None:
399
392
  """
@@ -403,10 +396,10 @@ class DataManager(pyquoks.utils._HasRequiredAttributes):
403
396
  for attribute, value in kwargs.items():
404
397
  value: pydantic.BaseModel | list[pydantic.BaseModel]
405
398
 
406
- if attribute not in self._OBJECTS.keys():
399
+ if attribute not in self.__class__.__annotations__.keys():
407
400
  raise AttributeError(f"{attribute} is not specified!")
408
401
 
409
- object_type = self._OBJECTS.get(attribute)
402
+ object_type = self.__class__.__annotations__.get(attribute)
410
403
 
411
404
  if not isinstance(
412
405
  value,
@@ -440,14 +433,11 @@ class DatabaseManager(pyquoks.utils._HasRequiredAttributes):
440
433
 
441
434
  **Required attributes**::
442
435
 
443
- _OBJECTS = {"users": UsersDatabase}
444
-
445
436
  # Predefined
446
437
 
447
438
  _PATH = pyquoks.utils.get_path("db/")
448
439
 
449
440
  Attributes:
450
- _OBJECTS: Dictionary with names of attributes and child objects
451
441
  _PATH: Path to the directory with databases
452
442
  """
453
443
 
@@ -511,12 +501,9 @@ class DatabaseManager(pyquoks.utils._HasRequiredAttributes):
511
501
  self.commit()
512
502
 
513
503
  _REQUIRED_ATTRIBUTES = {
514
- "_OBJECTS",
515
504
  "_PATH",
516
505
  }
517
506
 
518
- _OBJECTS: dict[str, type]
519
-
520
507
  _PATH: str = pyquoks.utils.get_path("db/")
521
508
 
522
509
  def __init__(self) -> None:
@@ -527,15 +514,20 @@ class DatabaseManager(pyquoks.utils._HasRequiredAttributes):
527
514
  exist_ok=True,
528
515
  )
529
516
 
530
- for attribute, child_class in self._OBJECTS.items():
531
- setattr(self, attribute, child_class(self))
517
+ for attribute, child_class in self.__class__.__annotations__.items():
518
+ if issubclass(child_class, DatabaseManager.Database):
519
+ setattr(self, attribute, child_class(self))
520
+ else:
521
+ raise AttributeError(
522
+ f"{attribute} has incorrect type! (must be subclass of {DatabaseManager.Database.__name__})",
523
+ )
532
524
 
533
525
  def close_all(self) -> None:
534
526
  """
535
527
  Closes all database connections
536
528
  """
537
529
 
538
- for attribute in self._OBJECTS.keys():
530
+ for attribute in self.__class__.__annotations__.keys():
539
531
  getattr(self, attribute).close()
540
532
 
541
533
 
pyquoks/utils.py CHANGED
@@ -1,29 +1,26 @@
1
1
  import datetime
2
2
  import os
3
+ import platform
4
+ import subprocess
3
5
  import sys
4
6
 
5
7
  import psutil
6
8
 
7
9
 
8
- class _HasRequiredAttributes:
10
+ def check_connection() -> bool:
9
11
  """
10
- Assistive class for checking required attributes
11
-
12
- **Required attributes**::
13
-
14
- _REQUIRED_ATTRIBUTES = {"_ATTRIBUTES", "_OBJECTS"}
15
-
16
- Attributes:
17
- _REQUIRED_ATTRIBUTES: Set of required attributes in the class
12
+ :return: Status of "ping www.google.com"
18
13
  """
19
14
 
20
- _REQUIRED_ATTRIBUTES: set[str]
21
-
22
- def _check_attributes(self) -> None:
23
- if hasattr(self, "_REQUIRED_ATTRIBUTES"):
24
- for attribute in self._REQUIRED_ATTRIBUTES:
25
- if not hasattr(self, attribute):
26
- raise AttributeError(f"The required class attribute is not set! ({attribute})")
15
+ return subprocess.run(
16
+ args=[
17
+ "ping",
18
+ "-n" if platform.system().lower() == "windows" else "-c",
19
+ "1",
20
+ "www.google.com",
21
+ ],
22
+ capture_output=True,
23
+ ).returncode == 0
27
24
 
28
25
 
29
26
  def get_path(relative_path: str, use_meipass: bool = False) -> str:
@@ -52,3 +49,24 @@ def get_process_created_datetime(pid: int = os.getpid()) -> datetime.datetime:
52
49
  return datetime.datetime.fromtimestamp(
53
50
  timestamp=process.create_time(),
54
51
  )
52
+
53
+
54
+ class _HasRequiredAttributes:
55
+ """
56
+ Assistive class for checking required attributes
57
+
58
+ **Required attributes**::
59
+
60
+ _REQUIRED_ATTRIBUTES = {"_ATTRIBUTES", "_PATH"}
61
+
62
+ Attributes:
63
+ _REQUIRED_ATTRIBUTES: Set of required attributes in the class
64
+ """
65
+
66
+ _REQUIRED_ATTRIBUTES: set[str]
67
+
68
+ def _check_attributes(self) -> None:
69
+ if hasattr(self, "_REQUIRED_ATTRIBUTES"):
70
+ for attribute in self._REQUIRED_ATTRIBUTES:
71
+ if not hasattr(self, attribute):
72
+ raise AttributeError(f"The required class attribute is not set! ({attribute})")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyquoks
3
- Version: 2.2.1.1
3
+ Version: 2.3.0
4
4
  Summary: Пакет PyPI для часто используемых модулей в проектах diquoks
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -22,7 +22,7 @@ Requires-Dist: itsdangerous (==2.2.0)
22
22
  Requires-Dist: jinja2 (==3.1.6)
23
23
  Requires-Dist: markupsafe (==3.0.3)
24
24
  Requires-Dist: pillow (==12.0.0)
25
- Requires-Dist: psutil (==7.1.3)
25
+ Requires-Dist: psutil (==7.2.1)
26
26
  Requires-Dist: pydantic (==2.12.5)
27
27
  Requires-Dist: pydantic-core (==2.41.5)
28
28
  Requires-Dist: requests (==2.32.5)
@@ -0,0 +1,9 @@
1
+ pyquoks/__init__.py,sha256=u62PPaulBuYAxCYvLzsPkJb9hezXHCg6ZONHmnCJf-I,120
2
+ pyquoks/data.py,sha256=LkoMEDK-WVrVDktGjAW-h0SDy64ONQK1zJx0FRwRc4U,18790
3
+ pyquoks/localhost.py,sha256=HPixbz33l4ZkLrk__kbb4mekPjJKA78-Lpi3AjCWvgs,1062
4
+ pyquoks/test.py,sha256=Hx3cLng0uDMDVMx-NveLOPlgpX51A00aVELa0sbR5D0,3379
5
+ pyquoks/utils.py,sha256=shCyMYgpg8pGSJLuHqO4nEWDeTOAc7b5BjlgDVhvZV4,1861
6
+ pyquoks-2.3.0.dist-info/licenses/LICENSE,sha256=eEd8UIYxvKUY7vqrV1XTFo70_FQdiW6o1fznseCXRJs,1095
7
+ pyquoks-2.3.0.dist-info/METADATA,sha256=1DduBlhlVnJhiBK-OctUC6Ys65insZ2aZ2i17zU8OpY,1866
8
+ pyquoks-2.3.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
9
+ pyquoks-2.3.0.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- pyquoks/__init__.py,sha256=u62PPaulBuYAxCYvLzsPkJb9hezXHCg6ZONHmnCJf-I,120
2
- pyquoks/data.py,sha256=xvydnHUAILEK9kqI5UYY8KS36Hf3ORK9ZwgwAt8K318,18132
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.1.dist-info/licenses/LICENSE,sha256=eEd8UIYxvKUY7vqrV1XTFo70_FQdiW6o1fznseCXRJs,1095
7
- pyquoks-2.2.1.1.dist-info/METADATA,sha256=PjmiP5rZQ1XNEs7_wUS9KTvB6cEVVUQF_S_vGLzoOjY,1868
8
- pyquoks-2.2.1.1.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
9
- pyquoks-2.2.1.1.dist-info/RECORD,,