pyquoks 0.0.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.
__init__.py ADDED
@@ -0,0 +1 @@
1
+ from pyquoks import data, models, utils
pyquoks/__init__.py ADDED
File without changes
pyquoks/data.py ADDED
@@ -0,0 +1,191 @@
1
+ from __future__ import annotations
2
+ import configparser, datetime, logging, winreg, json, sys, io, os
3
+ import requests, PIL.Image, PIL.ImageDraw
4
+ from . import utils
5
+
6
+
7
+ # Providers
8
+ class IDataProvider:
9
+ _PATH: str
10
+ _DATA_VALUES: dict[str, type]
11
+
12
+ def __init__(self) -> None:
13
+ for k, v in self._DATA_VALUES.items():
14
+ try:
15
+ with open(self._PATH.format(k), "rb") as file:
16
+ setattr(self, k, v(json_data=json.loads(file.read())))
17
+ except:
18
+ setattr(self, k, None)
19
+
20
+
21
+ class IConfigProvider:
22
+ class IConfig:
23
+ _SECTION: str = None
24
+ _CONFIG_VALUES: dict[str, type]
25
+
26
+ def __init__(self, parent: IConfigProvider = None) -> None:
27
+ if isinstance(parent, IConfigProvider):
28
+ self._CONFIG_VALUES = parent._CONFIG_VALUES.get(self._SECTION)
29
+ self._incorrect_content_exception = configparser.ParsingError("config.ini is filled incorrectly!")
30
+ self._config = configparser.ConfigParser()
31
+ self._config.read(utils.get_path("config.ini"))
32
+ if not self._config.has_section(self._SECTION):
33
+ self._config.add_section(self._SECTION)
34
+ for k, v in self._CONFIG_VALUES.items():
35
+ try:
36
+ setattr(self, k, self._config.get(self._SECTION, k))
37
+ except:
38
+ self._config.set(self._SECTION, k, v.__name__)
39
+ with open(utils.get_path("config.ini"), "w") as file:
40
+ self._config.write(fp=file)
41
+ for k, v in self._CONFIG_VALUES.items():
42
+ try:
43
+ if v == int:
44
+ setattr(self, k, int(getattr(self, k)))
45
+ elif v == bool:
46
+ if getattr(self, k) not in (str(True), str(False)):
47
+ setattr(self, k, None)
48
+ raise self._incorrect_content_exception
49
+ else:
50
+ setattr(self, k, getattr(self, k) == str(True))
51
+ elif v in (dict, list):
52
+ setattr(self, k, json.loads(getattr(self, k)))
53
+ except:
54
+ setattr(self, k, None)
55
+ raise self._incorrect_content_exception
56
+ if not self.values:
57
+ raise self._incorrect_content_exception
58
+
59
+ @property
60
+ def values(self) -> dict | None:
61
+ try:
62
+ return {i: getattr(self, i) for i in self._CONFIG_VALUES}
63
+ except:
64
+ return None
65
+
66
+ _CONFIG_VALUES: dict[str, dict[str, type]]
67
+ _CONFIG_OBJECTS: dict[str, type]
68
+
69
+ def __init__(self) -> None:
70
+ for k, v in self._CONFIG_OBJECTS.items():
71
+ setattr(self, k, v(self))
72
+
73
+
74
+ class IAssetsProvider:
75
+ class IDirectory:
76
+ _PATH: str = None
77
+ _NAMES: set[str]
78
+
79
+ def __init__(self, parent: IAssetsProvider):
80
+ for i in self._NAMES:
81
+ setattr(self, i, parent.file_image(parent._PATH.format(self._PATH.format(i))))
82
+
83
+ class INetwork:
84
+ _URLS: dict[str, str]
85
+
86
+ def __init__(self, parent: IAssetsProvider):
87
+ for k, v in self._URLS:
88
+ setattr(self, k, parent.network_image(v))
89
+
90
+ _PATH: str
91
+ _ASSETS_OBJECTS: dict[str, type]
92
+
93
+ def __init__(self):
94
+ for k, v in self._ASSETS_OBJECTS.items():
95
+ setattr(self, k, v(self))
96
+
97
+ @staticmethod
98
+ def file_image(path: str) -> PIL.Image.Image:
99
+ with open(path, "rb") as file:
100
+ return PIL.Image.open(io.BytesIO(file.read()))
101
+
102
+ @staticmethod
103
+ def network_image(url: str) -> PIL.Image.Image:
104
+ return PIL.Image.open(io.BytesIO(requests.get(url).content))
105
+
106
+ @staticmethod
107
+ def round_corners(image: PIL.Image.Image, radius: int) -> PIL.Image.Image:
108
+ if image.mode != "RGB":
109
+ image = image.convert("RGB")
110
+ width, height = image.size
111
+ shape = PIL.Image.new("L", (radius * 2, radius * 2), 0)
112
+ alpha = PIL.Image.new("L", image.size, "white")
113
+ PIL.ImageDraw.Draw(shape).ellipse((0, 0, radius * 2, radius * 2), fill=255)
114
+ alpha.paste(shape.crop((0, 0, radius, radius)), (0, 0))
115
+ alpha.paste(shape.crop((0, radius, radius, radius * 2)), (0, height - radius))
116
+ alpha.paste(shape.crop((radius, 0, radius * 2, radius)), (width - radius, 0))
117
+ alpha.paste(shape.crop((radius, radius, radius * 2, radius * 2)), (width - radius, height - radius))
118
+ image.putalpha(alpha)
119
+ return image
120
+
121
+
122
+ class IStringsProvider:
123
+ _STRINGS_OBJECTS: dict[str, type]
124
+
125
+ def __init__(self):
126
+ for k, v in self._STRINGS_OBJECTS.items():
127
+ setattr(self, k, v())
128
+
129
+
130
+ # Managers
131
+ class IRegistryManager:
132
+ class IRegistry:
133
+ _NAME: str = None
134
+ _REGISTRY_VALUES: dict[str, int]
135
+
136
+ def __init__(self, parent: IRegistryManager = None) -> None:
137
+ if isinstance(parent, IRegistryManager):
138
+ self._REGISTRY_VALUES = parent._REGISTRY_VALUES.get(self._NAME)
139
+ self._path = winreg.CreateKey(parent._path, self._NAME)
140
+ for i in self._REGISTRY_VALUES.keys():
141
+ try:
142
+ setattr(self, i, winreg.QueryValueEx(self._path, i)[int()])
143
+ except:
144
+ setattr(self, i, None)
145
+
146
+ @property
147
+ def values(self) -> dict | None:
148
+ try:
149
+ return {i: getattr(self, i) for i in self._REGISTRY_VALUES}
150
+ except:
151
+ return None
152
+
153
+ def refresh(self) -> IRegistryManager.IRegistry:
154
+ self.__init__()
155
+ return self
156
+
157
+ def update(self, **kwargs) -> None:
158
+ for k, v in kwargs.items():
159
+ winreg.SetValueEx(self._path, k, None, self._REGISTRY_VALUES.get(k), v)
160
+ setattr(self, k, v)
161
+
162
+ _KEY: str
163
+ _REGISTRY_VALUES: dict[str, dict[str, int]]
164
+ _REGISTRY_OBJECTS: dict[str, type]
165
+ _path: winreg.HKEYType
166
+
167
+ def __init__(self) -> None:
168
+ self._path = winreg.CreateKey(winreg.HKEY_CURRENT_USER, self._KEY)
169
+ for k, v in self._REGISTRY_OBJECTS.items():
170
+ setattr(self, k, v(self))
171
+
172
+ def refresh(self) -> IRegistryManager:
173
+ self.__init__()
174
+ return self
175
+
176
+
177
+ # Services
178
+ class LoggerService(logging.Logger):
179
+ def __init__(self, name: str, file_handling: bool = True, filename: str = datetime.datetime.now().strftime("%d-%m-%y-%H-%M-%S"), level: int = logging.NOTSET, folder_name: str = "logs") -> None:
180
+ super().__init__(name, level)
181
+ stream_handler = logging.StreamHandler(sys.stdout)
182
+ stream_handler.setFormatter(logging.Formatter(fmt="$levelname $asctime $name - $message", datefmt="%d-%m-%y %H:%M:%S", style="$"))
183
+ self.addHandler(stream_handler)
184
+ if file_handling:
185
+ os.makedirs(utils.get_path(folder_name, only_abspath=True), exist_ok=True)
186
+ file_handler = logging.FileHandler(utils.get_path(f"{folder_name}/{filename}-{name}.log", only_abspath=True), encoding="utf-8")
187
+ file_handler.setFormatter(logging.Formatter(fmt="$levelname $asctime - $message", datefmt="%d-%m-%y %H:%M:%S", style="$"))
188
+ self.addHandler(file_handler)
189
+
190
+ def log_exception(self, e: Exception) -> None:
191
+ self.error(msg=e, exc_info=True)
pyquoks/models.py ADDED
@@ -0,0 +1,63 @@
1
+ from __future__ import annotations
2
+
3
+
4
+ class IContainer:
5
+ _ATTRIBUTES: set[str] = None
6
+ _DATA: dict[str, type] = None
7
+ _OBJECTS: dict[str, type] = None
8
+ data: dict
9
+
10
+ def __init__(self, json_data: dict):
11
+ setattr(self, "data", json_data)
12
+ if isinstance(self._ATTRIBUTES, set):
13
+ for i in self._ATTRIBUTES:
14
+ setattr(self, i, self.data.get(i, None))
15
+ if isinstance(self._DATA, dict):
16
+ for k, v in self._DATA.items():
17
+ try:
18
+ setattr(self, k, [v(i) for i in self.data])
19
+ except:
20
+ setattr(self, k, None)
21
+ elif isinstance(self._OBJECTS, dict):
22
+ for k, v in self._OBJECTS.items():
23
+ try:
24
+ setattr(self, k, [v(i) for i in self.data.get(k)])
25
+ except:
26
+ setattr(self, k, None)
27
+
28
+
29
+ class IModel:
30
+ _ATTRIBUTES: set[str] | dict[str, set[str]] = None
31
+ _OBJECTS: dict[str, type] = None
32
+ data: dict | list[dict]
33
+
34
+ def __init__(self, json_data: dict | list[dict]):
35
+ setattr(self, "data", json_data)
36
+ if isinstance(self._ATTRIBUTES, set):
37
+ for i in self._ATTRIBUTES:
38
+ setattr(self, i, self.data.get(i, None))
39
+ elif isinstance(self._ATTRIBUTES, dict):
40
+ for k, v in self._ATTRIBUTES.items():
41
+ if isinstance(v, set):
42
+ for i in v:
43
+ try:
44
+ setattr(self, i, self.data.get(k).get(i, None))
45
+ except:
46
+ setattr(self, i, None)
47
+ if isinstance(self._OBJECTS, dict):
48
+ for k, v in self._OBJECTS.items():
49
+ try:
50
+ setattr(self, k, v(self.data.get(k)))
51
+ except:
52
+ setattr(self, k, None)
53
+
54
+
55
+ class IValues:
56
+ _ATTRIBUTES: set[str] = None
57
+
58
+ def __init__(self, **kwargs):
59
+ for i in self._ATTRIBUTES:
60
+ setattr(self, i, kwargs.get(i, None))
61
+
62
+ def update(self, **kwargs):
63
+ self.__init__(**kwargs)
pyquoks/utils.py ADDED
@@ -0,0 +1,13 @@
1
+ from __future__ import annotations
2
+ import sys, os
3
+
4
+
5
+ def get_path(relative_path: str, only_abspath: bool = False) -> str:
6
+ try:
7
+ base_path = sys._MEIPASS
8
+ except:
9
+ base_path = os.path.abspath("..")
10
+ finally:
11
+ if only_abspath:
12
+ base_path = os.path.abspath("..")
13
+ return os.path.join(base_path, relative_path)
@@ -0,0 +1,5 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyquoks
3
+ Version: 0.0.0
4
+ License-File: LICENSE
5
+ Dynamic: license-file
@@ -0,0 +1,10 @@
1
+ __init__.py,sha256=8ph_71TsetPLJ4GmDhUsK6J6P2Vmii1nQcPqs2HHZlw,41
2
+ pyquoks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ pyquoks/data.py,sha256=Ub9VykwcMaNEDKUSCtejSJLcDO_q501GEBRiQfciliw,7665
4
+ pyquoks/models.py,sha256=IRn-bUoCuFqiYLR420pL-S6tAC2nYGjnVJR_6UzbYtk,2155
5
+ pyquoks/utils.py,sha256=mLYQQcNRNJJHBn22XGgd2J2Hg0IgU1YoEc8avBh310s,364
6
+ pyquoks-0.0.0.dist-info/licenses/LICENSE,sha256=eEd8UIYxvKUY7vqrV1XTFo70_FQdiW6o1fznseCXRJs,1095
7
+ pyquoks-0.0.0.dist-info/METADATA,sha256=p3SHdkwP9u9_PPejwGFgnY1Z4ymm0OyxVhr7jBmazXA,100
8
+ pyquoks-0.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ pyquoks-0.0.0.dist-info/top_level.txt,sha256=i5kNjs5WLNNvU-YjutYM-OG6P30Gur6a-culADpmvKk,17
10
+ pyquoks-0.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Denis Titovets
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ __init__
2
+ pyquoks