xloft 0.1.17__py3-none-any.whl → 0.1.18__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/__init__.py CHANGED
@@ -5,6 +5,10 @@ Modules exported by this package:
5
5
  - `NamedTuple`: Class imitates the behavior of the _named tuple_.
6
6
  """
7
7
 
8
- __all__ = ("NamedTuple",)
8
+ __all__ = (
9
+ "to_human_size",
10
+ "NamedTuple",
11
+ )
9
12
 
13
+ from xloft.humanism import to_human_size
10
14
  from xloft.namedtuple import NamedTuple
xloft/humanism.py ADDED
@@ -0,0 +1,30 @@
1
+ """Humanism.
2
+
3
+ The module contains the following functions:
4
+
5
+ - `to_human_size(size)` - Returns a humanized string: 200 bytes | 1 KB | 1.5 MB etc.
6
+ """
7
+
8
+ import math
9
+
10
+
11
+ def to_human_size(size: int) -> str:
12
+ """Convert number of bytes to readable format.
13
+
14
+ Examples:
15
+ >>> from xloft import to_human_size
16
+ >>> to_human_size(200)
17
+ 200 bytes
18
+ >>> to_human_size(1048576)
19
+ 1 MB
20
+
21
+ Args:
22
+ size: The number of bytes.
23
+
24
+ Returns:
25
+ Returns a humanized string: 200 bytes | 1 KB | 1.5 MB etc.
26
+ """
27
+ idx: int = math.floor(math.log(size) / math.log(1024))
28
+ human_size: int | float = size if size < 1024 else abs(round(size / pow(1024, idx), 2))
29
+ order = ["bytes", "KB", "MB", "GB", "TB"][idx]
30
+ return "{:g} {}".format(human_size, order)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xloft
3
- Version: 0.1.17
3
+ Version: 0.1.18
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
@@ -52,7 +52,6 @@ Description-Content-Type: text/markdown
52
52
  <a href="https://mypy-lang.org/" alt="Types: Mypy"><img src="https://img.shields.io/badge/types-Mypy-202235.svg?color=0c7ebf" alt="Types: Mypy"></a>
53
53
  <a href="https://docs.astral.sh/ruff/" alt="Code style: Ruff"><img src="https://img.shields.io/badge/code%20style-Ruff-FDD835.svg" alt="Code style: Ruff"></a>
54
54
  <a href="https://github.com/kebasyaty/xloft" alt="PyPI implementation"><img src="https://img.shields.io/pypi/implementation/xloft" alt="PyPI implementation"></a>
55
- <a href="https://github.com/kebasyaty/xloft" alt="GitHub repository"><img src="https://img.shields.io/badge/--ecebeb?logo=github&logoColor=000000" alt="GitHub repository"></a>
56
55
  <br>
57
56
  <a href="https://pypi.org/project/xloft"><img src="https://img.shields.io/pypi/format/xloft" alt="Format"></a>
58
57
  <a href="https://github.com/kebasyaty/xloft"><img src="https://img.shields.io/github/languages/top/kebasyaty/xloft" alt="Top"></a>
@@ -61,7 +60,7 @@ Description-Content-Type: text/markdown
61
60
  <a href="https://github.com/kebasyaty/xloft/releases/" alt="GitHub release"><img src="https://img.shields.io/github/release/kebasyaty/xloft" alt="GitHub release"></a>
62
61
  </p>
63
62
  <p align="center">
64
- Currently, the collection is represented by one element `NamedTuple`.
63
+ Currently, the collection is represented by two elements of `ТameЕuple` and `to_human_size`.
65
64
  </p>
66
65
  </p>
67
66
  </div>
@@ -84,6 +83,8 @@ uv add xloft
84
83
 
85
84
  ## Usage
86
85
 
86
+ - **NamedTuple**
87
+
87
88
  ```python
88
89
  from xloft import NamedTuple
89
90
 
@@ -152,6 +153,19 @@ del nt.y # => raise: AttributeCannotBeDelete
152
153
  del nt._id # => raise: AttributeCannotBeDelete
153
154
  ```
154
155
 
156
+ - **to_human_size**
157
+
158
+ ```python
159
+ from xloft import to_human_size
160
+
161
+
162
+ s = to_human_size(200)
163
+ print(s) # => 200 bytes
164
+
165
+ s = to_human_size(1048576)
166
+ print(s) # => 1 MB
167
+ ```
168
+
155
169
  ## Changelog
156
170
 
157
171
  [View the change history.](https://github.com/kebasyaty/xloft/blob/main/CHANGELOG.md "Changelog")
@@ -0,0 +1,9 @@
1
+ xloft/__init__.py,sha256=zvpDtBWkgaj3oTMsDSWw2SLl7LMy7zO2SyvEhiKwzmg,287
2
+ xloft/errors.py,sha256=GYXvi2l01VUDQSs6skiOfQsKLF6tFuUhJMqNkL7BJNI,857
3
+ xloft/humanism.py,sha256=KQ-bIQJrVUZ3Xc5mVRQ07bvjq1LJzROr8tTV3RJWC0o,822
4
+ xloft/namedtuple.py,sha256=OkAHqMaV4hN6Qj_oaOYQ9-y9x4Muv4mNrBn48T6RpiI,6818
5
+ xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ xloft-0.1.18.dist-info/METADATA,sha256=rewzGpwSxU4oT0xru5xSdQq0cxpgLyyApmSILBTPe-s,6696
7
+ xloft-0.1.18.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
+ xloft-0.1.18.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
9
+ xloft-0.1.18.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- xloft/__init__.py,sha256=YtzkovVqW8hLxBXxM0U7K_qqfU8XBJ1pzX6tAgTUNFw,215
2
- xloft/errors.py,sha256=GYXvi2l01VUDQSs6skiOfQsKLF6tFuUhJMqNkL7BJNI,857
3
- xloft/namedtuple.py,sha256=OkAHqMaV4hN6Qj_oaOYQ9-y9x4Muv4mNrBn48T6RpiI,6818
4
- xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- xloft-0.1.17.dist-info/METADATA,sha256=o1sR41EDgbhanFcbH42an3NfaGClZW2ZsQz9tu-CDQw,6669
6
- xloft-0.1.17.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- xloft-0.1.17.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
8
- xloft-0.1.17.dist-info/RECORD,,
File without changes