xloft 0.6.5__py3-none-any.whl → 0.6.7__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
@@ -9,12 +9,7 @@ Modules exported by this package:
9
9
 
10
10
  from __future__ import annotations
11
11
 
12
- __all__ = (
13
- "to_human_size",
14
- "is_number",
15
- "NamedTuple",
16
- )
12
+ __all__ = ("NamedTuple",)
13
+
17
14
 
18
- from xloft.converters.human_size import to_human_size
19
- from xloft.itis import is_number
20
15
  from xloft.namedtuple import NamedTuple
@@ -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
@@ -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
- result = f"{human_size} {order}"
66
- _cache_human_size[n_bytes] = result
67
- return result
39
+ return f"{human_size} {order}"
xloft/itis.py CHANGED
@@ -4,11 +4,6 @@ from __future__ import annotations
4
4
 
5
5
  __all__ = ("is_number",)
6
6
 
7
- import re
8
-
9
- # Caching
10
- _REGEX_IS_NUMBER = re.compile(r"^[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?$")
11
-
12
7
 
13
8
  def is_number(value: str) -> bool:
14
9
  """Check if a string is a number.
@@ -21,4 +16,8 @@ def is_number(value: str) -> bool:
21
16
  Returns:
22
17
  True, if the string is a number.
23
18
  """
24
- return _REGEX_IS_NUMBER.match(value) is not None
19
+ try:
20
+ float(value)
21
+ return True
22
+ except ValueError:
23
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xloft
3
- Version: 0.6.5
3
+ Version: 0.6.7
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
 
@@ -158,10 +160,12 @@ del nt.y # => raise: AttributeCannotBeDelete
158
160
  del nt._id # => raise: AttributeCannotBeDelete
159
161
  ```
160
162
 
161
- - **Converter**
163
+ - **Converters**
162
164
 
163
165
  ```python
164
- from xloft import to_human_size
166
+ """Convert the number of bytes into a human-readable format."""
167
+
168
+ from xloft.converters import to_human_size
165
169
 
166
170
 
167
171
  to_human_size(200) # => 200 bytes
@@ -172,23 +176,30 @@ to_human_size(1048575) # => 1023.999 KB
172
176
  - **ItIs**
173
177
 
174
178
  ```python
175
- from xloft import is_number
179
+ """Check if a string is a number."""
176
180
 
181
+ from xloft.itis import is_number
177
182
 
178
- is_number("-1230.0123") # => True
179
- is_number("+1230.0123") # => True
180
- is_number("1230.0123") # => True
181
- is_number("1230.0") # => True
182
- is_number("1230") # => True
183
- is_number("1.23e-5") # => True
184
- is_number("1.23E-5") # => True
185
- is_number(".5") # => True
186
183
 
187
184
  is_number("") # => False
188
185
  is_number(" ") # => False
189
186
  is_number("1230.") # => False
190
187
  is_number("0x5") # => False
191
188
  is_number("0o5") # => False
189
+
190
+ is_number("-5.0") # => True
191
+ is_number("+5.0") # => True
192
+ is_number("5.0") # => True
193
+ is_number(".5") # => True
194
+ is_number("5.") # => True
195
+ is_number("3.4E+38") # => True
196
+ is_number("3.4E-38") # => True
197
+ is_number("1.7E+308") # => True
198
+ is_number("1.7E-308") # => True
199
+ is_number("-1.7976931348623157e+308") # => True
200
+ is_number("1.7976931348623157e+308") # => True
201
+ is_number("72028601076372765770200707816364342373431783018070841859646251155447849538676") # => True
202
+ is_number("-72028601076372765770200707816364342373431783018070841859646251155447849538676") # => True
192
203
  ```
193
204
 
194
205
  ## Changelog
@@ -0,0 +1,11 @@
1
+ xloft/__init__.py,sha256=DoAO9PDwoOfrE0RNKysMfHE2i7XarwVMjTPtwtDhJ_w,359
2
+ xloft/errors.py,sha256=hZcmF0QVVdvE5oM1jsXymRk_pPGgDSnUDM9wx9zJAYQ,895
3
+ xloft/itis.py,sha256=CRtnOhrw1IY8pPxXy4dCv7wVXUhXmo0OgLLlSSVnmxI,430
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.7.dist-info/METADATA,sha256=bBIRqomAqnJAby9ze0NUZHifL4HcyRJOdsh_1yNI7Q8,7766
9
+ xloft-0.6.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
+ xloft-0.6.7.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
11
+ xloft-0.6.7.dist-info/RECORD,,
@@ -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