absfuyu 3.4.0__py3-none-any.whl → 4.1.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 +1 -1
- absfuyu/cli/do_group.py +51 -2
- absfuyu/config/__init__.py +13 -13
- absfuyu/core.py +18 -16
- absfuyu/extensions/extra/data_analysis.py +74 -28
- absfuyu/fun/__init__.py +24 -23
- absfuyu/fun/tarot.py +6 -7
- absfuyu/game/__init__.py +2 -2
- absfuyu/game/game_stat.py +1 -1
- absfuyu/game/sudoku.py +6 -5
- absfuyu/game/tictactoe.py +4 -4
- absfuyu/general/content.py +7 -7
- absfuyu/general/data_extension.py +44 -63
- absfuyu/general/generator.py +4 -2
- absfuyu/logger.py +2 -2
- absfuyu/pkg_data/__init__.py +13 -20
- absfuyu/tools/checksum.py +56 -0
- absfuyu/tools/converter.py +33 -10
- absfuyu/tools/obfuscator.py +1 -1
- absfuyu/util/__init__.py +13 -14
- absfuyu/util/api.py +7 -7
- absfuyu/util/json_method.py +9 -9
- absfuyu/util/lunar.py +7 -8
- absfuyu/util/path.py +23 -21
- absfuyu/util/performance.py +8 -8
- absfuyu/util/shorten_number.py +228 -0
- absfuyu/util/zipped.py +18 -6
- {absfuyu-3.4.0.dist-info → absfuyu-4.1.0.dist-info}/METADATA +6 -9
- absfuyu-4.1.0.dist-info/RECORD +61 -0
- {absfuyu-3.4.0.dist-info → absfuyu-4.1.0.dist-info}/WHEEL +1 -1
- {absfuyu-3.4.0.dist-info → absfuyu-4.1.0.dist-info}/licenses/LICENSE +21 -21
- absfuyu-3.4.0.dist-info/RECORD +0 -59
- {absfuyu-3.4.0.dist-info → absfuyu-4.1.0.dist-info}/entry_points.txt +0 -0
absfuyu/tools/converter.py
CHANGED
|
@@ -3,8 +3,8 @@ Absufyu: Converter
|
|
|
3
3
|
------------------
|
|
4
4
|
Convert stuff
|
|
5
5
|
|
|
6
|
-
Version: 1.
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 1.3.0
|
|
7
|
+
Date updated: 01/02/2025 (dd/mm/yyyy)
|
|
8
8
|
|
|
9
9
|
Feature:
|
|
10
10
|
--------
|
|
@@ -25,7 +25,7 @@ import math
|
|
|
25
25
|
import re
|
|
26
26
|
import string
|
|
27
27
|
from itertools import chain, combinations
|
|
28
|
-
from
|
|
28
|
+
from pathlib import Path
|
|
29
29
|
|
|
30
30
|
from absfuyu.core import CLITextColor
|
|
31
31
|
from absfuyu.logger import logger
|
|
@@ -49,6 +49,29 @@ class Base64EncodeDecode:
|
|
|
49
49
|
def decode(data: str) -> str:
|
|
50
50
|
return base64.b64decode(data).decode()
|
|
51
51
|
|
|
52
|
+
@staticmethod
|
|
53
|
+
def encode_image(img_path: Path | str, data_tag: bool = False) -> str:
|
|
54
|
+
"""Encode image file into base64 string
|
|
55
|
+
|
|
56
|
+
Parameters
|
|
57
|
+
----------
|
|
58
|
+
img_path : Path | str
|
|
59
|
+
Path to image
|
|
60
|
+
data_tag : bool, optional
|
|
61
|
+
Add data tag before base64 string, by default False
|
|
62
|
+
|
|
63
|
+
Returns
|
|
64
|
+
-------
|
|
65
|
+
str
|
|
66
|
+
Encoded image
|
|
67
|
+
"""
|
|
68
|
+
img = Path(img_path)
|
|
69
|
+
with open(img, "rb") as img_file:
|
|
70
|
+
b64_data = base64.b64encode(img_file.read()).decode("utf-8")
|
|
71
|
+
if data_tag:
|
|
72
|
+
return f"data:image/{img.suffix[1:]};charset=utf-8;base64,{b64_data}"
|
|
73
|
+
return b64_data
|
|
74
|
+
|
|
52
75
|
|
|
53
76
|
class ChemistryElement:
|
|
54
77
|
"""Chemistry Element"""
|
|
@@ -74,7 +97,7 @@ class ChemistryElement:
|
|
|
74
97
|
# return self.symbol
|
|
75
98
|
return f"{self.__class__.__name__}({self.symbol})"
|
|
76
99
|
|
|
77
|
-
def to_dict(self) ->
|
|
100
|
+
def to_dict(self) -> dict[str, str | int | float]:
|
|
78
101
|
"""
|
|
79
102
|
Output content to dict
|
|
80
103
|
|
|
@@ -88,7 +111,7 @@ class ChemistryElement:
|
|
|
88
111
|
}
|
|
89
112
|
|
|
90
113
|
@classmethod
|
|
91
|
-
def from_dict(cls, data:
|
|
114
|
+
def from_dict(cls, data: dict[str, str | int | float]) -> "ChemistryElement":
|
|
92
115
|
"""
|
|
93
116
|
Convert from ``dict`` data
|
|
94
117
|
|
|
@@ -114,11 +137,11 @@ class Text2Chemistry:
|
|
|
114
137
|
def __repr__(self) -> str:
|
|
115
138
|
return self.__str__()
|
|
116
139
|
|
|
117
|
-
def _load_chemistry_data(self) ->
|
|
140
|
+
def _load_chemistry_data(self) -> list[ChemistryElement]:
|
|
118
141
|
"""
|
|
119
142
|
Load chemistry pickle data
|
|
120
143
|
"""
|
|
121
|
-
data:
|
|
144
|
+
data: list[dict] = Pickler.load(self.data_location) # type: ignore
|
|
122
145
|
return [ChemistryElement.from_dict(x) for x in data]
|
|
123
146
|
|
|
124
147
|
@property
|
|
@@ -136,7 +159,7 @@ class Text2Chemistry:
|
|
|
136
159
|
# logger.debug(available)
|
|
137
160
|
return base.difference(available)
|
|
138
161
|
|
|
139
|
-
def convert(self, text: str) ->
|
|
162
|
+
def convert(self, text: str) -> list[list[ChemistryElement]]:
|
|
140
163
|
"""
|
|
141
164
|
Convert text to chemistry symbol
|
|
142
165
|
|
|
@@ -163,7 +186,7 @@ class Text2Chemistry:
|
|
|
163
186
|
data = self._load_chemistry_data()
|
|
164
187
|
|
|
165
188
|
# List possible elements
|
|
166
|
-
possible_elements:
|
|
189
|
+
possible_elements: list[ChemistryElement] = []
|
|
167
190
|
for i, letter in enumerate(text_lower):
|
|
168
191
|
for element in data:
|
|
169
192
|
if element.symbol.lower().startswith(
|
|
@@ -219,7 +242,7 @@ class Str2Pixel:
|
|
|
219
242
|
str_data: str,
|
|
220
243
|
*,
|
|
221
244
|
pixel_size: int = 2,
|
|
222
|
-
pixel_symbol_overwrite:
|
|
245
|
+
pixel_symbol_overwrite: str | None = None,
|
|
223
246
|
) -> None:
|
|
224
247
|
"""
|
|
225
248
|
str_data: Pixel string data (Format: <number_of_pixel><color_code>)
|
absfuyu/tools/obfuscator.py
CHANGED
|
@@ -217,7 +217,7 @@ class Obfuscator:
|
|
|
217
217
|
)
|
|
218
218
|
for x in bait_lst:
|
|
219
219
|
output.append(
|
|
220
|
-
f"{x}='{gen.generate_string(charset=Charset.DEFAULT,size=self.split_every_length,times=1,string_type_if_1=True)}'"
|
|
220
|
+
f"{x}='{gen.generate_string(charset=Charset.DEFAULT, size=self.split_every_length, times=1, string_type_if_1=True)}'"
|
|
221
221
|
)
|
|
222
222
|
|
|
223
223
|
random_eval_text = str(random.randint(1, 100))
|
absfuyu/util/__init__.py
CHANGED
|
@@ -3,15 +3,14 @@ Absufyu: Utilities
|
|
|
3
3
|
------------------
|
|
4
4
|
Some random utilities
|
|
5
5
|
|
|
6
|
-
Version: 1.5.
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 1.5.2
|
|
7
|
+
Date updated: 25/11/2024 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
# Library
|
|
11
11
|
###########################################################################
|
|
12
12
|
import pkgutil
|
|
13
13
|
from datetime import datetime
|
|
14
|
-
from typing import Optional, Union
|
|
15
14
|
|
|
16
15
|
from absfuyu.logger import logger
|
|
17
16
|
|
|
@@ -34,10 +33,10 @@ def get_installed_package():
|
|
|
34
33
|
|
|
35
34
|
|
|
36
35
|
def set_min(
|
|
37
|
-
current_value:
|
|
36
|
+
current_value: int | float,
|
|
38
37
|
*,
|
|
39
|
-
min_value:
|
|
40
|
-
) ->
|
|
38
|
+
min_value: int | float = 0,
|
|
39
|
+
) -> int | float:
|
|
41
40
|
"""
|
|
42
41
|
Return ``min_value`` when ``current_value`` < ``min_value``
|
|
43
42
|
|
|
@@ -67,10 +66,10 @@ def set_min(
|
|
|
67
66
|
|
|
68
67
|
|
|
69
68
|
def set_max(
|
|
70
|
-
current_value:
|
|
69
|
+
current_value: int | float,
|
|
71
70
|
*,
|
|
72
|
-
max_value:
|
|
73
|
-
) ->
|
|
71
|
+
max_value: int | float = 100,
|
|
72
|
+
) -> int | float:
|
|
74
73
|
"""
|
|
75
74
|
Return ``max_value`` when ``current_value`` > ``max_value``
|
|
76
75
|
|
|
@@ -100,11 +99,11 @@ def set_max(
|
|
|
100
99
|
|
|
101
100
|
|
|
102
101
|
def set_min_max(
|
|
103
|
-
current_value:
|
|
102
|
+
current_value: int | float,
|
|
104
103
|
*,
|
|
105
|
-
min_value:
|
|
106
|
-
max_value:
|
|
107
|
-
) ->
|
|
104
|
+
min_value: int | float = 0,
|
|
105
|
+
max_value: int | float = 100,
|
|
106
|
+
) -> int | float:
|
|
108
107
|
"""
|
|
109
108
|
Return ``min_value`` | ``max_value`` when ``current_value``
|
|
110
109
|
is outside ``[min_value, max_value]``
|
|
@@ -139,7 +138,7 @@ def set_min_max(
|
|
|
139
138
|
|
|
140
139
|
|
|
141
140
|
def stop_after_day(
|
|
142
|
-
year:
|
|
141
|
+
year: int | None = None, month: int | None = None, day: int | None = None
|
|
143
142
|
) -> None:
|
|
144
143
|
"""
|
|
145
144
|
Stop working after specified day.
|
absfuyu/util/api.py
CHANGED
|
@@ -3,8 +3,8 @@ Absufyu: API
|
|
|
3
3
|
------------
|
|
4
4
|
Fetch data stuff
|
|
5
5
|
|
|
6
|
-
Version: 1.2.
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 1.2.1
|
|
7
|
+
Date updated: 15/11/2024 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
# Module level
|
|
@@ -21,7 +21,7 @@ import json
|
|
|
21
21
|
import re
|
|
22
22
|
import subprocess
|
|
23
23
|
from pathlib import Path
|
|
24
|
-
from typing import
|
|
24
|
+
from typing import NamedTuple
|
|
25
25
|
|
|
26
26
|
import requests
|
|
27
27
|
from deprecated.sphinx import versionchanged
|
|
@@ -42,7 +42,7 @@ class PingResult(NamedTuple):
|
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
@versionchanged(version="3.4.0", reason="Change function's return")
|
|
45
|
-
def ping_windows(host:
|
|
45
|
+
def ping_windows(host: list[str], ping_count: int = 3) -> list[PingResult]:
|
|
46
46
|
"""
|
|
47
47
|
Ping web
|
|
48
48
|
|
|
@@ -66,7 +66,7 @@ def ping_windows(host: List[str], ping_count: int = 3) -> List[PingResult]:
|
|
|
66
66
|
>>> ping_windows(["1.1.1.1", "google.com"])
|
|
67
67
|
['1.1.1.1 : xxms', 'google.com : xxms']
|
|
68
68
|
"""
|
|
69
|
-
out:
|
|
69
|
+
out: list[PingResult] = []
|
|
70
70
|
|
|
71
71
|
for ip in host:
|
|
72
72
|
output = subprocess.run(
|
|
@@ -96,7 +96,7 @@ class APIRequest:
|
|
|
96
96
|
self,
|
|
97
97
|
api_url: str,
|
|
98
98
|
*, # Use "*" to force using keyword in function parameter | Example: APIRequest(url, encoding="utf-8")
|
|
99
|
-
encoding:
|
|
99
|
+
encoding: str | None = "utf-8",
|
|
100
100
|
) -> None:
|
|
101
101
|
"""
|
|
102
102
|
:param api_url: api link
|
|
@@ -111,7 +111,7 @@ class APIRequest:
|
|
|
111
111
|
def __repr__(self) -> str:
|
|
112
112
|
return self.__str__()
|
|
113
113
|
|
|
114
|
-
def fetch_data(self, *, update: bool = False, json_cache:
|
|
114
|
+
def fetch_data(self, *, update: bool = False, json_cache: str | Path):
|
|
115
115
|
"""
|
|
116
116
|
Fetch data from an API then cache it for later use
|
|
117
117
|
|
absfuyu/util/json_method.py
CHANGED
|
@@ -3,8 +3,8 @@ Absfuyu: Json Method
|
|
|
3
3
|
--------------------
|
|
4
4
|
``.json`` file handling
|
|
5
5
|
|
|
6
|
-
Version: 1.1.
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 1.1.4
|
|
7
|
+
Date updated: 15/11/2024 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
# Module level
|
|
@@ -16,7 +16,7 @@ __all__ = ["JsonFile"]
|
|
|
16
16
|
###########################################################################
|
|
17
17
|
import json
|
|
18
18
|
from pathlib import Path
|
|
19
|
-
from typing import Any
|
|
19
|
+
from typing import Any
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
# Function
|
|
@@ -38,10 +38,10 @@ class JsonFile:
|
|
|
38
38
|
|
|
39
39
|
def __init__(
|
|
40
40
|
self,
|
|
41
|
-
json_file_location:
|
|
41
|
+
json_file_location: str | Path,
|
|
42
42
|
*,
|
|
43
|
-
encoding:
|
|
44
|
-
indent:
|
|
43
|
+
encoding: str | None = "utf-8",
|
|
44
|
+
indent: int | str | None = 4,
|
|
45
45
|
sort_keys: bool = True,
|
|
46
46
|
) -> None:
|
|
47
47
|
"""
|
|
@@ -54,7 +54,7 @@ class JsonFile:
|
|
|
54
54
|
self.encoding = encoding
|
|
55
55
|
self.indent = indent
|
|
56
56
|
self.sort_keys = sort_keys
|
|
57
|
-
self.data:
|
|
57
|
+
self.data: dict[Any, Any] = {}
|
|
58
58
|
|
|
59
59
|
def __str__(self) -> str:
|
|
60
60
|
return f"{self.__class__.__name__}({self.json_file_location.name})"
|
|
@@ -62,7 +62,7 @@ class JsonFile:
|
|
|
62
62
|
def __repr__(self) -> str:
|
|
63
63
|
return self.__str__()
|
|
64
64
|
|
|
65
|
-
def load_json(self) ->
|
|
65
|
+
def load_json(self) -> dict[Any, Any]:
|
|
66
66
|
"""
|
|
67
67
|
Load ``.json`` file
|
|
68
68
|
|
|
@@ -79,7 +79,7 @@ class JsonFile:
|
|
|
79
79
|
with open(self.json_file_location, "w", encoding=self.encoding) as file:
|
|
80
80
|
file.writelines(json_data)
|
|
81
81
|
|
|
82
|
-
def update_data(self, data:
|
|
82
|
+
def update_data(self, data: dict[Any, Any]) -> None:
|
|
83
83
|
"""
|
|
84
84
|
Update ``.json`` data without save
|
|
85
85
|
|
absfuyu/util/lunar.py
CHANGED
|
@@ -4,8 +4,8 @@ Absfuyu: Lunar calendar
|
|
|
4
4
|
-----------------------
|
|
5
5
|
Convert to lunar calendar
|
|
6
6
|
|
|
7
|
-
Version: 1.0.
|
|
8
|
-
Date updated:
|
|
7
|
+
Version: 1.0.3
|
|
8
|
+
Date updated: 15/11/2024 (dd/mm/yyyy)
|
|
9
9
|
|
|
10
10
|
Source:
|
|
11
11
|
-------
|
|
@@ -22,7 +22,6 @@ __all__ = ["LunarCalendar"]
|
|
|
22
22
|
###########################################################################
|
|
23
23
|
import math
|
|
24
24
|
from datetime import date, datetime
|
|
25
|
-
from typing import Optional, Union
|
|
26
25
|
|
|
27
26
|
|
|
28
27
|
# Class
|
|
@@ -56,9 +55,9 @@ class LunarCalendar:
|
|
|
56
55
|
def _julian_day_from_date(
|
|
57
56
|
self,
|
|
58
57
|
*,
|
|
59
|
-
overwrite_year:
|
|
60
|
-
overwrite_month:
|
|
61
|
-
overwrite_day:
|
|
58
|
+
overwrite_year: int | None = None,
|
|
59
|
+
overwrite_month: int | None = None,
|
|
60
|
+
overwrite_day: int | None = None,
|
|
62
61
|
) -> int:
|
|
63
62
|
"""
|
|
64
63
|
Compute the (integral) Julian day number of `self.date`
|
|
@@ -211,7 +210,7 @@ class LunarCalendar:
|
|
|
211
210
|
"""
|
|
212
211
|
return int(self._new_moon(k) + 0.5 + self.time_zone / 24.0)
|
|
213
212
|
|
|
214
|
-
def _get_lunar_month_11(self, *, overwrite_year:
|
|
213
|
+
def _get_lunar_month_11(self, *, overwrite_year: int | None = None) -> int:
|
|
215
214
|
"""
|
|
216
215
|
Find the day that starts the luner month 11
|
|
217
216
|
of the given year for the given time zone.
|
|
@@ -373,7 +372,7 @@ class LunarCalendar:
|
|
|
373
372
|
return cls(year, month, day, lunar_leap=lunar_leap).to_lunar()
|
|
374
373
|
|
|
375
374
|
@classmethod
|
|
376
|
-
def from_datetime(cls, datetime_object:
|
|
375
|
+
def from_datetime(cls, datetime_object: date | datetime):
|
|
377
376
|
"""
|
|
378
377
|
Convert from ``datetime.datetime`` object
|
|
379
378
|
|
absfuyu/util/path.py
CHANGED
|
@@ -3,8 +3,8 @@ Absfuyu: Path
|
|
|
3
3
|
-------------
|
|
4
4
|
Path related
|
|
5
5
|
|
|
6
|
-
Version: 1.6.
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 1.6.7
|
|
7
|
+
Date updated: 06/01/2025 (dd/mm/yyyy)
|
|
8
8
|
|
|
9
9
|
Feature:
|
|
10
10
|
--------
|
|
@@ -32,7 +32,7 @@ import shutil
|
|
|
32
32
|
from datetime import datetime
|
|
33
33
|
from functools import partial
|
|
34
34
|
from pathlib import Path
|
|
35
|
-
from typing import Any,
|
|
35
|
+
from typing import Any, Literal, NamedTuple
|
|
36
36
|
|
|
37
37
|
from deprecated.sphinx import versionadded
|
|
38
38
|
|
|
@@ -69,7 +69,7 @@ class DirectoryInfo(NamedTuple):
|
|
|
69
69
|
class DirectoryBase:
|
|
70
70
|
def __init__(
|
|
71
71
|
self,
|
|
72
|
-
source_path:
|
|
72
|
+
source_path: str | Path,
|
|
73
73
|
create_if_not_exist: bool = False,
|
|
74
74
|
) -> None:
|
|
75
75
|
"""
|
|
@@ -114,21 +114,21 @@ class DirectoryBase:
|
|
|
114
114
|
# Everything
|
|
115
115
|
@property
|
|
116
116
|
@versionadded(version="3.3.0")
|
|
117
|
-
def everything(self) ->
|
|
117
|
+
def everything(self) -> list[Path]:
|
|
118
118
|
"""
|
|
119
119
|
Every folders and files in this Directory
|
|
120
120
|
"""
|
|
121
121
|
return list(x for x in self.source_path.glob("**/*"))
|
|
122
122
|
|
|
123
123
|
@versionadded(version="3.3.0")
|
|
124
|
-
def _every_folder(self) ->
|
|
124
|
+
def _every_folder(self) -> list[Path]:
|
|
125
125
|
"""
|
|
126
126
|
Every folders in this Directory
|
|
127
127
|
"""
|
|
128
128
|
return list(x for x in self.source_path.glob("**/*") if x.is_dir())
|
|
129
129
|
|
|
130
130
|
@versionadded(version="3.3.0")
|
|
131
|
-
def _every_file(self) ->
|
|
131
|
+
def _every_file(self) -> list[Path]:
|
|
132
132
|
"""
|
|
133
133
|
Every folders in this Directory
|
|
134
134
|
"""
|
|
@@ -224,7 +224,7 @@ class DirectoryBasicOperation(DirectoryBase):
|
|
|
224
224
|
logger.debug("Overwriting file...DONE")
|
|
225
225
|
|
|
226
226
|
# Delete folder
|
|
227
|
-
def _mtime_folder(self) ->
|
|
227
|
+
def _mtime_folder(self) -> list[FileOrFolderWithModificationTime]:
|
|
228
228
|
"""
|
|
229
229
|
Get modification time of file/folder (first level only)
|
|
230
230
|
"""
|
|
@@ -236,7 +236,7 @@ class DirectoryBasicOperation(DirectoryBase):
|
|
|
236
236
|
]
|
|
237
237
|
|
|
238
238
|
@staticmethod
|
|
239
|
-
def _delete_files(list_of_files:
|
|
239
|
+
def _delete_files(list_of_files: list[Path]) -> None:
|
|
240
240
|
"""
|
|
241
241
|
Delete files/folders
|
|
242
242
|
"""
|
|
@@ -316,7 +316,9 @@ class DirectoryBasicOperation(DirectoryBase):
|
|
|
316
316
|
logger.error(f"Removing {self.source_path}...FAILED\n{e}")
|
|
317
317
|
|
|
318
318
|
# Zip
|
|
319
|
-
def compress(
|
|
319
|
+
def compress(
|
|
320
|
+
self, *, format: Literal["zip", "tar", "gztar", "bztar", "xztar"] = "zip"
|
|
321
|
+
) -> Path | None:
|
|
320
322
|
"""
|
|
321
323
|
Compress the directory (Default: Create ``.zip`` file)
|
|
322
324
|
|
|
@@ -366,7 +368,7 @@ class Directory(DirectoryBasicOperation, DirectoryTree):
|
|
|
366
368
|
"""
|
|
367
369
|
|
|
368
370
|
# Directory structure
|
|
369
|
-
def _list_dir(self, *ignore: str) ->
|
|
371
|
+
def _list_dir(self, *ignore: str) -> list[Path]:
|
|
370
372
|
"""
|
|
371
373
|
List all directories and files
|
|
372
374
|
|
|
@@ -395,7 +397,7 @@ class Directory(DirectoryBasicOperation, DirectoryTree):
|
|
|
395
397
|
|
|
396
398
|
@staticmethod
|
|
397
399
|
@versionadded(version="3.3.0")
|
|
398
|
-
def _split_dir(list_of_path:
|
|
400
|
+
def _split_dir(list_of_path: list[Path]) -> list[list[str]]:
|
|
399
401
|
"""
|
|
400
402
|
Split pathname by ``os.sep``
|
|
401
403
|
|
|
@@ -421,11 +423,11 @@ class Directory(DirectoryBasicOperation, DirectoryTree):
|
|
|
421
423
|
|
|
422
424
|
def _separate_dir_and_files(
|
|
423
425
|
self,
|
|
424
|
-
list_of_path:
|
|
426
|
+
list_of_path: list[Path],
|
|
425
427
|
*,
|
|
426
|
-
tab_symbol:
|
|
427
|
-
sub_dir_symbol:
|
|
428
|
-
) ->
|
|
428
|
+
tab_symbol: str | None = None,
|
|
429
|
+
sub_dir_symbol: str | None = None,
|
|
430
|
+
) -> list[str]:
|
|
429
431
|
"""
|
|
430
432
|
Separate dir and file and transform into folder structure
|
|
431
433
|
|
|
@@ -453,7 +455,7 @@ class Directory(DirectoryBasicOperation, DirectoryTree):
|
|
|
453
455
|
if not sub_dir_symbol:
|
|
454
456
|
sub_dir_symbol = "|-- "
|
|
455
457
|
|
|
456
|
-
temp:
|
|
458
|
+
temp: list[list[str]] = self._split_dir(list_of_path)
|
|
457
459
|
|
|
458
460
|
return [ # Returns n-tab space with sub-dir-symbol for the last item in x
|
|
459
461
|
f"{tab_symbol * (len(x) - 1)}{sub_dir_symbol}{x[-1]}" for x in temp
|
|
@@ -485,8 +487,8 @@ class Directory(DirectoryBasicOperation, DirectoryTree):
|
|
|
485
487
|
)
|
|
486
488
|
...
|
|
487
489
|
"""
|
|
488
|
-
temp:
|
|
489
|
-
out:
|
|
490
|
+
temp: list[Path] = self._list_dir(*ignore)
|
|
491
|
+
out: list[str] = self._separate_dir_and_files(temp)
|
|
490
492
|
return "\n".join(out) # Join the list
|
|
491
493
|
|
|
492
494
|
def list_structure_pkg(self) -> str:
|
|
@@ -506,7 +508,7 @@ class Directory(DirectoryBasicOperation, DirectoryTree):
|
|
|
506
508
|
class SaveFileAs:
|
|
507
509
|
"""File as multiple file type"""
|
|
508
510
|
|
|
509
|
-
def __init__(self, data: Any, *, encoding:
|
|
511
|
+
def __init__(self, data: Any, *, encoding: str | None = "utf-8") -> None:
|
|
510
512
|
"""
|
|
511
513
|
:param encoding: Default: utf-8
|
|
512
514
|
"""
|
|
@@ -519,7 +521,7 @@ class SaveFileAs:
|
|
|
519
521
|
def __repr__(self) -> str:
|
|
520
522
|
return self.__str__()
|
|
521
523
|
|
|
522
|
-
def to_txt(self, path:
|
|
524
|
+
def to_txt(self, path: str | Path) -> None:
|
|
523
525
|
"""
|
|
524
526
|
Save as ``.txt`` file
|
|
525
527
|
|
absfuyu/util/performance.py
CHANGED
|
@@ -3,8 +3,8 @@ Absfuyu: Performance
|
|
|
3
3
|
--------------------
|
|
4
4
|
Performance Check
|
|
5
5
|
|
|
6
|
-
Version: 1.2.
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 1.2.4
|
|
7
|
+
Date updated: 15/11/2024 (dd/mm/yyyy)
|
|
8
8
|
|
|
9
9
|
Feature:
|
|
10
10
|
--------
|
|
@@ -33,7 +33,7 @@ import time
|
|
|
33
33
|
import tracemalloc
|
|
34
34
|
from functools import wraps
|
|
35
35
|
from inspect import getsource
|
|
36
|
-
from typing import Any, Callable
|
|
36
|
+
from typing import Any, Callable
|
|
37
37
|
|
|
38
38
|
from deprecated.sphinx import versionadded, versionchanged
|
|
39
39
|
|
|
@@ -271,7 +271,7 @@ class Checker:
|
|
|
271
271
|
return f"{self.__class__.__name__}({self.item_to_check})"
|
|
272
272
|
|
|
273
273
|
@property
|
|
274
|
-
def name(self) ->
|
|
274
|
+
def name(self) -> Any | None:
|
|
275
275
|
"""``__name__`` of variable (if any)"""
|
|
276
276
|
try:
|
|
277
277
|
return self.item_to_check.__name__
|
|
@@ -284,7 +284,7 @@ class Checker:
|
|
|
284
284
|
return self.item_to_check
|
|
285
285
|
|
|
286
286
|
@property
|
|
287
|
-
def docstring(self) ->
|
|
287
|
+
def docstring(self) -> str | None:
|
|
288
288
|
"""``__doc__`` of variable (if any)"""
|
|
289
289
|
return self.item_to_check.__doc__ # type: ignore
|
|
290
290
|
|
|
@@ -299,20 +299,20 @@ class Checker:
|
|
|
299
299
|
return id(self.item_to_check)
|
|
300
300
|
|
|
301
301
|
@property
|
|
302
|
-
def dir_(self) ->
|
|
302
|
+
def dir_(self) -> list[str]:
|
|
303
303
|
"""``dir()`` of variable"""
|
|
304
304
|
# return self.item_to_check.__dir__()
|
|
305
305
|
return ListNoDunder(self.item_to_check.__dir__())
|
|
306
306
|
|
|
307
307
|
@property
|
|
308
|
-
def source(self) ->
|
|
308
|
+
def source(self) -> str | None:
|
|
309
309
|
"""Source code of variable (if available)"""
|
|
310
310
|
try:
|
|
311
311
|
return getsource(self.item_to_check)
|
|
312
312
|
except Exception:
|
|
313
313
|
return None
|
|
314
314
|
|
|
315
|
-
def check(self, full: bool = False) ->
|
|
315
|
+
def check(self, full: bool = False) -> dict[str, Any]:
|
|
316
316
|
"""
|
|
317
317
|
Check the variable
|
|
318
318
|
|