python-bunch 0.1.5__py3-none-any.whl → 0.1.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.
- bunch/bunch.py +70 -70
- bunch/immutable_bunch.py +75 -75
- {python_bunch-0.1.5.dist-info → python_bunch-0.1.6.dist-info}/METADATA +53 -52
- python_bunch-0.1.6.dist-info/RECORD +8 -0
- {python_bunch-0.1.5.dist-info → python_bunch-0.1.6.dist-info}/WHEEL +1 -1
- {python_bunch-0.1.5.dist-info → python_bunch-0.1.6.dist-info}/licenses/LICENSE +18 -18
- python_bunch-0.1.5.dist-info/RECORD +0 -8
- {python_bunch-0.1.5.dist-info → python_bunch-0.1.6.dist-info}/top_level.txt +0 -0
bunch/bunch.py
CHANGED
@@ -1,70 +1,70 @@
|
|
1
|
-
import json
|
2
|
-
from typing import Any
|
3
|
-
|
4
|
-
|
5
|
-
class Bunch:
|
6
|
-
def __init__(self, *args, **kwargs):
|
7
|
-
for arg in args:
|
8
|
-
if not isinstance(arg, dict):
|
9
|
-
kwargs[arg] = None
|
10
|
-
self.__dict__.update(kwargs)
|
11
|
-
|
12
|
-
def __getitem__(self, key: Any) -> Any or None:
|
13
|
-
return self.__dict__.get(key, None)
|
14
|
-
|
15
|
-
def __setitem__(self, key: Any, value: Any) -> None:
|
16
|
-
self.__dict__[key] = value
|
17
|
-
|
18
|
-
def __delitem__(self, key: Any) -> None:
|
19
|
-
del self.__dict__[key]
|
20
|
-
|
21
|
-
def __contains__(self, key: Any) -> bool:
|
22
|
-
return key in self.__dict__
|
23
|
-
|
24
|
-
def __str__(self) -> str:
|
25
|
-
return json.dumps(self.__dict__, sort_keys=False)
|
26
|
-
|
27
|
-
def __repr__(self) -> str:
|
28
|
-
return self.__str__()
|
29
|
-
|
30
|
-
def __getattr__(self, key: Any) -> Any or None:
|
31
|
-
if key in self.__dict__:
|
32
|
-
return self.__dict__[key]
|
33
|
-
return None
|
34
|
-
|
35
|
-
def __setattr__(self, name: str, value: Any) -> None:
|
36
|
-
self.__dict__[name] = value
|
37
|
-
|
38
|
-
def __delattr__(self, name) -> None:
|
39
|
-
del self.__dict__[name]
|
40
|
-
|
41
|
-
def contains_value(self, value: Any) -> bool:
|
42
|
-
return value in self.__dict__.values()
|
43
|
-
|
44
|
-
def clear(self) -> None:
|
45
|
-
self.__dict__.clear()
|
46
|
-
|
47
|
-
def pop(self, key: Any, default: Any = None) -> Any or None:
|
48
|
-
return self.__dict__.pop(key, default)
|
49
|
-
|
50
|
-
def popitem(self) -> Any or None:
|
51
|
-
return self.__dict__.popitem()
|
52
|
-
|
53
|
-
def update(self, other: dict) -> None:
|
54
|
-
self.__dict__.update(other)
|
55
|
-
|
56
|
-
def setdefault(self, key: Any, default: Any = None) -> Any or None:
|
57
|
-
return self.__dict__.setdefault(key, default)
|
58
|
-
|
59
|
-
def keys(self):
|
60
|
-
return self.__dict__.keys()
|
61
|
-
|
62
|
-
def values(self):
|
63
|
-
return self.__dict__.values()
|
64
|
-
|
65
|
-
def items(self):
|
66
|
-
return self.__dict__.items()
|
67
|
-
|
68
|
-
@staticmethod
|
69
|
-
def from_dict(dictionary: dict) -> Any:
|
70
|
-
return Bunch(**dictionary)
|
1
|
+
import json
|
2
|
+
from typing import Any
|
3
|
+
|
4
|
+
|
5
|
+
class Bunch:
|
6
|
+
def __init__(self, *args, **kwargs):
|
7
|
+
for arg in args:
|
8
|
+
if not isinstance(arg, dict):
|
9
|
+
kwargs[arg] = None
|
10
|
+
self.__dict__.update(kwargs)
|
11
|
+
|
12
|
+
def __getitem__(self, key: Any) -> Any or None:
|
13
|
+
return self.__dict__.get(key, None)
|
14
|
+
|
15
|
+
def __setitem__(self, key: Any, value: Any) -> None:
|
16
|
+
self.__dict__[key] = value
|
17
|
+
|
18
|
+
def __delitem__(self, key: Any) -> None:
|
19
|
+
del self.__dict__[key]
|
20
|
+
|
21
|
+
def __contains__(self, key: Any) -> bool:
|
22
|
+
return key in self.__dict__
|
23
|
+
|
24
|
+
def __str__(self) -> str:
|
25
|
+
return json.dumps(self.__dict__, sort_keys=False)
|
26
|
+
|
27
|
+
def __repr__(self) -> str:
|
28
|
+
return self.__str__()
|
29
|
+
|
30
|
+
def __getattr__(self, key: Any) -> Any or None:
|
31
|
+
if key in self.__dict__:
|
32
|
+
return self.__dict__[key]
|
33
|
+
return None
|
34
|
+
|
35
|
+
def __setattr__(self, name: str, value: Any) -> None:
|
36
|
+
self.__dict__[name] = value
|
37
|
+
|
38
|
+
def __delattr__(self, name) -> None:
|
39
|
+
del self.__dict__[name]
|
40
|
+
|
41
|
+
def contains_value(self, value: Any) -> bool:
|
42
|
+
return value in self.__dict__.values()
|
43
|
+
|
44
|
+
def clear(self) -> None:
|
45
|
+
self.__dict__.clear()
|
46
|
+
|
47
|
+
def pop(self, key: Any, default: Any = None) -> Any or None:
|
48
|
+
return self.__dict__.pop(key, default)
|
49
|
+
|
50
|
+
def popitem(self) -> Any or None:
|
51
|
+
return self.__dict__.popitem()
|
52
|
+
|
53
|
+
def update(self, other: dict) -> None:
|
54
|
+
self.__dict__.update(other)
|
55
|
+
|
56
|
+
def setdefault(self, key: Any, default: Any = None) -> Any or None:
|
57
|
+
return self.__dict__.setdefault(key, default)
|
58
|
+
|
59
|
+
def keys(self):
|
60
|
+
return self.__dict__.keys()
|
61
|
+
|
62
|
+
def values(self):
|
63
|
+
return self.__dict__.values()
|
64
|
+
|
65
|
+
def items(self):
|
66
|
+
return self.__dict__.items()
|
67
|
+
|
68
|
+
@staticmethod
|
69
|
+
def from_dict(dictionary: dict) -> Any:
|
70
|
+
return Bunch(**dictionary)
|
bunch/immutable_bunch.py
CHANGED
@@ -1,75 +1,75 @@
|
|
1
|
-
import json
|
2
|
-
from typing import Any
|
3
|
-
|
4
|
-
|
5
|
-
class ImmutableBunchException(Exception):
|
6
|
-
def __init__(self, message: str) -> None:
|
7
|
-
super().__init__(message)
|
8
|
-
|
9
|
-
|
10
|
-
class ImmutableBunch:
|
11
|
-
def __init__(self, *args, **kwargs):
|
12
|
-
for arg in args:
|
13
|
-
if not isinstance(arg, dict):
|
14
|
-
kwargs[arg] = None
|
15
|
-
self.__dict__.update(kwargs)
|
16
|
-
|
17
|
-
def __getitem__(self, key: Any) -> Any or None:
|
18
|
-
return self.__dict__.get(key, None)
|
19
|
-
|
20
|
-
def __setitem__(self, key: Any, value: Any) -> None:
|
21
|
-
raise ImmutableBunchException('ImmutableBunch does not support item assignment')
|
22
|
-
|
23
|
-
def __delitem__(self, key: Any) -> None:
|
24
|
-
raise ImmutableBunchException('ImmutableBunch does not support item deletion')
|
25
|
-
|
26
|
-
def __contains__(self, key: Any) -> bool:
|
27
|
-
return key in self.__dict__
|
28
|
-
|
29
|
-
def __str__(self) -> str:
|
30
|
-
return json.dumps(self.__dict__, sort_keys=False)
|
31
|
-
|
32
|
-
def __repr__(self) -> str:
|
33
|
-
return self.__str__()
|
34
|
-
|
35
|
-
def __getattr__(self, key: Any) -> Any or None:
|
36
|
-
if key in self.__dict__:
|
37
|
-
return self.__dict__[key]
|
38
|
-
return None
|
39
|
-
|
40
|
-
def __setattr__(self, name: str, value: Any) -> None:
|
41
|
-
raise ImmutableBunchException('ImmutableBunch does not support attribute assignment')
|
42
|
-
|
43
|
-
def __delattr__(self, name) -> None:
|
44
|
-
raise ImmutableBunchException('ImmutableBunch does not support attribute deletion')
|
45
|
-
|
46
|
-
def contains_value(self, value: Any) -> bool:
|
47
|
-
return value in self.__dict__.values()
|
48
|
-
|
49
|
-
def clear(self) -> None:
|
50
|
-
raise ImmutableBunchException('ImmutableBunch does not support clearing')
|
51
|
-
|
52
|
-
def pop(self, key: Any, default: Any = None) -> Any or None:
|
53
|
-
raise ImmutableBunchException('ImmutableBunch does not support popping')
|
54
|
-
|
55
|
-
def popitem(self) -> Any or None:
|
56
|
-
raise ImmutableBunchException('ImmutableBunch does not support popitem')
|
57
|
-
|
58
|
-
def update(self, other: dict) -> None:
|
59
|
-
raise ImmutableBunchException('ImmutableBunch does not support update')
|
60
|
-
|
61
|
-
def setdefault(self, key: Any, default: Any = None) -> Any or None:
|
62
|
-
raise ImmutableBunchException('ImmutableBunch does not support setdefault')
|
63
|
-
|
64
|
-
def keys(self):
|
65
|
-
return self.__dict__.keys()
|
66
|
-
|
67
|
-
def values(self):
|
68
|
-
return self.__dict__.values()
|
69
|
-
|
70
|
-
def items(self):
|
71
|
-
return self.__dict__.items()
|
72
|
-
|
73
|
-
@staticmethod
|
74
|
-
def from_dict(dictionary: dict) -> Any:
|
75
|
-
return ImmutableBunch(**dictionary)
|
1
|
+
import json
|
2
|
+
from typing import Any
|
3
|
+
|
4
|
+
|
5
|
+
class ImmutableBunchException(Exception):
|
6
|
+
def __init__(self, message: str) -> None:
|
7
|
+
super().__init__(message)
|
8
|
+
|
9
|
+
|
10
|
+
class ImmutableBunch:
|
11
|
+
def __init__(self, *args, **kwargs):
|
12
|
+
for arg in args:
|
13
|
+
if not isinstance(arg, dict):
|
14
|
+
kwargs[arg] = None
|
15
|
+
self.__dict__.update(kwargs)
|
16
|
+
|
17
|
+
def __getitem__(self, key: Any) -> Any or None:
|
18
|
+
return self.__dict__.get(key, None)
|
19
|
+
|
20
|
+
def __setitem__(self, key: Any, value: Any) -> None:
|
21
|
+
raise ImmutableBunchException('ImmutableBunch does not support item assignment')
|
22
|
+
|
23
|
+
def __delitem__(self, key: Any) -> None:
|
24
|
+
raise ImmutableBunchException('ImmutableBunch does not support item deletion')
|
25
|
+
|
26
|
+
def __contains__(self, key: Any) -> bool:
|
27
|
+
return key in self.__dict__
|
28
|
+
|
29
|
+
def __str__(self) -> str:
|
30
|
+
return json.dumps(self.__dict__, sort_keys=False)
|
31
|
+
|
32
|
+
def __repr__(self) -> str:
|
33
|
+
return self.__str__()
|
34
|
+
|
35
|
+
def __getattr__(self, key: Any) -> Any or None:
|
36
|
+
if key in self.__dict__:
|
37
|
+
return self.__dict__[key]
|
38
|
+
return None
|
39
|
+
|
40
|
+
def __setattr__(self, name: str, value: Any) -> None:
|
41
|
+
raise ImmutableBunchException('ImmutableBunch does not support attribute assignment')
|
42
|
+
|
43
|
+
def __delattr__(self, name) -> None:
|
44
|
+
raise ImmutableBunchException('ImmutableBunch does not support attribute deletion')
|
45
|
+
|
46
|
+
def contains_value(self, value: Any) -> bool:
|
47
|
+
return value in self.__dict__.values()
|
48
|
+
|
49
|
+
def clear(self) -> None:
|
50
|
+
raise ImmutableBunchException('ImmutableBunch does not support clearing')
|
51
|
+
|
52
|
+
def pop(self, key: Any, default: Any = None) -> Any or None:
|
53
|
+
raise ImmutableBunchException('ImmutableBunch does not support popping')
|
54
|
+
|
55
|
+
def popitem(self) -> Any or None:
|
56
|
+
raise ImmutableBunchException('ImmutableBunch does not support popitem')
|
57
|
+
|
58
|
+
def update(self, other: dict) -> None:
|
59
|
+
raise ImmutableBunchException('ImmutableBunch does not support update')
|
60
|
+
|
61
|
+
def setdefault(self, key: Any, default: Any = None) -> Any or None:
|
62
|
+
raise ImmutableBunchException('ImmutableBunch does not support setdefault')
|
63
|
+
|
64
|
+
def keys(self):
|
65
|
+
return self.__dict__.keys()
|
66
|
+
|
67
|
+
def values(self):
|
68
|
+
return self.__dict__.values()
|
69
|
+
|
70
|
+
def items(self):
|
71
|
+
return self.__dict__.items()
|
72
|
+
|
73
|
+
@staticmethod
|
74
|
+
def from_dict(dictionary: dict) -> Any:
|
75
|
+
return ImmutableBunch(**dictionary)
|
@@ -1,52 +1,53 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: python-bunch
|
3
|
-
Version: 0.1.
|
4
|
-
Summary: A lightweight Python class that behaves like a dict but supports attribute-style access.
|
5
|
-
Author-email: Omer Menashe <unspecified@mail.com>
|
6
|
-
License: MIT
|
7
|
-
|
8
|
-
|
9
|
-
Classifier:
|
10
|
-
Classifier:
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
-
|
24
|
-
-
|
25
|
-
-
|
26
|
-
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
print(my_bunch
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
print(my_immutable_bunch
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: python-bunch
|
3
|
+
Version: 0.1.6
|
4
|
+
Summary: A lightweight Python class that behaves like a dict but supports attribute-style access.
|
5
|
+
Author-email: Omer Menashe <unspecified@mail.com>
|
6
|
+
License: MIT
|
7
|
+
Project-URL: Source, https://github.com/iamomerm/python-bunch
|
8
|
+
Keywords: python-bunch,bunch,dict,attribute-access,json,utility
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
11
|
+
Classifier: Operating System :: OS Independent
|
12
|
+
Requires-Python: >=3.7
|
13
|
+
Description-Content-Type: text/markdown
|
14
|
+
License-File: LICENSE
|
15
|
+
Dynamic: license-file
|
16
|
+
|
17
|
+
## Bunch
|
18
|
+
|
19
|
+
A simple Python class that allows dictionary-style and attribute-style access to data interchangeably. Think of it as a lightweight object wrapper for dictionaries — great for config objects, JSON responses, or anything else you'd normally throw in a dict.
|
20
|
+
|
21
|
+
### <ins> Features </ins>
|
22
|
+
|
23
|
+
- Access keys as attributes or like a dictionary
|
24
|
+
- Convert from regular dictionaries
|
25
|
+
- Pretty-printed JSON representation
|
26
|
+
- Check if a value exists
|
27
|
+
- Fully compatible with `in`, `.keys()`, `.items()`, etc.
|
28
|
+
|
29
|
+
### <ins> Installation </ins>
|
30
|
+
|
31
|
+
You can install this package via PIP: _pip install python-bunch_
|
32
|
+
|
33
|
+
### <ins> Usage </ins>
|
34
|
+
|
35
|
+
```python
|
36
|
+
# - Mutable Bunch -
|
37
|
+
from bunch.bunch import Bunch
|
38
|
+
|
39
|
+
my_bunch = Bunch({'name': 'Jane', 'age': 30})
|
40
|
+
|
41
|
+
print(my_bunch.name) # Output: Jane
|
42
|
+
print(my_bunch['age']) # Output: 30
|
43
|
+
|
44
|
+
# - Immutable Bunch -v
|
45
|
+
from bunch.immutable_bunch import ImmutableBunch
|
46
|
+
|
47
|
+
my_immutable_bunch = ImmutableBunch({'name': 'John', 'age': 25})
|
48
|
+
print(my_immutable_bunch.name) # Output: John
|
49
|
+
print(my_immutable_bunch['age']) # Output: 35
|
50
|
+
|
51
|
+
# Attempting to modify an ImmutableBunch will raise an Exception
|
52
|
+
my_immutable_bunch.name = 'Alice' # Raises ImmutableBunchException
|
53
|
+
```
|
@@ -0,0 +1,8 @@
|
|
1
|
+
bunch/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
bunch/bunch.py,sha256=seTk3I_dKKAmVcMHTTUZUWXZYkPQYV_aStgl2eN0V-I,1945
|
3
|
+
bunch/immutable_bunch.py,sha256=SIGHf0HSfJbddEr8wfVK3mB-qSnaO1_rz--VQKcr5Cc,2522
|
4
|
+
python_bunch-0.1.6.dist-info/licenses/LICENSE,sha256=pd5qyxFyPdg1u_AlxsTrh9RF1Ys0AH8sM3C0HTC9EgY,1057
|
5
|
+
python_bunch-0.1.6.dist-info/METADATA,sha256=FZyX2weuuFpOgY3z7rZSG19njP3aRsJ4bbijlc997H4,1828
|
6
|
+
python_bunch-0.1.6.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
|
7
|
+
python_bunch-0.1.6.dist-info/top_level.txt,sha256=A1w3sDjR8t1mZ4GDuhD9afxgybqy6nHJHPA4CbrgFRA,6
|
8
|
+
python_bunch-0.1.6.dist-info/RECORD,,
|
@@ -1,18 +1,18 @@
|
|
1
|
-
This applies only to the contents of this package and does not affect the licensing of any projects that depend on it.
|
2
|
-
|
3
|
-
This is free and unencumbered software released into the public domain.
|
4
|
-
|
5
|
-
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
6
|
-
software, either in source code form or as a compiled binary, for any purpose,
|
7
|
-
commercial or non-commercial, and by any means.
|
8
|
-
|
9
|
-
In jurisdictions that recognize copyright laws, the author has dedicated any
|
10
|
-
copyright interest in the software to the public domain. This software is
|
11
|
-
provided "as is", without warranty of any kind, express or implied, including
|
12
|
-
but not limited to the warranties of merchantability, fitness for a particular
|
13
|
-
purpose and noninfringement. In no event shall the authors be liable for any
|
14
|
-
claim, damages or other liability, whether in an action of contract, tort or
|
15
|
-
otherwise, arising from, out of or in connection with the software or the use
|
16
|
-
or other dealings in the software.
|
17
|
-
|
18
|
-
For more information, please refer to <https://unlicense.org>
|
1
|
+
This applies only to the contents of this package and does not affect the licensing of any projects that depend on it.
|
2
|
+
|
3
|
+
This is free and unencumbered software released into the public domain.
|
4
|
+
|
5
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
6
|
+
software, either in source code form or as a compiled binary, for any purpose,
|
7
|
+
commercial or non-commercial, and by any means.
|
8
|
+
|
9
|
+
In jurisdictions that recognize copyright laws, the author has dedicated any
|
10
|
+
copyright interest in the software to the public domain. This software is
|
11
|
+
provided "as is", without warranty of any kind, express or implied, including
|
12
|
+
but not limited to the warranties of merchantability, fitness for a particular
|
13
|
+
purpose and noninfringement. In no event shall the authors be liable for any
|
14
|
+
claim, damages or other liability, whether in an action of contract, tort or
|
15
|
+
otherwise, arising from, out of or in connection with the software or the use
|
16
|
+
or other dealings in the software.
|
17
|
+
|
18
|
+
For more information, please refer to <https://unlicense.org>
|
@@ -1,8 +0,0 @@
|
|
1
|
-
bunch/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
bunch/bunch.py,sha256=KThKq7aLFbig8EVnbXzZKcCaD4AVRFCF9XJUquWV5rw,1875
|
3
|
-
bunch/immutable_bunch.py,sha256=5tCZeMRSOAAv5bWhNKUKEWV8DE0LMTxS4OF1KmlbOCw,2447
|
4
|
-
python_bunch-0.1.5.dist-info/licenses/LICENSE,sha256=Hsoz6W43KBiNLAODKAcjo2witGQKjZ05gVU_mUD4eHs,1039
|
5
|
-
python_bunch-0.1.5.dist-info/METADATA,sha256=uhpwWbI6h05P2S4pSMzpW2hrK6Hl_8tWgsCFW9OMueI,1713
|
6
|
-
python_bunch-0.1.5.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
7
|
-
python_bunch-0.1.5.dist-info/top_level.txt,sha256=A1w3sDjR8t1mZ4GDuhD9afxgybqy6nHJHPA4CbrgFRA,6
|
8
|
-
python_bunch-0.1.5.dist-info/RECORD,,
|
File without changes
|