absfuyu 3.2.0__py3-none-any.whl → 3.4.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.
Potentially problematic release.
This version of absfuyu might be problematic. Click here for more details.
- absfuyu/__init__.py +3 -10
- absfuyu/__main__.py +5 -250
- absfuyu/cli/__init__.py +51 -0
- absfuyu/cli/color.py +24 -0
- absfuyu/cli/config_group.py +56 -0
- absfuyu/cli/do_group.py +98 -0
- absfuyu/cli/game_group.py +109 -0
- absfuyu/config/__init__.py +55 -94
- absfuyu/config/config.json +0 -7
- absfuyu/core.py +5 -66
- absfuyu/everything.py +7 -9
- absfuyu/extensions/beautiful.py +30 -23
- absfuyu/extensions/dev/__init__.py +11 -8
- absfuyu/extensions/dev/password_hash.py +4 -2
- absfuyu/extensions/dev/passwordlib.py +7 -5
- absfuyu/extensions/dev/project_starter.py +4 -2
- absfuyu/extensions/dev/shutdownizer.py +148 -0
- absfuyu/extensions/extra/__init__.py +1 -2
- absfuyu/extensions/extra/data_analysis.py +110 -58
- absfuyu/fun/WGS.py +50 -26
- absfuyu/fun/__init__.py +6 -7
- absfuyu/fun/tarot.py +1 -1
- absfuyu/game/__init__.py +75 -81
- absfuyu/game/game_stat.py +36 -0
- absfuyu/game/sudoku.py +41 -48
- absfuyu/game/tictactoe.py +303 -548
- absfuyu/game/wordle.py +56 -47
- absfuyu/general/__init__.py +17 -7
- absfuyu/general/content.py +16 -15
- absfuyu/general/data_extension.py +314 -109
- absfuyu/general/generator.py +67 -67
- absfuyu/general/human.py +148 -78
- absfuyu/logger.py +94 -68
- absfuyu/pkg_data/__init__.py +29 -25
- absfuyu/py.typed +0 -0
- absfuyu/sort.py +61 -47
- absfuyu/tools/__init__.py +0 -1
- absfuyu/tools/converter.py +80 -62
- absfuyu/tools/keygen.py +62 -67
- absfuyu/tools/obfuscator.py +57 -53
- absfuyu/tools/stats.py +24 -24
- absfuyu/tools/web.py +10 -9
- absfuyu/util/__init__.py +38 -40
- absfuyu/util/api.py +53 -43
- absfuyu/util/json_method.py +25 -27
- absfuyu/util/lunar.py +20 -24
- absfuyu/util/path.py +362 -241
- absfuyu/util/performance.py +36 -98
- absfuyu/util/pkl.py +8 -8
- absfuyu/util/zipped.py +17 -19
- absfuyu/version.py +137 -148
- absfuyu-3.4.0.dist-info/METADATA +124 -0
- absfuyu-3.4.0.dist-info/RECORD +59 -0
- {absfuyu-3.2.0.dist-info → absfuyu-3.4.0.dist-info}/WHEEL +1 -2
- {absfuyu-3.2.0.dist-info → absfuyu-3.4.0.dist-info}/entry_points.txt +1 -0
- {absfuyu-3.2.0.dist-info → absfuyu-3.4.0.dist-info/licenses}/LICENSE +1 -1
- absfuyu/extensions/dev/pkglib.py +0 -98
- absfuyu/game/tictactoe2.py +0 -318
- absfuyu-3.2.0.dist-info/METADATA +0 -216
- absfuyu-3.2.0.dist-info/RECORD +0 -55
- absfuyu-3.2.0.dist-info/top_level.txt +0 -1
absfuyu/config/__init__.py
CHANGED
|
@@ -3,11 +3,10 @@ Absfuyu: Configuration
|
|
|
3
3
|
----------------------
|
|
4
4
|
Package configuration module
|
|
5
5
|
|
|
6
|
-
Version: 2.0.
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 2.0.4
|
|
7
|
+
Date updated: 06/04/2024 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
|
-
|
|
11
10
|
# Module level
|
|
12
11
|
###########################################################################
|
|
13
12
|
__all__ = [
|
|
@@ -20,15 +19,14 @@ __all__ = [
|
|
|
20
19
|
# Library
|
|
21
20
|
###########################################################################
|
|
22
21
|
from pathlib import Path
|
|
23
|
-
from typing import Any, Dict, List, Optional, TypedDict
|
|
22
|
+
from typing import Any, Dict, List, Optional, TypedDict
|
|
24
23
|
|
|
25
24
|
from absfuyu.core import CONFIG_PATH
|
|
26
25
|
from absfuyu.util.json_method import JsonFile
|
|
27
26
|
|
|
28
|
-
|
|
29
27
|
# Setting
|
|
30
28
|
###########################################################################
|
|
31
|
-
_SPACE_REPLACE = "-"
|
|
29
|
+
_SPACE_REPLACE = "-" # Replace " " character in setting name
|
|
32
30
|
|
|
33
31
|
|
|
34
32
|
# Type hint
|
|
@@ -41,25 +39,11 @@ class SettingDictFormat(TypedDict):
|
|
|
41
39
|
:param help: Description for the setting
|
|
42
40
|
:param value: Current value of the setting
|
|
43
41
|
"""
|
|
42
|
+
|
|
44
43
|
default: Any
|
|
45
44
|
help: str
|
|
46
45
|
value: Any
|
|
47
46
|
|
|
48
|
-
class VersionDictFormat(TypedDict):
|
|
49
|
-
"""
|
|
50
|
-
Format for the ``version`` section in ``config``
|
|
51
|
-
|
|
52
|
-
:param major: Major changes
|
|
53
|
-
:param minor: Minor changes
|
|
54
|
-
:param patch: Patches and fixes
|
|
55
|
-
:param release_level: Release level
|
|
56
|
-
:param serial: Release serial
|
|
57
|
-
"""
|
|
58
|
-
major: int
|
|
59
|
-
minor: int
|
|
60
|
-
patch: int
|
|
61
|
-
release_level: str
|
|
62
|
-
serial: int
|
|
63
47
|
|
|
64
48
|
class ConfigFormat(TypedDict):
|
|
65
49
|
"""
|
|
@@ -70,21 +54,16 @@ class ConfigFormat(TypedDict):
|
|
|
70
54
|
:param version: version section
|
|
71
55
|
:type version: VersionDictFormat
|
|
72
56
|
"""
|
|
57
|
+
|
|
73
58
|
setting: Dict[str, SettingDictFormat]
|
|
74
|
-
version: VersionDictFormat
|
|
75
59
|
|
|
76
60
|
|
|
77
61
|
# Class
|
|
78
62
|
###########################################################################
|
|
79
63
|
class Setting:
|
|
80
64
|
"""Setting"""
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
name: str,
|
|
84
|
-
value: Any,
|
|
85
|
-
default: Any,
|
|
86
|
-
help_: str = ""
|
|
87
|
-
) -> None:
|
|
65
|
+
|
|
66
|
+
def __init__(self, name: str, value: Any, default: Any, help_: str = "") -> None:
|
|
88
67
|
"""
|
|
89
68
|
:param name: Name of the setting
|
|
90
69
|
:param value: Value of the setting
|
|
@@ -101,29 +80,26 @@ class Setting:
|
|
|
101
80
|
|
|
102
81
|
def __repr__(self) -> str:
|
|
103
82
|
return self.__str__()
|
|
104
|
-
|
|
83
|
+
|
|
105
84
|
@classmethod
|
|
106
85
|
def from_dict(cls, dict_data: Dict[str, SettingDictFormat]):
|
|
107
86
|
"""
|
|
108
87
|
Convert ``dict`` into ``Setting`` (``len==1`` only)
|
|
109
88
|
"""
|
|
110
89
|
name: str = list(dict_data.keys())[0]
|
|
111
|
-
_val:
|
|
112
|
-
value: Any = _val
|
|
113
|
-
default: Any = _val
|
|
114
|
-
help_: str = _val
|
|
115
|
-
# value: Any = _val["value"]
|
|
116
|
-
# default: Any = _val["default"]
|
|
117
|
-
# help_: str = _val["help"]
|
|
90
|
+
_val: SettingDictFormat = list(dict_data.values())[0]
|
|
91
|
+
value: Any = _val["value"]
|
|
92
|
+
default: Any = _val["default"]
|
|
93
|
+
help_: str = _val["help"]
|
|
118
94
|
return cls(name, value, default, help_)
|
|
119
|
-
|
|
95
|
+
|
|
120
96
|
def reset(self) -> None:
|
|
121
97
|
"""
|
|
122
|
-
Reset setting to default value
|
|
98
|
+
Reset setting to default value
|
|
123
99
|
(``Setting.value = Setting.default``)
|
|
124
100
|
"""
|
|
125
101
|
self.value = self.default
|
|
126
|
-
|
|
102
|
+
|
|
127
103
|
def update_value(self, value: Any) -> None:
|
|
128
104
|
"""Update current value"""
|
|
129
105
|
self.value = value
|
|
@@ -133,11 +109,7 @@ class Setting:
|
|
|
133
109
|
Convert ``Setting`` into ``dict``
|
|
134
110
|
"""
|
|
135
111
|
output: Dict[str, SettingDictFormat] = {
|
|
136
|
-
self.name: {
|
|
137
|
-
"default": self.default,
|
|
138
|
-
"help": self.help,
|
|
139
|
-
"value": self.value
|
|
140
|
-
}
|
|
112
|
+
self.name: {"default": self.default, "help": self.help, "value": self.value}
|
|
141
113
|
}
|
|
142
114
|
return output
|
|
143
115
|
|
|
@@ -146,6 +118,7 @@ class Config:
|
|
|
146
118
|
"""
|
|
147
119
|
Config handling
|
|
148
120
|
"""
|
|
121
|
+
|
|
149
122
|
def __init__(self, config_file: Path, name: Optional[str] = None) -> None:
|
|
150
123
|
"""
|
|
151
124
|
config_file: Path to `.json` config file
|
|
@@ -159,41 +132,34 @@ class Config:
|
|
|
159
132
|
self.name = self.config_path.name
|
|
160
133
|
|
|
161
134
|
# Data
|
|
162
|
-
self.settings: List[Setting] = None
|
|
163
|
-
self.
|
|
164
|
-
self._fetch_data() # Load data
|
|
135
|
+
self.settings: List[Setting] = None # type: ignore
|
|
136
|
+
self._fetch_data() # Load data
|
|
165
137
|
|
|
166
138
|
def __str__(self) -> str:
|
|
167
139
|
return f"{self.__class__.__name__}({self.config_path.name})"
|
|
168
140
|
|
|
169
141
|
def __repr__(self) -> str:
|
|
170
142
|
return self.__str__()
|
|
171
|
-
|
|
143
|
+
|
|
172
144
|
# Data prepare and export
|
|
173
145
|
def _fetch_data(self) -> None:
|
|
174
146
|
"""Load data from ``self.config_file`` file"""
|
|
175
147
|
data: dict = self.json_engine.load_json()
|
|
176
|
-
settings: Dict[str, SettingDictFormat] = data.get("setting")
|
|
177
|
-
self.settings
|
|
178
|
-
|
|
179
|
-
|
|
148
|
+
settings: Dict[str, SettingDictFormat] = data.get("setting") # type: ignore
|
|
149
|
+
self.settings = [Setting.from_dict({k: v}) for k, v in settings.items()]
|
|
150
|
+
|
|
180
151
|
def _prepare_data(self) -> ConfigFormat:
|
|
181
152
|
"""Prepare data to save config"""
|
|
182
153
|
settings = dict()
|
|
183
154
|
for setting in self.settings:
|
|
184
155
|
settings.update(setting.to_dict())
|
|
185
156
|
|
|
186
|
-
out: ConfigFormat = {
|
|
187
|
-
"setting": settings,
|
|
188
|
-
"version": self.version
|
|
189
|
-
}
|
|
157
|
+
out: ConfigFormat = {"setting": settings}
|
|
190
158
|
return out
|
|
191
|
-
|
|
159
|
+
|
|
192
160
|
def save(self) -> None:
|
|
193
161
|
"""Save config to ``.json`` file"""
|
|
194
|
-
self.json_engine.update_data(
|
|
195
|
-
self._prepare_data()
|
|
196
|
-
)
|
|
162
|
+
self.json_engine.update_data(self._prepare_data()) # type: ignore
|
|
197
163
|
self.json_engine.save_json()
|
|
198
164
|
|
|
199
165
|
# Setting method
|
|
@@ -211,15 +177,15 @@ class Config:
|
|
|
211
177
|
return setting
|
|
212
178
|
else:
|
|
213
179
|
raise ValueError(f"Setting list: {self.setting_list}")
|
|
214
|
-
|
|
180
|
+
|
|
215
181
|
def reset_config(self) -> None:
|
|
216
182
|
"""Reset all settings to default value"""
|
|
217
|
-
[setting.reset() for setting in self.settings]
|
|
183
|
+
[setting.reset() for setting in self.settings] # type: ignore
|
|
218
184
|
self.save()
|
|
219
|
-
|
|
185
|
+
|
|
220
186
|
def show_settings(self) -> List[Setting]:
|
|
221
187
|
"""
|
|
222
|
-
Returns a list of available settings
|
|
188
|
+
Returns a list of available settings
|
|
223
189
|
(wrapper for ``Config.settings``)
|
|
224
190
|
"""
|
|
225
191
|
return self.settings
|
|
@@ -227,12 +193,12 @@ class Config:
|
|
|
227
193
|
def change_setting(self, name: str, value: Any) -> None:
|
|
228
194
|
"""
|
|
229
195
|
Change ``Setting`` (if available)
|
|
230
|
-
|
|
196
|
+
|
|
231
197
|
Parameters
|
|
232
198
|
----------
|
|
233
199
|
name : str
|
|
234
200
|
Name of the setting
|
|
235
|
-
|
|
201
|
+
|
|
236
202
|
value : Any
|
|
237
203
|
Value of the setting
|
|
238
204
|
"""
|
|
@@ -245,10 +211,10 @@ class Config:
|
|
|
245
211
|
else:
|
|
246
212
|
raise ValueError(f"Setting list: {self.setting_list}")
|
|
247
213
|
self.save()
|
|
248
|
-
|
|
214
|
+
|
|
249
215
|
def toggle_setting(self, name: str) -> None:
|
|
250
216
|
"""
|
|
251
|
-
Special ``change_setting()`` method.
|
|
217
|
+
Special ``change_setting()`` method.
|
|
252
218
|
Turn on/off if ``type(<setting>) is bool``
|
|
253
219
|
|
|
254
220
|
Parameters
|
|
@@ -263,13 +229,13 @@ class Config:
|
|
|
263
229
|
# Change value
|
|
264
230
|
try:
|
|
265
231
|
self.change_setting(name, not setting_value)
|
|
266
|
-
except:
|
|
267
|
-
raise SystemExit("This setting is not type: bool")
|
|
268
|
-
|
|
232
|
+
except Exception:
|
|
233
|
+
raise SystemExit("This setting is not type: bool") # noqa: B904
|
|
234
|
+
|
|
269
235
|
def add_setting(self, name: str, value: Any, default: Any, help_: str = "") -> None:
|
|
270
236
|
"""
|
|
271
237
|
Add ``Setting`` if not exist
|
|
272
|
-
|
|
238
|
+
|
|
273
239
|
Parameters
|
|
274
240
|
----------
|
|
275
241
|
name : str
|
|
@@ -289,44 +255,39 @@ class Config:
|
|
|
289
255
|
if new_setting not in self.settings:
|
|
290
256
|
self.settings.append(new_setting)
|
|
291
257
|
self.save()
|
|
292
|
-
|
|
258
|
+
|
|
293
259
|
def del_setting(self, name: str) -> None:
|
|
294
260
|
"""
|
|
295
261
|
Delete ``Setting``
|
|
296
|
-
|
|
262
|
+
|
|
297
263
|
Parameters
|
|
298
264
|
----------
|
|
299
265
|
name : str
|
|
300
266
|
Name of the setting
|
|
301
267
|
"""
|
|
302
268
|
name = name.strip().lower().replace(" ", _SPACE_REPLACE)
|
|
303
|
-
self.settings = [x for x in self.settings if
|
|
269
|
+
self.settings = [x for x in self.settings if x.name != name]
|
|
304
270
|
self.save()
|
|
305
271
|
|
|
306
272
|
def welcome(self) -> None:
|
|
307
273
|
"""Run first-run script (if any)"""
|
|
308
274
|
self.change_setting("first-run", False)
|
|
309
275
|
|
|
310
|
-
# Version
|
|
311
|
-
def update_version(self, version_data: VersionDictFormat) -> None:
|
|
312
|
-
"""
|
|
313
|
-
Update version
|
|
314
|
-
|
|
315
|
-
Parameters
|
|
316
|
-
----------
|
|
317
|
-
version_data : VersionDictFormat
|
|
318
|
-
Version data
|
|
319
|
-
"""
|
|
320
|
-
self.version = version_data
|
|
321
|
-
self.save()
|
|
322
|
-
|
|
323
276
|
|
|
324
277
|
# Init
|
|
325
278
|
###########################################################################
|
|
326
279
|
ABSFUYU_CONFIG = Config(CONFIG_PATH)
|
|
327
280
|
|
|
328
|
-
|
|
329
|
-
#
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
281
|
+
# TODO: Create a config file when not available [W.I.P]
|
|
282
|
+
# _settings = [
|
|
283
|
+
# Setting(
|
|
284
|
+
# "auto-install-extra", False, False, "Automatically install required packages"
|
|
285
|
+
# ),
|
|
286
|
+
# Setting("first-run", True, True, "Check if this package has ever been run"),
|
|
287
|
+
# Setting(
|
|
288
|
+
# "luckgod-mode",
|
|
289
|
+
# False,
|
|
290
|
+
# False,
|
|
291
|
+
# "A chance that the machine will be randomly shutdown",
|
|
292
|
+
# ),
|
|
293
|
+
# ]
|
absfuyu/config/config.json
CHANGED
absfuyu/core.py
CHANGED
|
@@ -3,19 +3,14 @@ Absfuyu: Core
|
|
|
3
3
|
-------------
|
|
4
4
|
Contain type hints and other stuffs
|
|
5
5
|
|
|
6
|
-
Version: 2.
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 2.2.0
|
|
7
|
+
Date updated: 14/04/2024 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
|
-
|
|
11
10
|
# Module Package
|
|
12
11
|
###########################################################################
|
|
13
12
|
__all__ = [
|
|
14
|
-
# module
|
|
15
|
-
"ModulePackage",
|
|
16
|
-
"ModuleList",
|
|
17
13
|
# color
|
|
18
|
-
"Color",
|
|
19
14
|
"CLITextColor",
|
|
20
15
|
# path
|
|
21
16
|
"CORE_PATH",
|
|
@@ -23,25 +18,13 @@ __all__ = [
|
|
|
23
18
|
"DATA_PATH",
|
|
24
19
|
]
|
|
25
20
|
|
|
26
|
-
|
|
27
|
-
ModuleList = [
|
|
28
|
-
"config",
|
|
29
|
-
"extensions",
|
|
30
|
-
"fun",
|
|
31
|
-
"game",
|
|
32
|
-
"general",
|
|
33
|
-
"pkg_data",
|
|
34
|
-
"sort",
|
|
35
|
-
"tools",
|
|
36
|
-
"util",
|
|
37
|
-
"version",
|
|
38
|
-
]
|
|
21
|
+
__package_feature__ = ["beautiful", "extra", "res", "full", "dev"]
|
|
39
22
|
|
|
40
23
|
|
|
41
|
-
# Library
|
|
42
|
-
###########################################################################
|
|
43
24
|
from pathlib import Path
|
|
25
|
+
|
|
44
26
|
# import sys
|
|
27
|
+
# from sys import version_info as _python_version
|
|
45
28
|
|
|
46
29
|
# if sys.version_info.minor >= 10:
|
|
47
30
|
# from importlib.resources import files
|
|
@@ -52,41 +35,6 @@ from pathlib import Path
|
|
|
52
35
|
# raise ImportError("Please install importlib-resources")
|
|
53
36
|
|
|
54
37
|
|
|
55
|
-
try:
|
|
56
|
-
import colorama as __colorama
|
|
57
|
-
except ImportError:
|
|
58
|
-
__colorama = None
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
# Color - colorama
|
|
62
|
-
###########################################################################
|
|
63
|
-
if __colorama is not None:
|
|
64
|
-
# __colorama.init(autoreset=True)
|
|
65
|
-
Color = {
|
|
66
|
-
"green": __colorama.Fore.LIGHTGREEN_EX,
|
|
67
|
-
"GREEN": __colorama.Fore.GREEN,
|
|
68
|
-
"blue": __colorama.Fore.LIGHTCYAN_EX,
|
|
69
|
-
"BLUE": __colorama.Fore.CYAN,
|
|
70
|
-
"red": __colorama.Fore.LIGHTRED_EX,
|
|
71
|
-
"RED": __colorama.Fore.RED,
|
|
72
|
-
"yellow": __colorama.Fore.LIGHTYELLOW_EX,
|
|
73
|
-
"YELLOW": __colorama.Fore.YELLOW,
|
|
74
|
-
"reset": __colorama.Fore.RESET,
|
|
75
|
-
}
|
|
76
|
-
else:
|
|
77
|
-
Color = {
|
|
78
|
-
"green": "",
|
|
79
|
-
"GREEN": "",
|
|
80
|
-
"blue": "",
|
|
81
|
-
"BLUE": "",
|
|
82
|
-
"red": "",
|
|
83
|
-
"RED": "",
|
|
84
|
-
"yellow": "",
|
|
85
|
-
"YELLOW": "",
|
|
86
|
-
"reset": "",
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
38
|
class CLITextColor:
|
|
91
39
|
"""Color code for text in terminal"""
|
|
92
40
|
|
|
@@ -102,16 +50,7 @@ class CLITextColor:
|
|
|
102
50
|
RESET = "\x1b[39m"
|
|
103
51
|
|
|
104
52
|
|
|
105
|
-
# Path
|
|
106
|
-
###########################################################################
|
|
107
|
-
# CORE_PATH = Path(os.path.abspath(os.path.dirname(__file__)))
|
|
108
53
|
CORE_PATH = Path(__file__).parent.absolute()
|
|
109
54
|
# CORE_PATH = files("absfuyu")
|
|
110
55
|
CONFIG_PATH = CORE_PATH.joinpath("config", "config.json")
|
|
111
56
|
DATA_PATH = CORE_PATH.joinpath("pkg_data")
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
# Run
|
|
115
|
-
###########################################################################
|
|
116
|
-
if __name__ == "__main__":
|
|
117
|
-
print(CORE_PATH)
|
absfuyu/everything.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# flake8: noqa
|
|
1
2
|
"""
|
|
2
3
|
Absfuyu: Everything
|
|
3
4
|
-------------------
|
|
@@ -11,23 +12,20 @@ Usage:
|
|
|
11
12
|
>>> from absfuyu import everything as ab
|
|
12
13
|
"""
|
|
13
14
|
|
|
14
|
-
|
|
15
15
|
# Library
|
|
16
16
|
###########################################################################
|
|
17
|
-
from absfuyu.core import *
|
|
18
17
|
from absfuyu.config import *
|
|
18
|
+
from absfuyu.core import *
|
|
19
|
+
from absfuyu.extensions import *
|
|
19
20
|
from absfuyu.fun import *
|
|
20
|
-
from absfuyu.
|
|
21
|
+
from absfuyu.game import *
|
|
22
|
+
from absfuyu.general import *
|
|
21
23
|
from absfuyu.logger import *
|
|
24
|
+
from absfuyu.pkg_data import *
|
|
22
25
|
from absfuyu.sort import *
|
|
23
|
-
from absfuyu.version import *
|
|
24
|
-
|
|
25
|
-
from absfuyu.general import *
|
|
26
|
-
from absfuyu.extensions import *
|
|
27
|
-
from absfuyu.game import *
|
|
28
26
|
from absfuyu.tools import *
|
|
29
27
|
from absfuyu.util import *
|
|
30
|
-
|
|
28
|
+
from absfuyu.version import *
|
|
31
29
|
|
|
32
30
|
# Is loaded
|
|
33
31
|
###########################################################################
|
absfuyu/extensions/beautiful.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# type: ignore
|
|
1
2
|
"""
|
|
2
3
|
Absfuyu: Beautiful
|
|
3
4
|
------------------
|
|
@@ -7,15 +8,15 @@ Version: 1.0.2
|
|
|
7
8
|
Date updated: 24/11/2023 (dd/mm/yyyy)
|
|
8
9
|
"""
|
|
9
10
|
|
|
10
|
-
|
|
11
11
|
# Module level
|
|
12
12
|
###########################################################################
|
|
13
13
|
__all__ = [
|
|
14
|
-
"beautiful_output",
|
|
14
|
+
"beautiful_output",
|
|
15
|
+
"print",
|
|
16
|
+
"demo",
|
|
15
17
|
]
|
|
16
18
|
|
|
17
19
|
|
|
18
|
-
|
|
19
20
|
# Library
|
|
20
21
|
###########################################################################
|
|
21
22
|
from functools import wraps as __wraps
|
|
@@ -33,24 +34,25 @@ try:
|
|
|
33
34
|
from rich.text import Text as __Text
|
|
34
35
|
except ImportError:
|
|
35
36
|
from absfuyu.config import ABSFUYU_CONFIG
|
|
37
|
+
|
|
36
38
|
if ABSFUYU_CONFIG._get_setting("auto-install-extra").value:
|
|
37
39
|
__cmd: str = "python -m pip install -U absfuyu[beautiful]".split()
|
|
38
40
|
from subprocess import run as __run
|
|
41
|
+
|
|
39
42
|
__run(__cmd)
|
|
40
43
|
else:
|
|
41
|
-
raise SystemExit("This feature is in absfuyu[beautiful] package")
|
|
44
|
+
raise SystemExit("This feature is in absfuyu[beautiful] package") # noqa: B904
|
|
42
45
|
else:
|
|
43
46
|
BEAUTIFUL_MODE = True
|
|
44
47
|
|
|
45
48
|
|
|
46
|
-
|
|
47
49
|
# Function
|
|
48
50
|
###########################################################################
|
|
49
51
|
def beautiful_output(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
layout_option: int = 2,
|
|
53
|
+
header_visible: __Optional[bool] = True,
|
|
54
|
+
footer_visible: __Optional[bool] = False,
|
|
55
|
+
):
|
|
54
56
|
"""
|
|
55
57
|
Beautify function output
|
|
56
58
|
|
|
@@ -62,21 +64,19 @@ def beautiful_output(
|
|
|
62
64
|
footer_visible : True | False | None
|
|
63
65
|
Show footer
|
|
64
66
|
"""
|
|
65
|
-
|
|
67
|
+
|
|
66
68
|
if not BEAUTIFUL_MODE:
|
|
67
69
|
raise SystemExit("This feature is in absfuyu[beautiful] package")
|
|
68
70
|
|
|
69
71
|
def decorator(func):
|
|
70
|
-
|
|
71
72
|
@__wraps(func)
|
|
72
73
|
def wrapper(*args, **kwargs):
|
|
73
|
-
|
|
74
74
|
# Measure performance
|
|
75
75
|
start_time = __perf()
|
|
76
76
|
f = func(*args, **kwargs)
|
|
77
77
|
finished_time = __perf()
|
|
78
78
|
elapsed = f"Time elapsed: {finished_time - start_time:,.6f} s"
|
|
79
|
-
|
|
79
|
+
|
|
80
80
|
# Make header
|
|
81
81
|
header_table = __Table.grid(expand=True)
|
|
82
82
|
header_table.add_row(
|
|
@@ -94,11 +94,11 @@ def beautiful_output(
|
|
|
94
94
|
style="white on blue",
|
|
95
95
|
),
|
|
96
96
|
)
|
|
97
|
-
|
|
97
|
+
|
|
98
98
|
# Make output table
|
|
99
99
|
out_table = __Table.grid(expand=True)
|
|
100
|
-
out_table.add_column(ratio=2)
|
|
101
|
-
out_table.add_column()
|
|
100
|
+
out_table.add_column(ratio=2) # result
|
|
101
|
+
out_table.add_column() # performance
|
|
102
102
|
r_txt = __Text(
|
|
103
103
|
str(f),
|
|
104
104
|
overflow="fold",
|
|
@@ -132,16 +132,21 @@ def beautiful_output(
|
|
|
132
132
|
True: header_table,
|
|
133
133
|
False: line,
|
|
134
134
|
None: __Text(),
|
|
135
|
-
}
|
|
135
|
+
} # header[header_visible]
|
|
136
136
|
footer = {
|
|
137
137
|
True: footer_table,
|
|
138
138
|
False: line,
|
|
139
139
|
None: __Text(),
|
|
140
|
-
}
|
|
140
|
+
} # footer[footer_visible]
|
|
141
141
|
layout = {
|
|
142
142
|
1: __Group(header[header_visible], out_table, footer[footer_visible]),
|
|
143
|
-
2: __Group(
|
|
144
|
-
|
|
143
|
+
2: __Group(
|
|
144
|
+
header[header_visible],
|
|
145
|
+
result_panel,
|
|
146
|
+
performance_panel,
|
|
147
|
+
footer[footer_visible],
|
|
148
|
+
),
|
|
149
|
+
3: __Group(result_panel),
|
|
145
150
|
}
|
|
146
151
|
if layout_option in layout:
|
|
147
152
|
return layout[layout_option]
|
|
@@ -150,7 +155,7 @@ def beautiful_output(
|
|
|
150
155
|
# return layout[3]
|
|
151
156
|
|
|
152
157
|
return wrapper
|
|
153
|
-
|
|
158
|
+
|
|
154
159
|
return decorator
|
|
155
160
|
|
|
156
161
|
|
|
@@ -162,7 +167,7 @@ if BEAUTIFUL_MODE:
|
|
|
162
167
|
# demo
|
|
163
168
|
@beautiful_output()
|
|
164
169
|
def __demo_decorator(x: any = None):
|
|
165
|
-
code="""\
|
|
170
|
+
code = """\
|
|
166
171
|
# demo
|
|
167
172
|
from absfuyu.extensions import beautiful as bu
|
|
168
173
|
@bu.beautiful_output()
|
|
@@ -174,8 +179,10 @@ bu.print(testcode())"""
|
|
|
174
179
|
x = code
|
|
175
180
|
return x
|
|
176
181
|
|
|
182
|
+
|
|
177
183
|
def demo(x: any = None):
|
|
178
184
|
print(__demo_decorator(x))
|
|
179
185
|
|
|
186
|
+
|
|
180
187
|
if __name__ == "__main__":
|
|
181
|
-
demo()
|
|
188
|
+
demo()
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
# type: ignore
|
|
2
|
+
# flake8: noqa
|
|
3
|
+
|
|
1
4
|
"""
|
|
2
5
|
Absfuyu: Development
|
|
3
|
-
|
|
4
|
-
Some stuffs that are not ready to use yet
|
|
6
|
+
--------------------
|
|
7
|
+
Some stuffs that are not ready to use yet.
|
|
8
|
+
Use at your own risk, everything is subject to change
|
|
5
9
|
|
|
6
10
|
Version: 2.0.0
|
|
7
11
|
Date updated: 23/11/2023 (dd/mm/yyyy)
|
|
8
12
|
"""
|
|
9
13
|
|
|
10
|
-
|
|
11
14
|
# Module level
|
|
12
15
|
###########################################################################
|
|
13
16
|
__all__ = [
|
|
@@ -19,10 +22,10 @@ __all__ = [
|
|
|
19
22
|
# Library
|
|
20
23
|
###########################################################################
|
|
21
24
|
import base64
|
|
25
|
+
import re
|
|
22
26
|
from collections import deque
|
|
23
27
|
from functools import lru_cache
|
|
24
|
-
import
|
|
25
|
-
from typing import Dict, TypedDict, Final, List, NamedTuple
|
|
28
|
+
from typing import Dict, Final, List, NamedTuple
|
|
26
29
|
|
|
27
30
|
|
|
28
31
|
# PASSWORD CHECKER
|
|
@@ -113,7 +116,7 @@ def load_toml_file(toml_file: str):
|
|
|
113
116
|
|
|
114
117
|
if _python_version.minor < 11:
|
|
115
118
|
try:
|
|
116
|
-
import tomli as tomllib
|
|
119
|
+
import tomli as tomllib # type: ignore
|
|
117
120
|
except ImportError:
|
|
118
121
|
raise ImportError("Please install tomli python package")
|
|
119
122
|
except:
|
|
@@ -128,6 +131,7 @@ def load_toml_file(toml_file: str):
|
|
|
128
131
|
|
|
129
132
|
def get_sitemap(url: str):
|
|
130
133
|
import re
|
|
134
|
+
|
|
131
135
|
import requests
|
|
132
136
|
|
|
133
137
|
class Url(NamedTuple):
|
|
@@ -161,6 +165,7 @@ def get_sitemap(url: str):
|
|
|
161
165
|
|
|
162
166
|
from absfuyu.general import ClassBase
|
|
163
167
|
|
|
168
|
+
|
|
164
169
|
class SimpleStrEncrypt(ClassBase):
|
|
165
170
|
"""
|
|
166
171
|
Simple Encryption
|
|
@@ -231,8 +236,6 @@ class SimpleStrEncrypt(ClassBase):
|
|
|
231
236
|
return data
|
|
232
237
|
|
|
233
238
|
|
|
234
|
-
|
|
235
|
-
|
|
236
239
|
# testing
|
|
237
240
|
CON_VAR: Final[List[str]] = ["a", "b"] # Declare as final
|
|
238
241
|
|