python-bunch 0.1.6__py3-none-any.whl → 0.1.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.
- bunch/bunch.py +16 -2
- bunch/immutable_bunch.py +17 -3
- {python_bunch-0.1.6.dist-info → python_bunch-0.1.7.dist-info}/METADATA +1 -1
- python_bunch-0.1.7.dist-info/RECORD +8 -0
- {python_bunch-0.1.6.dist-info → python_bunch-0.1.7.dist-info}/WHEEL +1 -1
- python_bunch-0.1.6.dist-info/RECORD +0 -8
- {python_bunch-0.1.6.dist-info → python_bunch-0.1.7.dist-info}/licenses/LICENSE +0 -0
- {python_bunch-0.1.6.dist-info → python_bunch-0.1.7.dist-info}/top_level.txt +0 -0
bunch/bunch.py
CHANGED
@@ -66,5 +66,19 @@ class Bunch:
|
|
66
66
|
return self.__dict__.items()
|
67
67
|
|
68
68
|
@staticmethod
|
69
|
-
def from_dict(dictionary: dict) ->
|
70
|
-
|
69
|
+
def from_dict(dictionary: dict, recursive: bool = True) -> 'Bunch':
|
70
|
+
ret = Bunch()
|
71
|
+
if recursive:
|
72
|
+
for key, value in dictionary.items():
|
73
|
+
if isinstance(value, dict):
|
74
|
+
ret[key] = Bunch.from_dict(value, recursive=True)
|
75
|
+
elif isinstance(value, list):
|
76
|
+
ret[key] = [
|
77
|
+
Bunch.from_dict(item, recursive=True) if isinstance(item, dict) else item
|
78
|
+
for item in value
|
79
|
+
]
|
80
|
+
else:
|
81
|
+
ret[key] = value
|
82
|
+
else:
|
83
|
+
ret.update(dictionary)
|
84
|
+
return ret
|
bunch/immutable_bunch.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import json
|
2
2
|
from typing import Any
|
3
|
-
|
3
|
+
from bunch.bunch import Bunch
|
4
4
|
|
5
5
|
class ImmutableBunchException(Exception):
|
6
6
|
def __init__(self, message: str) -> None:
|
@@ -71,5 +71,19 @@ class ImmutableBunch:
|
|
71
71
|
return self.__dict__.items()
|
72
72
|
|
73
73
|
@staticmethod
|
74
|
-
def from_dict(dictionary: dict) ->
|
75
|
-
|
74
|
+
def from_dict(dictionary: dict, recursive: bool = True) -> 'ImmutableBunch':
|
75
|
+
ret = dict()
|
76
|
+
if recursive:
|
77
|
+
for key, value in dictionary.items():
|
78
|
+
if isinstance(value, dict):
|
79
|
+
ret[key] = ImmutableBunch.from_dict(value, recursive=True)
|
80
|
+
elif isinstance(value, list):
|
81
|
+
ret[key] = [
|
82
|
+
ImmutableBunch.from_dict(item, recursive=True) if isinstance(item, dict) else item
|
83
|
+
for item in value
|
84
|
+
]
|
85
|
+
else:
|
86
|
+
ret[key] = value
|
87
|
+
else:
|
88
|
+
ret.update(dictionary)
|
89
|
+
return ImmutableBunch(**ret)
|
@@ -0,0 +1,8 @@
|
|
1
|
+
bunch/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
bunch/bunch.py,sha256=2McoGdOxW2DCmM4ysMKBsrzsVSG335x9sbrWYREb7Q8,2528
|
3
|
+
bunch/immutable_bunch.py,sha256=8xRbuR-Rwo0o7DieldF6rsXd8GyHAz95xfSkisfdw_A,3169
|
4
|
+
python_bunch-0.1.7.dist-info/licenses/LICENSE,sha256=pd5qyxFyPdg1u_AlxsTrh9RF1Ys0AH8sM3C0HTC9EgY,1057
|
5
|
+
python_bunch-0.1.7.dist-info/METADATA,sha256=HRIQLCZxomfc2_aSiZtQadsbm4PRpbYimf5vHZBk9Vg,1828
|
6
|
+
python_bunch-0.1.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
7
|
+
python_bunch-0.1.7.dist-info/top_level.txt,sha256=A1w3sDjR8t1mZ4GDuhD9afxgybqy6nHJHPA4CbrgFRA,6
|
8
|
+
python_bunch-0.1.7.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
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,,
|
File without changes
|
File without changes
|