xloft 0.4.5__py3-none-any.whl → 0.4.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/human.py
CHANGED
|
@@ -7,10 +7,26 @@ The module contains the following functions:
|
|
|
7
7
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
|
+
__all__ = (
|
|
11
|
+
"to_human_size",
|
|
12
|
+
"get_cach_human_size",
|
|
13
|
+
)
|
|
14
|
+
|
|
10
15
|
import math
|
|
11
16
|
|
|
17
|
+
# To caching the results from to_human_size method.
|
|
18
|
+
_cach_human_size: dict[int, str] = {}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def get_cach_human_size() -> dict[int, str]:
|
|
22
|
+
"""Get a copy of the variable _cach_human_size.
|
|
23
|
+
|
|
24
|
+
Hint: To tests.
|
|
25
|
+
"""
|
|
26
|
+
return _cach_human_size.copy()
|
|
27
|
+
|
|
12
28
|
|
|
13
|
-
def to_human_size(
|
|
29
|
+
def to_human_size(n_bytes: int) -> str:
|
|
14
30
|
"""Convert number of bytes to readable format.
|
|
15
31
|
|
|
16
32
|
Examples:
|
|
@@ -23,15 +39,20 @@ def to_human_size(size: int) -> str:
|
|
|
23
39
|
1023.999 KB
|
|
24
40
|
|
|
25
41
|
Args:
|
|
26
|
-
|
|
42
|
+
n_bytes: The number of bytes.
|
|
27
43
|
|
|
28
44
|
Returns:
|
|
29
45
|
Returns a humanized string: 200 bytes | 1 KB | 1.5 MB etc.
|
|
30
46
|
"""
|
|
31
|
-
|
|
47
|
+
result: str | None = _cach_human_size.get(n_bytes)
|
|
48
|
+
if result is not None:
|
|
49
|
+
return result
|
|
50
|
+
idx: int = math.floor(math.log(n_bytes) / math.log(1024))
|
|
32
51
|
ndigits: int = [0, 3, 6, 9, 12][idx]
|
|
33
|
-
human_size: int | float =
|
|
52
|
+
human_size: int | float = n_bytes if n_bytes < 1024 else abs(round(n_bytes / pow(1024, idx), ndigits))
|
|
34
53
|
order = ["bytes", "KB", "MB", "GB", "TB"][idx]
|
|
35
54
|
if math.modf(human_size)[0] == 0.0:
|
|
36
55
|
human_size = int(human_size)
|
|
37
|
-
|
|
56
|
+
result = f"{human_size} {order}"
|
|
57
|
+
_cach_human_size[n_bytes] = result
|
|
58
|
+
return result
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
xloft/__init__.py,sha256=UL4IR8EcFjgWoQFayl6FrK2u8QmZytGCwa_E1jDiCmE,475
|
|
2
2
|
xloft/errors.py,sha256=hZcmF0QVVdvE5oM1jsXymRk_pPGgDSnUDM9wx9zJAYQ,895
|
|
3
|
-
xloft/human.py,sha256=
|
|
3
|
+
xloft/human.py,sha256=2Jg69412ocJpsOxNyTgaTEwiKTEdHbEOuSQM0LNUEa0,1625
|
|
4
4
|
xloft/namedtuple.py,sha256=a_l3bZF-L2I7MGxuF2CXzAHgNai-Vyj6SY1ODwxs7TU,6856
|
|
5
5
|
xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
6
|
xloft/quantum.py,sha256=ZkFqqFROC9j5JbwJmej3yL9VJcqElPrrimFTz0Pe3Mk,4679
|
|
7
|
-
xloft-0.4.
|
|
8
|
-
xloft-0.4.
|
|
9
|
-
xloft-0.4.
|
|
10
|
-
xloft-0.4.
|
|
7
|
+
xloft-0.4.6.dist-info/METADATA,sha256=MmWF-_pRdZp8ytxmPVZE3JX9p4tLmf0K9G8tjXuNzS0,7241
|
|
8
|
+
xloft-0.4.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
9
|
+
xloft-0.4.6.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
10
|
+
xloft-0.4.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|