python-benedict 0.33.1__tar.gz → 0.34.1__tar.gz
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.
- {python-benedict-0.33.1/python_benedict.egg-info → python_benedict-0.34.1}/PKG-INFO +12 -12
- {python-benedict-0.33.1 → python_benedict-0.34.1}/README.md +9 -8
- python_benedict-0.34.1/benedict/core/clean.py +55 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/keypaths.py +3 -2
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/dicts/__init__.py +9 -3
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/dicts/keylist/keylist_dict.py +6 -6
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/dicts/keypath/keypath_util.py +1 -1
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/metadata.py +1 -1
- {python-benedict-0.33.1 → python_benedict-0.34.1}/pyproject.toml +5 -4
- {python-benedict-0.33.1 → python_benedict-0.34.1/python_benedict.egg-info}/PKG-INFO +12 -12
- python-benedict-0.33.1/benedict/core/clean.py +0 -19
- {python-benedict-0.33.1 → python_benedict-0.34.1}/LICENSE.txt +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/MANIFEST.in +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/__init__.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/__init__.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/clone.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/dump.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/filter.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/find.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/flatten.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/groupby.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/invert.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/items_sorted.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/keylists.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/match.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/merge.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/move.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/nest.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/remove.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/rename.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/search.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/standardize.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/subset.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/swap.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/traverse.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/unflatten.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/core/unique.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/dicts/base/__init__.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/dicts/base/base_dict.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/dicts/io/__init__.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/dicts/io/io_dict.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/dicts/io/io_util.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/dicts/keyattr/__init__.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/dicts/keyattr/keyattr_dict.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/dicts/keylist/__init__.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/dicts/keylist/keylist_util.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/dicts/keypath/__init__.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/dicts/keypath/keypath_dict.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/dicts/parse/__init__.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/dicts/parse/parse_dict.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/dicts/parse/parse_util.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/exceptions.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/extras.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/serializers/__init__.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/serializers/abstract.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/serializers/base64.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/serializers/cli.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/serializers/csv.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/serializers/html.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/serializers/ini.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/serializers/json.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/serializers/pickle.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/serializers/plist.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/serializers/query_string.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/serializers/toml.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/serializers/xls.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/serializers/xml.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/serializers/yaml.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/utils/__init__.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/benedict/utils/type_util.py +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/python_benedict.egg-info/SOURCES.txt +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/python_benedict.egg-info/dependency_links.txt +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/python_benedict.egg-info/requires.txt +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/python_benedict.egg-info/top_level.txt +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/setup.cfg +0 -0
- {python-benedict-0.33.1 → python_benedict-0.34.1}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: python-benedict
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.34.1
|
|
4
4
|
Summary: python-benedict is a dict subclass with keylist/keypath/keyattr support, normalized I/O operations (base64, csv, ini, json, pickle, plist, query-string, toml, xls, xml, yaml) and many utilities... for humans, obviously.
|
|
5
5
|
Author-email: Fabio Caccamo <fabio.caccamo@gmail.com>
|
|
6
6
|
Maintainer-email: Fabio Caccamo <fabio.caccamo@gmail.com>
|
|
@@ -47,11 +47,10 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
47
47
|
Classifier: Natural Language :: English
|
|
48
48
|
Classifier: Operating System :: OS Independent
|
|
49
49
|
Classifier: Programming Language :: Python :: 3
|
|
50
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
51
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
52
50
|
Classifier: Programming Language :: Python :: 3.10
|
|
53
51
|
Classifier: Programming Language :: Python :: 3.11
|
|
54
52
|
Classifier: Programming Language :: Python :: 3.12
|
|
53
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
55
54
|
Classifier: Topic :: Education :: Testing
|
|
56
55
|
Classifier: Topic :: Software Development :: Build Tools
|
|
57
56
|
Classifier: Topic :: System :: Filesystems
|
|
@@ -89,7 +88,7 @@ Requires-Dist: pyyaml<7.0,>=6.0; extra == "yaml"
|
|
|
89
88
|
[](https://www.python.org/)
|
|
90
89
|
[](https://pypi.org/project/python-benedict/)
|
|
91
90
|
[](https://pepy.tech/project/python-benedict)
|
|
92
|
-
[](https://github.com/fabiocaccamo/python-benedict/stargazers)
|
|
91
|
+
[](https://github.com/fabiocaccamo/python-benedict/stargazers)
|
|
93
92
|
[](https://github.com/fabiocaccamo/python-benedict/blob/main/LICENSE.txt)
|
|
94
93
|
|
|
95
94
|
[](https://results.pre-commit.ci/latest/github/fabiocaccamo/python-benedict/main)
|
|
@@ -121,7 +120,7 @@ python-benedict is a dict subclass with **keylist/keypath/keyattr** support, **I
|
|
|
121
120
|
- [Usage](#usage)
|
|
122
121
|
- [Basics](#basics)
|
|
123
122
|
- [Keyattr](#keyattr) `my_dict.x.y.z`
|
|
124
|
-
- [Keylist](#keylist) `my_dict["x", "y", "z"]`
|
|
123
|
+
- [Keylist](#keylist) `my_dict[["x", "y", "z"]]`
|
|
125
124
|
- [Keypath](#keypath) `my_dict["x.y.z"]`
|
|
126
125
|
- [Custom keypath separator](#custom-keypath-separator)
|
|
127
126
|
- [Change keypath separator](#change-keypath-separator)
|
|
@@ -218,22 +217,22 @@ d.keyattr_dynamic = True
|
|
|
218
217
|
> **Warning** - even if this feature is very useful, it has some obvious limitations: it works only for string keys that are *unprotected* (not starting with an `_`) and that don't clash with the currently supported methods names.
|
|
219
218
|
|
|
220
219
|
### Keylist
|
|
221
|
-
Wherever a **key** is used, it is possible to use also a **list
|
|
220
|
+
Wherever a **key** is used, it is possible to use also a **list of keys**.
|
|
222
221
|
|
|
223
222
|
```python
|
|
224
223
|
d = benedict()
|
|
225
224
|
|
|
226
225
|
# set values by keys list
|
|
227
|
-
d["profile", "firstname"] = "Fabio"
|
|
228
|
-
d["profile", "lastname"] = "Caccamo"
|
|
226
|
+
d[["profile", "firstname"]] = "Fabio"
|
|
227
|
+
d[["profile", "lastname"]] = "Caccamo"
|
|
229
228
|
print(d) # -> { "profile":{ "firstname":"Fabio", "lastname":"Caccamo" } }
|
|
230
229
|
print(d["profile"]) # -> { "firstname":"Fabio", "lastname":"Caccamo" }
|
|
231
230
|
|
|
232
231
|
# check if keypath exists in dict
|
|
233
|
-
print(["profile", "lastname"] in d) # -> True
|
|
232
|
+
print([["profile", "lastname"]] in d) # -> True
|
|
234
233
|
|
|
235
234
|
# delete value by keys list
|
|
236
|
-
del d["profile", "lastname"]
|
|
235
|
+
del d[["profile", "lastname"]]
|
|
237
236
|
print(d["profile"]) # -> { "firstname":"Fabio" }
|
|
238
237
|
```
|
|
239
238
|
|
|
@@ -546,7 +545,8 @@ items = d.items_sorted_by_values(reverse=False)
|
|
|
546
545
|
```python
|
|
547
546
|
# Return a list of all keypaths in the dict.
|
|
548
547
|
# If indexes is True, the output will include list values indexes.
|
|
549
|
-
|
|
548
|
+
# If sort is True, the resulting list will be sorted
|
|
549
|
+
k = d.keypaths(indexes=False, sort=True)
|
|
550
550
|
```
|
|
551
551
|
|
|
552
552
|
#### `match`
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[](https://www.python.org/)
|
|
2
2
|
[](https://pypi.org/project/python-benedict/)
|
|
3
3
|
[](https://pepy.tech/project/python-benedict)
|
|
4
|
-
[](https://github.com/fabiocaccamo/python-benedict/stargazers)
|
|
4
|
+
[](https://github.com/fabiocaccamo/python-benedict/stargazers)
|
|
5
5
|
[](https://github.com/fabiocaccamo/python-benedict/blob/main/LICENSE.txt)
|
|
6
6
|
|
|
7
7
|
[](https://results.pre-commit.ci/latest/github/fabiocaccamo/python-benedict/main)
|
|
@@ -33,7 +33,7 @@ python-benedict is a dict subclass with **keylist/keypath/keyattr** support, **I
|
|
|
33
33
|
- [Usage](#usage)
|
|
34
34
|
- [Basics](#basics)
|
|
35
35
|
- [Keyattr](#keyattr) `my_dict.x.y.z`
|
|
36
|
-
- [Keylist](#keylist) `my_dict["x", "y", "z"]`
|
|
36
|
+
- [Keylist](#keylist) `my_dict[["x", "y", "z"]]`
|
|
37
37
|
- [Keypath](#keypath) `my_dict["x.y.z"]`
|
|
38
38
|
- [Custom keypath separator](#custom-keypath-separator)
|
|
39
39
|
- [Change keypath separator](#change-keypath-separator)
|
|
@@ -130,22 +130,22 @@ d.keyattr_dynamic = True
|
|
|
130
130
|
> **Warning** - even if this feature is very useful, it has some obvious limitations: it works only for string keys that are *unprotected* (not starting with an `_`) and that don't clash with the currently supported methods names.
|
|
131
131
|
|
|
132
132
|
### Keylist
|
|
133
|
-
Wherever a **key** is used, it is possible to use also a **list
|
|
133
|
+
Wherever a **key** is used, it is possible to use also a **list of keys**.
|
|
134
134
|
|
|
135
135
|
```python
|
|
136
136
|
d = benedict()
|
|
137
137
|
|
|
138
138
|
# set values by keys list
|
|
139
|
-
d["profile", "firstname"] = "Fabio"
|
|
140
|
-
d["profile", "lastname"] = "Caccamo"
|
|
139
|
+
d[["profile", "firstname"]] = "Fabio"
|
|
140
|
+
d[["profile", "lastname"]] = "Caccamo"
|
|
141
141
|
print(d) # -> { "profile":{ "firstname":"Fabio", "lastname":"Caccamo" } }
|
|
142
142
|
print(d["profile"]) # -> { "firstname":"Fabio", "lastname":"Caccamo" }
|
|
143
143
|
|
|
144
144
|
# check if keypath exists in dict
|
|
145
|
-
print(["profile", "lastname"] in d) # -> True
|
|
145
|
+
print([["profile", "lastname"]] in d) # -> True
|
|
146
146
|
|
|
147
147
|
# delete value by keys list
|
|
148
|
-
del d["profile", "lastname"]
|
|
148
|
+
del d[["profile", "lastname"]]
|
|
149
149
|
print(d["profile"]) # -> { "firstname":"Fabio" }
|
|
150
150
|
```
|
|
151
151
|
|
|
@@ -458,7 +458,8 @@ items = d.items_sorted_by_values(reverse=False)
|
|
|
458
458
|
```python
|
|
459
459
|
# Return a list of all keypaths in the dict.
|
|
460
460
|
# If indexes is True, the output will include list values indexes.
|
|
461
|
-
|
|
461
|
+
# If sort is True, the resulting list will be sorted
|
|
462
|
+
k = d.keypaths(indexes=False, sort=True)
|
|
462
463
|
```
|
|
463
464
|
|
|
464
465
|
#### `match`
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
def _clean_dict(d, strings, collections):
|
|
2
|
+
keys = list(d.keys())
|
|
3
|
+
for key in keys:
|
|
4
|
+
d[key] = _clean_value(d[key], strings=strings, collections=collections)
|
|
5
|
+
if d[key] is None:
|
|
6
|
+
del d[key]
|
|
7
|
+
return d
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _clean_list(ls, strings, collections):
|
|
11
|
+
for i in range(len(ls) - 1, -1, -1):
|
|
12
|
+
ls[i] = _clean_value(ls[i], strings=strings, collections=collections)
|
|
13
|
+
if ls[i] is None:
|
|
14
|
+
ls.pop(i)
|
|
15
|
+
return ls
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _clean_set(values, strings, collections):
|
|
19
|
+
return {
|
|
20
|
+
value
|
|
21
|
+
for value in values
|
|
22
|
+
if _clean_value(value, strings=strings, collections=collections) is not None
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _clean_str(s, strings, collections):
|
|
27
|
+
return s if s and s.strip() else None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _clean_tuple(values, strings, collections):
|
|
31
|
+
return tuple(
|
|
32
|
+
value
|
|
33
|
+
for value in values
|
|
34
|
+
if _clean_value(value, strings=strings, collections=collections) is not None
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _clean_value(value, strings, collections):
|
|
39
|
+
if value is None:
|
|
40
|
+
return value
|
|
41
|
+
elif isinstance(value, list) and collections:
|
|
42
|
+
value = _clean_list(value, strings=strings, collections=collections) or None
|
|
43
|
+
elif isinstance(value, dict) and collections:
|
|
44
|
+
value = _clean_dict(value, strings=strings, collections=collections) or None
|
|
45
|
+
elif isinstance(value, set) and collections:
|
|
46
|
+
value = _clean_set(value, strings=strings, collections=collections) or None
|
|
47
|
+
elif isinstance(value, str) and strings:
|
|
48
|
+
value = _clean_str(value, strings=strings, collections=collections) or None
|
|
49
|
+
elif isinstance(value, tuple) and collections:
|
|
50
|
+
value = _clean_tuple(value, strings=strings, collections=collections) or None
|
|
51
|
+
return value
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def clean(d, strings=True, collections=True):
|
|
55
|
+
return _clean_dict(d, strings=strings, collections=collections)
|
|
@@ -2,11 +2,12 @@ from benedict.core.keylists import keylists
|
|
|
2
2
|
from benedict.utils import type_util
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
def keypaths(d, separator=".", indexes=False):
|
|
5
|
+
def keypaths(d, separator=".", indexes=False, sort=True):
|
|
6
6
|
separator = separator or "."
|
|
7
7
|
if not type_util.is_string(separator):
|
|
8
8
|
raise ValueError("separator argument must be a (non-empty) string.")
|
|
9
9
|
kls = keylists(d, indexes=indexes)
|
|
10
10
|
kps = [separator.join([f"{key}" for key in kl]) for kl in kls]
|
|
11
|
-
|
|
11
|
+
if sort:
|
|
12
|
+
kps.sort()
|
|
12
13
|
return kps
|
|
@@ -26,6 +26,7 @@ from benedict.dicts.io import IODict
|
|
|
26
26
|
from benedict.dicts.keyattr import KeyattrDict
|
|
27
27
|
from benedict.dicts.keylist import KeylistDict
|
|
28
28
|
from benedict.dicts.keypath import KeypathDict
|
|
29
|
+
from benedict.dicts.keypath import keypath_util
|
|
29
30
|
from benedict.dicts.parse import ParseDict
|
|
30
31
|
from benedict.serializers import JSONSerializer, YAMLSerializer
|
|
31
32
|
|
|
@@ -195,12 +196,14 @@ class benedict(KeyattrDict, KeypathDict, IODict, ParseDict):
|
|
|
195
196
|
"""
|
|
196
197
|
return _items_sorted_by_values(self, reverse=reverse)
|
|
197
198
|
|
|
198
|
-
def keypaths(self, indexes=False):
|
|
199
|
+
def keypaths(self, indexes=False, sort=True):
|
|
199
200
|
"""
|
|
200
201
|
Return a list of all keypaths in the dict.
|
|
201
202
|
If indexes is True, the output will include list values indexes.
|
|
202
203
|
"""
|
|
203
|
-
return _keypaths(
|
|
204
|
+
return _keypaths(
|
|
205
|
+
self, separator=self._keypath_separator, indexes=indexes, sort=sort
|
|
206
|
+
)
|
|
204
207
|
|
|
205
208
|
def match(self, pattern, indexes=True):
|
|
206
209
|
"""
|
|
@@ -219,7 +222,10 @@ class benedict(KeyattrDict, KeypathDict, IODict, ParseDict):
|
|
|
219
222
|
If overwrite is False, existing values will not be overwritten.
|
|
220
223
|
If concat is True, list values will be concatenated together.
|
|
221
224
|
"""
|
|
222
|
-
|
|
225
|
+
others = [other] + list(args)
|
|
226
|
+
for other in others:
|
|
227
|
+
keypath_util.check_keys(other, self._keypath_separator)
|
|
228
|
+
_merge(self, *others, **kwargs)
|
|
223
229
|
|
|
224
230
|
def move(self, key_src, key_dest):
|
|
225
231
|
"""
|
|
@@ -8,7 +8,7 @@ class KeylistDict(BaseDict):
|
|
|
8
8
|
super().__init__(*args, **kwargs)
|
|
9
9
|
|
|
10
10
|
def __contains__(self, key):
|
|
11
|
-
if type_util.
|
|
11
|
+
if type_util.is_list(key):
|
|
12
12
|
return self._contains_by_keys(key)
|
|
13
13
|
return super().__contains__(key)
|
|
14
14
|
|
|
@@ -19,7 +19,7 @@ class KeylistDict(BaseDict):
|
|
|
19
19
|
return False
|
|
20
20
|
|
|
21
21
|
def __delitem__(self, key):
|
|
22
|
-
if type_util.
|
|
22
|
+
if type_util.is_list(key):
|
|
23
23
|
self._delitem_by_keys(key)
|
|
24
24
|
return
|
|
25
25
|
super().__delitem__(key)
|
|
@@ -35,7 +35,7 @@ class KeylistDict(BaseDict):
|
|
|
35
35
|
raise KeyError(f"Invalid keys: {keys!r}")
|
|
36
36
|
|
|
37
37
|
def __getitem__(self, key):
|
|
38
|
-
if type_util.
|
|
38
|
+
if type_util.is_list(key):
|
|
39
39
|
return self._getitem_by_keys(key)
|
|
40
40
|
return super().__getitem__(key)
|
|
41
41
|
|
|
@@ -46,7 +46,7 @@ class KeylistDict(BaseDict):
|
|
|
46
46
|
raise KeyError(f"Invalid keys: {keys!r}")
|
|
47
47
|
|
|
48
48
|
def __setitem__(self, key, value):
|
|
49
|
-
if type_util.
|
|
49
|
+
if type_util.is_list(key):
|
|
50
50
|
self._setitem_by_keys(key, value)
|
|
51
51
|
return
|
|
52
52
|
super().__setitem__(key, value)
|
|
@@ -55,7 +55,7 @@ class KeylistDict(BaseDict):
|
|
|
55
55
|
keylist_util.set_item(self, keys, value)
|
|
56
56
|
|
|
57
57
|
def get(self, key, default=None):
|
|
58
|
-
if type_util.
|
|
58
|
+
if type_util.is_list(key):
|
|
59
59
|
return self._get_by_keys(key, default)
|
|
60
60
|
return super().get(key, default)
|
|
61
61
|
|
|
@@ -68,7 +68,7 @@ class KeylistDict(BaseDict):
|
|
|
68
68
|
return default
|
|
69
69
|
|
|
70
70
|
def pop(self, key, *args):
|
|
71
|
-
if type_util.
|
|
71
|
+
if type_util.is_list(key):
|
|
72
72
|
return self._pop_by_keys(key, *args)
|
|
73
73
|
return super().pop(key, *args)
|
|
74
74
|
|
|
@@ -26,7 +26,7 @@ def parse_keys(keypath, separator):
|
|
|
26
26
|
"""
|
|
27
27
|
Parse keys from keylist or keypath using the given separator.
|
|
28
28
|
"""
|
|
29
|
-
if type_util.
|
|
29
|
+
if type_util.is_list(keypath):
|
|
30
30
|
keys = []
|
|
31
31
|
for key in keypath:
|
|
32
32
|
keys += parse_keys(key, separator)
|
|
@@ -77,11 +77,10 @@ classifiers = [
|
|
|
77
77
|
"Natural Language :: English",
|
|
78
78
|
"Operating System :: OS Independent",
|
|
79
79
|
"Programming Language :: Python :: 3",
|
|
80
|
-
"Programming Language :: Python :: 3.8",
|
|
81
|
-
"Programming Language :: Python :: 3.9",
|
|
82
80
|
"Programming Language :: Python :: 3.10",
|
|
83
81
|
"Programming Language :: Python :: 3.11",
|
|
84
82
|
"Programming Language :: Python :: 3.12",
|
|
83
|
+
"Programming Language :: Python :: 3.13",
|
|
85
84
|
"Topic :: Education :: Testing",
|
|
86
85
|
"Topic :: Software Development :: Build Tools",
|
|
87
86
|
"Topic :: System :: Filesystems",
|
|
@@ -167,11 +166,13 @@ exclude = '''
|
|
|
167
166
|
'''
|
|
168
167
|
|
|
169
168
|
[tool.ruff]
|
|
170
|
-
ignore = ["B905", "E501"]
|
|
171
169
|
line-length = 88
|
|
170
|
+
|
|
171
|
+
[tool.ruff.lint]
|
|
172
|
+
ignore = ["B905", "E501"]
|
|
172
173
|
select = ["B", "B9", "C", "E", "F", "W"]
|
|
173
174
|
|
|
174
|
-
[tool.ruff.mccabe]
|
|
175
|
+
[tool.ruff.lint.mccabe]
|
|
175
176
|
max-complexity = 10
|
|
176
177
|
|
|
177
178
|
[tool.setuptools.packages.find]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: python-benedict
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.34.1
|
|
4
4
|
Summary: python-benedict is a dict subclass with keylist/keypath/keyattr support, normalized I/O operations (base64, csv, ini, json, pickle, plist, query-string, toml, xls, xml, yaml) and many utilities... for humans, obviously.
|
|
5
5
|
Author-email: Fabio Caccamo <fabio.caccamo@gmail.com>
|
|
6
6
|
Maintainer-email: Fabio Caccamo <fabio.caccamo@gmail.com>
|
|
@@ -47,11 +47,10 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
47
47
|
Classifier: Natural Language :: English
|
|
48
48
|
Classifier: Operating System :: OS Independent
|
|
49
49
|
Classifier: Programming Language :: Python :: 3
|
|
50
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
51
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
52
50
|
Classifier: Programming Language :: Python :: 3.10
|
|
53
51
|
Classifier: Programming Language :: Python :: 3.11
|
|
54
52
|
Classifier: Programming Language :: Python :: 3.12
|
|
53
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
55
54
|
Classifier: Topic :: Education :: Testing
|
|
56
55
|
Classifier: Topic :: Software Development :: Build Tools
|
|
57
56
|
Classifier: Topic :: System :: Filesystems
|
|
@@ -89,7 +88,7 @@ Requires-Dist: pyyaml<7.0,>=6.0; extra == "yaml"
|
|
|
89
88
|
[](https://www.python.org/)
|
|
90
89
|
[](https://pypi.org/project/python-benedict/)
|
|
91
90
|
[](https://pepy.tech/project/python-benedict)
|
|
92
|
-
[](https://github.com/fabiocaccamo/python-benedict/stargazers)
|
|
91
|
+
[](https://github.com/fabiocaccamo/python-benedict/stargazers)
|
|
93
92
|
[](https://github.com/fabiocaccamo/python-benedict/blob/main/LICENSE.txt)
|
|
94
93
|
|
|
95
94
|
[](https://results.pre-commit.ci/latest/github/fabiocaccamo/python-benedict/main)
|
|
@@ -121,7 +120,7 @@ python-benedict is a dict subclass with **keylist/keypath/keyattr** support, **I
|
|
|
121
120
|
- [Usage](#usage)
|
|
122
121
|
- [Basics](#basics)
|
|
123
122
|
- [Keyattr](#keyattr) `my_dict.x.y.z`
|
|
124
|
-
- [Keylist](#keylist) `my_dict["x", "y", "z"]`
|
|
123
|
+
- [Keylist](#keylist) `my_dict[["x", "y", "z"]]`
|
|
125
124
|
- [Keypath](#keypath) `my_dict["x.y.z"]`
|
|
126
125
|
- [Custom keypath separator](#custom-keypath-separator)
|
|
127
126
|
- [Change keypath separator](#change-keypath-separator)
|
|
@@ -218,22 +217,22 @@ d.keyattr_dynamic = True
|
|
|
218
217
|
> **Warning** - even if this feature is very useful, it has some obvious limitations: it works only for string keys that are *unprotected* (not starting with an `_`) and that don't clash with the currently supported methods names.
|
|
219
218
|
|
|
220
219
|
### Keylist
|
|
221
|
-
Wherever a **key** is used, it is possible to use also a **list
|
|
220
|
+
Wherever a **key** is used, it is possible to use also a **list of keys**.
|
|
222
221
|
|
|
223
222
|
```python
|
|
224
223
|
d = benedict()
|
|
225
224
|
|
|
226
225
|
# set values by keys list
|
|
227
|
-
d["profile", "firstname"] = "Fabio"
|
|
228
|
-
d["profile", "lastname"] = "Caccamo"
|
|
226
|
+
d[["profile", "firstname"]] = "Fabio"
|
|
227
|
+
d[["profile", "lastname"]] = "Caccamo"
|
|
229
228
|
print(d) # -> { "profile":{ "firstname":"Fabio", "lastname":"Caccamo" } }
|
|
230
229
|
print(d["profile"]) # -> { "firstname":"Fabio", "lastname":"Caccamo" }
|
|
231
230
|
|
|
232
231
|
# check if keypath exists in dict
|
|
233
|
-
print(["profile", "lastname"] in d) # -> True
|
|
232
|
+
print([["profile", "lastname"]] in d) # -> True
|
|
234
233
|
|
|
235
234
|
# delete value by keys list
|
|
236
|
-
del d["profile", "lastname"]
|
|
235
|
+
del d[["profile", "lastname"]]
|
|
237
236
|
print(d["profile"]) # -> { "firstname":"Fabio" }
|
|
238
237
|
```
|
|
239
238
|
|
|
@@ -546,7 +545,8 @@ items = d.items_sorted_by_values(reverse=False)
|
|
|
546
545
|
```python
|
|
547
546
|
# Return a list of all keypaths in the dict.
|
|
548
547
|
# If indexes is True, the output will include list values indexes.
|
|
549
|
-
|
|
548
|
+
# If sort is True, the resulting list will be sorted
|
|
549
|
+
k = d.keypaths(indexes=False, sort=True)
|
|
550
550
|
```
|
|
551
551
|
|
|
552
552
|
#### `match`
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
from benedict.utils import type_util
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def _clean_item(d, key, strings, collections):
|
|
5
|
-
value = d.get(key, None)
|
|
6
|
-
if not value:
|
|
7
|
-
del_none = value is None
|
|
8
|
-
del_string = strings and type_util.is_string(value)
|
|
9
|
-
del_collection = collections and type_util.is_collection(value)
|
|
10
|
-
return any([del_none, del_string, del_collection])
|
|
11
|
-
|
|
12
|
-
return False
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def clean(d, strings=True, collections=True):
|
|
16
|
-
keys = list(d.keys())
|
|
17
|
-
for key in keys:
|
|
18
|
-
if _clean_item(d, key, strings, collections):
|
|
19
|
-
del d[key]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python-benedict-0.33.1 → python_benedict-0.34.1}/python_benedict.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|