xloft 0.6.5__py3-none-any.whl → 0.6.6__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 xloft might be problematic. Click here for more details.
- xloft/converters/__init__.py +2 -12
- xloft/converters/human_size.py +2 -30
- {xloft-0.6.5.dist-info → xloft-0.6.6.dist-info}/METADATA +7 -1
- xloft-0.6.6.dist-info/RECORD +11 -0
- xloft-0.6.5.dist-info/RECORD +0 -11
- {xloft-0.6.5.dist-info → xloft-0.6.6.dist-info}/WHEEL +0 -0
- {xloft-0.6.5.dist-info → xloft-0.6.6.dist-info}/licenses/LICENSE +0 -0
xloft/converters/__init__.py
CHANGED
|
@@ -3,20 +3,10 @@
|
|
|
3
3
|
The module contains the following functions:
|
|
4
4
|
|
|
5
5
|
- `to_human_size(n_bytes)` - Returns a humanized string: 200 bytes | 1 KB | 1.5 MB etc.
|
|
6
|
-
- `get_cache_human_size` - Gets a copy of variable _cache_human_size.
|
|
7
|
-
- `clean_cache_human_size` - Resets of variable _cache_human_size.
|
|
8
6
|
"""
|
|
9
7
|
|
|
10
8
|
from __future__ import annotations
|
|
11
9
|
|
|
12
|
-
__all__ = (
|
|
13
|
-
"to_human_size",
|
|
14
|
-
"get_cache_human_size",
|
|
15
|
-
"clean_cache_human_size",
|
|
16
|
-
)
|
|
10
|
+
__all__ = ("to_human_size",)
|
|
17
11
|
|
|
18
|
-
from xloft.converters.human_size import
|
|
19
|
-
clean_cache_human_size,
|
|
20
|
-
get_cache_human_size,
|
|
21
|
-
to_human_size,
|
|
22
|
-
)
|
|
12
|
+
from xloft.converters.human_size import to_human_size
|
xloft/converters/human_size.py
CHANGED
|
@@ -3,37 +3,14 @@
|
|
|
3
3
|
The module contains the following functions:
|
|
4
4
|
|
|
5
5
|
- `to_human_size(n_bytes)` - Returns a humanized string: 200 bytes | 1 KB | 1.5 MB etc.
|
|
6
|
-
- `get_cache_human_size` - Gets a copy of variable _cache_human_size.
|
|
7
|
-
- `clean_cache_human_size` - Resets of variable _cache_human_size.
|
|
8
6
|
"""
|
|
9
7
|
|
|
10
8
|
from __future__ import annotations
|
|
11
9
|
|
|
12
|
-
__all__ = (
|
|
13
|
-
"to_human_size",
|
|
14
|
-
"get_cache_human_size",
|
|
15
|
-
"clean_cache_human_size",
|
|
16
|
-
)
|
|
10
|
+
__all__ = ("to_human_size",)
|
|
17
11
|
|
|
18
12
|
import math
|
|
19
13
|
|
|
20
|
-
# To caching the results from to_human_size method.
|
|
21
|
-
_cache_human_size: dict[int, str] = {}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def get_cache_human_size() -> dict[int, str]:
|
|
25
|
-
"""Gets a copy of variable _cach_human_size.
|
|
26
|
-
|
|
27
|
-
Hint: To tests.
|
|
28
|
-
"""
|
|
29
|
-
return _cache_human_size.copy()
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def clean_cache_human_size() -> None:
|
|
33
|
-
"""Resets of variable _cach_human_size."""
|
|
34
|
-
global _cache_human_size # noqa: PLW0603
|
|
35
|
-
_cache_human_size = {}
|
|
36
|
-
|
|
37
14
|
|
|
38
15
|
def to_human_size(n_bytes: int) -> str:
|
|
39
16
|
"""Converts the number of bytes into a human-readable format.
|
|
@@ -53,15 +30,10 @@ def to_human_size(n_bytes: int) -> str:
|
|
|
53
30
|
Returns:
|
|
54
31
|
Returns a humanized string: 200 bytes | 1 KB | 1.5 MB etc.
|
|
55
32
|
"""
|
|
56
|
-
result: str | None = _cache_human_size.get(n_bytes)
|
|
57
|
-
if result is not None:
|
|
58
|
-
return result
|
|
59
33
|
idx: int = math.floor(math.log(n_bytes) / math.log(1024))
|
|
60
34
|
ndigits: int = [0, 3, 6, 9, 12][idx]
|
|
61
35
|
human_size: int | float = n_bytes if n_bytes < 1024 else abs(round(n_bytes / pow(1024, idx), ndigits))
|
|
62
36
|
order = ["bytes", "KB", "MB", "GB", "TB"][idx]
|
|
63
37
|
if math.modf(human_size)[0] == 0.0:
|
|
64
38
|
human_size = int(human_size)
|
|
65
|
-
|
|
66
|
-
_cache_human_size[n_bytes] = result
|
|
67
|
-
return result
|
|
39
|
+
return f"{human_size} {order}"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xloft
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.6
|
|
4
4
|
Summary: (XLOFT) X-Library of tools
|
|
5
5
|
Project-URL: Homepage, https://github.com/kebasyaty/xloft
|
|
6
6
|
Project-URL: Repository, https://github.com/kebasyaty/xloft
|
|
@@ -91,6 +91,8 @@ uv add xloft
|
|
|
91
91
|
- **NamedTuple**
|
|
92
92
|
|
|
93
93
|
```python
|
|
94
|
+
"""This class imitates the behavior of the `named tuple`."""
|
|
95
|
+
|
|
94
96
|
from xloft import NamedTuple
|
|
95
97
|
|
|
96
98
|
|
|
@@ -161,6 +163,8 @@ del nt._id # => raise: AttributeCannotBeDelete
|
|
|
161
163
|
- **Converter**
|
|
162
164
|
|
|
163
165
|
```python
|
|
166
|
+
"""Convert the number of bytes into a human-readable format."""
|
|
167
|
+
|
|
164
168
|
from xloft import to_human_size
|
|
165
169
|
|
|
166
170
|
|
|
@@ -172,6 +176,8 @@ to_human_size(1048575) # => 1023.999 KB
|
|
|
172
176
|
- **ItIs**
|
|
173
177
|
|
|
174
178
|
```python
|
|
179
|
+
"""Check if a string is a number."""
|
|
180
|
+
|
|
175
181
|
from xloft import is_number
|
|
176
182
|
|
|
177
183
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
xloft/__init__.py,sha256=oLi6SfT894qR_qmWupAhtKUpfeeMlYek2mcdQB9nZNI,494
|
|
2
|
+
xloft/errors.py,sha256=hZcmF0QVVdvE5oM1jsXymRk_pPGgDSnUDM9wx9zJAYQ,895
|
|
3
|
+
xloft/itis.py,sha256=Uac1du1Z_rUf3e8uThLWcSYU0F27zThBDW6UMUEHz88,480
|
|
4
|
+
xloft/namedtuple.py,sha256=egEULlfATXM8gMhAMjQSHocwTudqqzXDGTYGZVSUGZs,5725
|
|
5
|
+
xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
xloft/converters/__init__.py,sha256=17_p8AQ-_UcKKioJolP_738LHCNOwohJIkCqeyaVO_M,316
|
|
7
|
+
xloft/converters/human_size.py,sha256=NcZRWF64LkQJ8-R00X7MCkNvXwlFDTcp5M3MylQzRTM,1149
|
|
8
|
+
xloft-0.6.6.dist-info/METADATA,sha256=A1jQ0KdswrWd_-q86S_Jkcm6PaTlIfe6zikhPBzzeY4,7432
|
|
9
|
+
xloft-0.6.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
10
|
+
xloft-0.6.6.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
11
|
+
xloft-0.6.6.dist-info/RECORD,,
|
xloft-0.6.5.dist-info/RECORD
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
xloft/__init__.py,sha256=oLi6SfT894qR_qmWupAhtKUpfeeMlYek2mcdQB9nZNI,494
|
|
2
|
-
xloft/errors.py,sha256=hZcmF0QVVdvE5oM1jsXymRk_pPGgDSnUDM9wx9zJAYQ,895
|
|
3
|
-
xloft/itis.py,sha256=Uac1du1Z_rUf3e8uThLWcSYU0F27zThBDW6UMUEHz88,480
|
|
4
|
-
xloft/namedtuple.py,sha256=egEULlfATXM8gMhAMjQSHocwTudqqzXDGTYGZVSUGZs,5725
|
|
5
|
-
xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
xloft/converters/__init__.py,sha256=ARuAwLLK55diQ8ggBeFC3inPRwn_aOyt6Ks_i8ObBl0,590
|
|
7
|
-
xloft/converters/human_size.py,sha256=vslG12Fln86zuCfXmDlmeijA2mCoLW3R2299PJ0wbxE,1957
|
|
8
|
-
xloft-0.6.5.dist-info/METADATA,sha256=DdbtaHZn8BCUlPgvM9T99IpP1PHu1NCAkeqG9ZYAGvk,7267
|
|
9
|
-
xloft-0.6.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
10
|
-
xloft-0.6.5.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
11
|
-
xloft-0.6.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|