xloft 0.1.16__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 +5 -1
- xloft/humanism.py +30 -0
- xloft/namedtuple.py +16 -11
- {xloft-0.1.16.dist-info → xloft-0.1.18.dist-info}/METADATA +37 -12
- xloft-0.1.18.dist-info/RECORD +9 -0
- xloft-0.1.16.dist-info/RECORD +0 -8
- {xloft-0.1.16.dist-info → xloft-0.1.18.dist-info}/WHEEL +0 -0
- {xloft-0.1.16.dist-info → xloft-0.1.18.dist-info}/licenses/LICENSE +0 -0
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__ = (
|
|
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)
|
xloft/namedtuple.py
CHANGED
|
@@ -4,17 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
Examples:
|
|
6
6
|
>>> from xloft import NamedTuple
|
|
7
|
-
>>> nt = NamedTuple(x=10, y="Hello")
|
|
7
|
+
>>> nt = NamedTuple(x=10, y="Hello", _id="507c7f79bcf86cd7994f6c0e")
|
|
8
8
|
>>> nt.x
|
|
9
9
|
10
|
|
10
|
+
>>> nt.y
|
|
11
|
+
Hello
|
|
12
|
+
>>> nt._id
|
|
13
|
+
507c7f79bcf86cd7994f6c0e
|
|
10
14
|
>>> nt.z
|
|
11
15
|
KeyError
|
|
12
16
|
>>> len(nt)
|
|
13
|
-
|
|
17
|
+
3
|
|
14
18
|
>>> nt.keys()
|
|
15
|
-
["x", "y"]
|
|
19
|
+
["x", "y", "_id"]
|
|
16
20
|
>>> nt.values()
|
|
17
|
-
[10, "Hello"]
|
|
21
|
+
[10, "Hello", "507c7f79bcf86cd7994f6c0e"]
|
|
18
22
|
>>> nt.has_key("x")
|
|
19
23
|
True
|
|
20
24
|
>>> nt.has_key("z")
|
|
@@ -27,20 +31,21 @@ Examples:
|
|
|
27
31
|
10
|
|
28
32
|
>>> nt.get("z")
|
|
29
33
|
None
|
|
30
|
-
>>> nt.update("z", [1, 2, 3])
|
|
31
|
-
KeyError
|
|
32
34
|
>>> d = nt.to_dict()
|
|
33
35
|
>>> d["x"]
|
|
34
36
|
10
|
|
35
|
-
>>> nt["z"] = [1, 2, 3]
|
|
36
|
-
TypeError
|
|
37
|
-
>>> nt.update("x", 20)
|
|
38
|
-
>>> nt.x
|
|
39
|
-
20
|
|
40
37
|
>>> for key, val in nt.items():
|
|
41
38
|
... print(f"Key: {key}, Value: {val}")
|
|
42
39
|
"Key: x, Value: 10"
|
|
43
40
|
"Key: y, Value: Hello"
|
|
41
|
+
"Key: _id, value: 507c7f79bcf86cd7994f6c0e"
|
|
42
|
+
>>> nt.update("x", 20)
|
|
43
|
+
>>> nt.x
|
|
44
|
+
20
|
|
45
|
+
>>> nt.update("z", [1, 2, 3])
|
|
46
|
+
KeyError
|
|
47
|
+
>>> nt["z"] = [1, 2, 3]
|
|
48
|
+
TypeError
|
|
44
49
|
>>> nt.x = 20
|
|
45
50
|
Error: AttributeDoesNotSetValue
|
|
46
51
|
>>> del nt.x
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xloft
|
|
3
|
-
Version: 0.1.
|
|
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
|
|
@@ -49,9 +49,9 @@ Description-Content-Type: text/markdown
|
|
|
49
49
|
<a href="https://github.com/kebasyaty/xloft/issues"><img src="https://img.shields.io/github/issues/kebasyaty/xloft.svg" alt="GitHub issues"></a>
|
|
50
50
|
<a href="https://pepy.tech/projects/xloft"><img src="https://static.pepy.tech/badge/xloft" alt="PyPI Downloads"></a>
|
|
51
51
|
<a href="https://github.com/kebasyaty/xloft/blob/main/LICENSE" alt="GitHub license"><img src="https://img.shields.io/github/license/kebasyaty/xloft" alt="GitHub license"></a>
|
|
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>
|
|
52
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>
|
|
53
54
|
<a href="https://github.com/kebasyaty/xloft" alt="PyPI implementation"><img src="https://img.shields.io/pypi/implementation/xloft" alt="PyPI implementation"></a>
|
|
54
|
-
<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>
|
|
55
55
|
<br>
|
|
56
56
|
<a href="https://pypi.org/project/xloft"><img src="https://img.shields.io/pypi/format/xloft" alt="Format"></a>
|
|
57
57
|
<a href="https://github.com/kebasyaty/xloft"><img src="https://img.shields.io/github/languages/top/kebasyaty/xloft" alt="Top"></a>
|
|
@@ -60,7 +60,7 @@ Description-Content-Type: text/markdown
|
|
|
60
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>
|
|
61
61
|
</p>
|
|
62
62
|
<p align="center">
|
|
63
|
-
Currently, the collection is represented by
|
|
63
|
+
Currently, the collection is represented by two elements of `ТameЕuple` and `to_human_size`.
|
|
64
64
|
</p>
|
|
65
65
|
</p>
|
|
66
66
|
</div>
|
|
@@ -83,38 +83,44 @@ uv add xloft
|
|
|
83
83
|
|
|
84
84
|
## Usage
|
|
85
85
|
|
|
86
|
+
- **NamedTuple**
|
|
87
|
+
|
|
86
88
|
```python
|
|
87
89
|
from xloft import NamedTuple
|
|
88
90
|
|
|
89
91
|
|
|
90
|
-
nt = NamedTuple(x=10, y="Hello")
|
|
92
|
+
nt = NamedTuple(x=10, y="Hello", _id="507c7f79bcf86cd7994f6c0e")
|
|
91
93
|
# or
|
|
92
|
-
d = {"x": 10, "y": "Hello"}
|
|
94
|
+
d = {"x": 10, "y": "Hello", "_id": "507c7f79bcf86cd7994f6c0e"}
|
|
93
95
|
nt = NamedTuple(**d)
|
|
94
96
|
|
|
95
97
|
nt.x # => 10
|
|
96
|
-
nt.y # =>
|
|
98
|
+
nt.y # => Hello
|
|
99
|
+
nt._id # => 507c7f79bcf86cd7994f6c0e
|
|
97
100
|
nt.z # => raise: KeyError
|
|
98
101
|
|
|
99
|
-
len(nt) # =>
|
|
100
|
-
nt.keys() # => ["x", "y"]
|
|
101
|
-
nt.values() # => [10, "Hello"]
|
|
102
|
+
len(nt) # => 3
|
|
103
|
+
nt.keys() # => ["x", "y", "_id"]
|
|
104
|
+
nt.values() # => [10, "Hello", "507c7f79bcf86cd7994f6c0e"]
|
|
102
105
|
|
|
103
106
|
nt.has_key("x") # => True
|
|
104
107
|
nt.has_key("y") # => True
|
|
108
|
+
nt.hsa_key("_id") # => True
|
|
105
109
|
nt.has_key("z") # => False
|
|
106
110
|
|
|
107
111
|
nt.has_value(10) # => True
|
|
108
112
|
nt.has_value("Hello") # => True
|
|
113
|
+
nt.has_value("507c7f79bcf86cd7994f6c0e") # => True
|
|
109
114
|
nt.has_value([1, 2, 3]) # => False
|
|
110
115
|
|
|
111
116
|
nt.get("x") # => 10
|
|
112
|
-
nt.get("y") # =>
|
|
117
|
+
nt.get("y") # => Hello
|
|
118
|
+
nt.get("_id") # => 507c7f79bcf86cd7994f6c0e
|
|
113
119
|
nt.get("z") # => None
|
|
114
120
|
|
|
115
121
|
d = nt.to_dict()
|
|
116
122
|
d["x"] # => 10
|
|
117
|
-
d.get("y") # =>
|
|
123
|
+
d.get("y") # => Hello
|
|
118
124
|
d.get("z") # => None
|
|
119
125
|
|
|
120
126
|
for key, val in nt.items():
|
|
@@ -122,23 +128,42 @@ for key, val in nt.items():
|
|
|
122
128
|
|
|
123
129
|
nt.update("x", 20)
|
|
124
130
|
nt.update("y", "Hi")
|
|
131
|
+
nt.update("_id", "new_id")
|
|
125
132
|
nt.x # => 20
|
|
126
|
-
nt.y # =>
|
|
133
|
+
nt.y # => Hi
|
|
134
|
+
nt._id # => new_id
|
|
127
135
|
nt.update("z", [1, 2, 3]) # => raise: KeyError
|
|
128
136
|
|
|
129
137
|
nt["x"] # => raise: KeyError
|
|
130
138
|
nt["y"] # => raise: KeyError
|
|
139
|
+
nt["_id"] # => raise: KeyError
|
|
131
140
|
nt["z"] # => raise: KeyError
|
|
132
141
|
nt["x"] = 20 # => TypeError
|
|
133
142
|
nt["y"] = "Hi" # => TypeError
|
|
143
|
+
nt["_id"] = "new_id" # => TypeError
|
|
134
144
|
nt["z"] = [1, 2, 3] # => TypeError
|
|
135
145
|
|
|
136
146
|
nt.x = 20 # => raise: AttributeDoesNotSetValue
|
|
137
147
|
nt.y = "Hi" # => raise: AttributeDoesNotSetValue
|
|
148
|
+
nt._id = "new_id" # => raise: AttributeDoesNotSetValue
|
|
138
149
|
nt.z = [1, 2, 3] # => raise: AttributeDoesNotSetValue
|
|
139
150
|
|
|
140
151
|
del nt.x # => raise: AttributeCannotBeDelete
|
|
141
152
|
del nt.y # => raise: AttributeCannotBeDelete
|
|
153
|
+
del nt._id # => raise: AttributeCannotBeDelete
|
|
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
|
|
142
167
|
```
|
|
143
168
|
|
|
144
169
|
## 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,,
|
xloft-0.1.16.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
xloft/__init__.py,sha256=YtzkovVqW8hLxBXxM0U7K_qqfU8XBJ1pzX6tAgTUNFw,215
|
|
2
|
-
xloft/errors.py,sha256=GYXvi2l01VUDQSs6skiOfQsKLF6tFuUhJMqNkL7BJNI,857
|
|
3
|
-
xloft/namedtuple.py,sha256=3ua0zTh9aAk7pucr6Mxrn6l-vRs_Jj0LdYwhij8PFsg,6631
|
|
4
|
-
xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
xloft-0.1.16.dist-info/METADATA,sha256=9kqznL4M1xNoZB4POK4vkFiVeJp39L61OnLPY-E_OVk,6037
|
|
6
|
-
xloft-0.1.16.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
-
xloft-0.1.16.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
8
|
-
xloft-0.1.16.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|