xloft 0.1.0__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 -0
- xloft/errors.py +24 -0
- xloft/namedtuple.py +54 -0
- xloft/py.typed +0 -0
- xloft-0.1.0.dist-info/METADATA +131 -0
- xloft-0.1.0.dist-info/RECORD +8 -0
- xloft-0.1.0.dist-info/WHEEL +4 -0
- xloft-0.1.0.dist-info/licenses/LICENSE +21 -0
xloft/__init__.py
ADDED
xloft/errors.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""XLOT Exceptions."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class XLOTException(Exception):
|
|
5
|
+
"""Root Custom Exception."""
|
|
6
|
+
|
|
7
|
+
def __init__(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def]# noqa: D107
|
|
8
|
+
super().__init__(*args, **kwargs)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class AttributeDoesNotSetValue(XLOTException):
|
|
12
|
+
"""Exception is raised if the attribute does not setting value."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, attribute_name: str) -> None: # noqa: D107
|
|
15
|
+
self.message = f"The attribute `{attribute_name}` does not setting value!"
|
|
16
|
+
super().__init__(self.message)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class AttributeCannotBeDelete(XLOTException):
|
|
20
|
+
"""Exception is raised if the attribute cannot be delete."""
|
|
21
|
+
|
|
22
|
+
def __init__(self, attribute_name: str) -> None: # noqa: D107
|
|
23
|
+
self.message = f"The attribute `{attribute_name}` cannot be delete!"
|
|
24
|
+
super().__init__(self.message)
|
xloft/namedtuple.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Named Tuple."""
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from xloft.errors import (
|
|
6
|
+
AttributeCannotBeDelete,
|
|
7
|
+
AttributeDoesNotSetValue,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class NamedTuple:
|
|
12
|
+
"""Named Tuple."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, **kwargs: dict[str, Any]) -> None: # noqa: D107
|
|
15
|
+
for name, value in kwargs.items():
|
|
16
|
+
self.__dict__[name] = value
|
|
17
|
+
|
|
18
|
+
def __getattr__(self, name: str) -> Any:
|
|
19
|
+
"""Getter."""
|
|
20
|
+
return self.__dict__[name]
|
|
21
|
+
|
|
22
|
+
def __setattr__(self, name: str, value: Any) -> None:
|
|
23
|
+
"""Setter."""
|
|
24
|
+
raise AttributeDoesNotSetValue(name)
|
|
25
|
+
|
|
26
|
+
def __delattr__(self, name: str) -> None:
|
|
27
|
+
"""Deleter."""
|
|
28
|
+
raise AttributeCannotBeDelete(name)
|
|
29
|
+
|
|
30
|
+
def __getitem__(self, key: str) -> Any:
|
|
31
|
+
"""Access by name of key."""
|
|
32
|
+
return self.__dict__[key]
|
|
33
|
+
|
|
34
|
+
def get(self, key: str, default: Any | None = None) -> Any | None:
|
|
35
|
+
"""Return the value for key if key is in the dictionary, else default."""
|
|
36
|
+
value = self.__dict__.get(key)
|
|
37
|
+
if value is not None:
|
|
38
|
+
return value
|
|
39
|
+
return default
|
|
40
|
+
|
|
41
|
+
def update(self, key: str, value: Any) -> Any:
|
|
42
|
+
"""Update a value of key.
|
|
43
|
+
|
|
44
|
+
Attention: This is an uncharacteristic action for the type `tuple`.
|
|
45
|
+
"""
|
|
46
|
+
self.__dict__[key] = value
|
|
47
|
+
|
|
48
|
+
def to_dict(self) -> dict[str, Any]:
|
|
49
|
+
"""Convert to the dictionary."""
|
|
50
|
+
return {key: value for key, value in self.__dict__.items() if not callable(value)}
|
|
51
|
+
|
|
52
|
+
def items(self) -> list[tuple[str, Any]]:
|
|
53
|
+
"""Return a set-like object providing a view on the NamedTuple's items."""
|
|
54
|
+
return [(key, value) for key, value in self.__dict__.items() if not callable(value)]
|
xloft/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xloft
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: (XLOFT) X-Library of tools
|
|
5
|
+
Project-URL: Homepage, https://github.com/kebasyaty/xloft
|
|
6
|
+
Project-URL: Repository, https://github.com/kebasyaty/xloft
|
|
7
|
+
Project-URL: Source, https://github.com/kebasyaty/xloft
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/kebasyaty/xloft/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/kebasyaty/xloft/blob/v0/CHANGELOG.md
|
|
10
|
+
Author-email: kebasyaty <kebasyaty@gmail.com>
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: collection,namedtuple,tools,xloft
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
18
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
19
|
+
Classifier: Operating System :: POSIX
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
25
|
+
Classifier: Topic :: Utilities
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: <4.0,>=3.12
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
<div align="center">
|
|
31
|
+
<p align="center">
|
|
32
|
+
<a href="https://github.com/kebasyaty/xloft">
|
|
33
|
+
<img
|
|
34
|
+
height="90"
|
|
35
|
+
alt="Logo"
|
|
36
|
+
src="https://raw.githubusercontent.com/kebasyaty/xloft/main/assets/logo.svg">
|
|
37
|
+
</a>
|
|
38
|
+
</p>
|
|
39
|
+
<p>
|
|
40
|
+
<h1>XLOFT</h1>
|
|
41
|
+
<h3>(XLOFT) X-Library of tools.</h3>
|
|
42
|
+
<p align="center">
|
|
43
|
+
<a href="https://github.com/kebasyaty/xloft/actions/workflows/test.yml" alt="Build Status"><img src="https://github.com/kebasyaty/xloft/actions/workflows/specs.yml/badge.svg" alt="Build Status"></a>
|
|
44
|
+
<a href="https://kebasyaty.github.io/xloft/" alt="Docs"><img src="https://img.shields.io/badge/docs-available-brightgreen.svg" alt="Docs"></a>
|
|
45
|
+
<a href="https://pypi.python.org/pypi/xloft/" alt="PyPI pyversions"><img src="https://img.shields.io/pypi/pyversions/xloft.svg" alt="PyPI pyversions"></a>
|
|
46
|
+
<a href="https://pypi.python.org/pypi/xloft/" alt="PyPI status"><img src="https://img.shields.io/pypi/status/xloft.svg" alt="PyPI status"></a>
|
|
47
|
+
<a href="https://pypi.python.org/pypi/xloft/" alt="PyPI version fury.io"><img src="https://badge.fury.io/py/xloft.svg" alt="PyPI version fury.io"></a>
|
|
48
|
+
<br>
|
|
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
|
+
<a href="https://pepy.tech/projects/xloft"><img src="https://static.pepy.tech/badge/xloft" alt="PyPI Downloads"></a>
|
|
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://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
|
+
<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
|
+
<br>
|
|
56
|
+
<a href="https://pypi.org/project/xloft"><img src="https://img.shields.io/pypi/format/xloft" alt="Format"></a>
|
|
57
|
+
<a href="https://github.com/kebasyaty/xloft"><img src="https://img.shields.io/github/languages/top/kebasyaty/xloft" alt="Top"></a>
|
|
58
|
+
<a href="https://github.com/kebasyaty/xloft"><img src="https://img.shields.io/github/repo-size/kebasyaty/xloft" alt="Size"></a>
|
|
59
|
+
<a href="https://github.com/kebasyaty/xloft"><img src="https://img.shields.io/github/last-commit/kebasyaty/xloft/main" alt="Last commit"></a>
|
|
60
|
+
</p>
|
|
61
|
+
<p align="center">
|
|
62
|
+
Currently, the collection is represented by one element `NamedTuple`.
|
|
63
|
+
</p>
|
|
64
|
+
</p>
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
##
|
|
68
|
+
|
|
69
|
+
## Requirements
|
|
70
|
+
|
|
71
|
+
[View the list of requirements.](https://github.com/kebasyaty/xloft/blob/main/REQUIREMENTS.md "View the list of requirements.")
|
|
72
|
+
|
|
73
|
+
## Installation
|
|
74
|
+
|
|
75
|
+
```shell
|
|
76
|
+
uv add xloft
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Usage
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from xloft import NamedTuple
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
nt = NamedTuple(x=10, y="Hello")
|
|
86
|
+
# or
|
|
87
|
+
d = {"x": 10, "y": "Hello"}
|
|
88
|
+
nt = NamedTuple(**d)
|
|
89
|
+
|
|
90
|
+
nt.x # => 10
|
|
91
|
+
nt.y # => "Hello"
|
|
92
|
+
nt.z # => raise: KeyError
|
|
93
|
+
|
|
94
|
+
nt["x"] # => 10
|
|
95
|
+
nt["y"] # => "Hello"
|
|
96
|
+
nt["z"] # => raise: KeyError
|
|
97
|
+
|
|
98
|
+
nt.get("x") # => 10
|
|
99
|
+
nt.get("y") # => "Hello"
|
|
100
|
+
nt.get("z") # => None
|
|
101
|
+
nt.get("z", [1, 2, 3] ) # => [1, 2, 3]
|
|
102
|
+
|
|
103
|
+
nt.x = 20 # => raise: AttributeDoesNotSetValue
|
|
104
|
+
nt.y = "Hi" # => raise: AttributeDoesNotSetValue
|
|
105
|
+
nt.z = [1, 2, 3] # => raise: AttributeDoesNotSetValue
|
|
106
|
+
|
|
107
|
+
nt.update("x", 20)
|
|
108
|
+
nt.update("y", "Hi")
|
|
109
|
+
nt["x"] # => 20
|
|
110
|
+
nt["y"] # => "Hi"
|
|
111
|
+
|
|
112
|
+
d = nt.to_dict()
|
|
113
|
+
d["x"] # => 10
|
|
114
|
+
d["y"] # => "Hello"
|
|
115
|
+
|
|
116
|
+
for key, val in nt.items():
|
|
117
|
+
print(f"Key: {key}, Value: {val}")
|
|
118
|
+
|
|
119
|
+
del nt.x # => raise: AttributeCannotBeDelete
|
|
120
|
+
del nt.y # => raise: AttributeCannotBeDelete
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### [See more examples here.](https://github.com/kebasyaty/xloft/tree/main/examples "See more examples here.")
|
|
124
|
+
|
|
125
|
+
## Changelog
|
|
126
|
+
|
|
127
|
+
[View the change history.](https://github.com/kebasyaty/xloft/blob/main/CHANGELOG.md "Changelog")
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
**This project is licensed under the** [MIT](https://github.com/kebasyaty/xloft/blob/main/LICENSE "MIT")**.**
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
xloft/__init__.py,sha256=yV847dKh9ROtw1fX5NHvPaHN-9cHYOfu9URQ--OVKXw,107
|
|
2
|
+
xloft/errors.py,sha256=GYXvi2l01VUDQSs6skiOfQsKLF6tFuUhJMqNkL7BJNI,857
|
|
3
|
+
xloft/namedtuple.py,sha256=ZOeVgj3gCN0a9XPrOwcd2UVfUUXTj88Uw6Rlx8sh2TQ,1723
|
|
4
|
+
xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
xloft-0.1.0.dist-info/METADATA,sha256=t1lrvtUZeVQcKEDr5ghWDbHbBntWb9ZQWXsdSICJX9o,5414
|
|
6
|
+
xloft-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
+
xloft-0.1.0.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
8
|
+
xloft-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Gennady Kostyunin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|