utility set of handling dict
Project description
features
deepmerge
walker
deepmerge
from dictknife import deepmerge
d0 = {
"a": {
"x": 1
},
"b": {
"y": 10
},
}
d1 = {
"a": {
"x": 1
},
"b": {
"z": 10
},
"c": 100
}
actual = self._callFUT(d0, d1)
expected = {
"a": {
"x": 1
},
"b": {
"y": 10,
"z": 10
},
"c": 100
}
assert actual == expected
walker
using LooseDictWalker example.
import json
import pprint
from dictknife import LooseDictWalker
refs = []
def on_has_ref(path, d):
refs.append((path[:], d["$ref"]))
walker = LooseDictWalker(on_container=on_has_ref)
# from: https://github.com/BigstickCarpet/json-schema-ref-parser
d = json.loads("""
{
"definitions": {
"person": {
"$ref": "schemas/people/Bruce-Wayne.json"
},
"place": {
"$ref": "schemas/places.yaml#/definitions/Gotham-City"
},
"thing": {
"$ref": "http://wayne-enterprises.com/things/batmobile"
},
"color": {
"$ref": "#/definitions/thing/properties/colors/black-as-the-night"
}
}
}
""")
walker.walk(["$ref"], d)
pprint.pprint(refs)
output
[(['definitions', 'color', '$ref'],
'#/definitions/thing/properties/colors/black-as-the-night'),
(['definitions', 'place', '$ref'],
'schemas/places.yaml#/definitions/Gotham-City'),
(['definitions', 'thing', '$ref'],
'http://wayne-enterprises.com/things/batmobile'),
(['definitions', 'person', '$ref'], 'schemas/people/Bruce-Wayne.json')]
todo: description about chains and operator and context,…
0.1
yaml/json load extras (pip install -e .[load])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dictknife-0.2.tar.gz
(5.7 kB
view hashes)
Built Distribution
Close
Hashes for dictknife-0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fd174317ffacef9bcc058f6500135900cf5db3e03542e595b5d44c3a48ef936 |
|
MD5 | 071b06bd489579b4056e47eb6279c421 |
|
BLAKE2b-256 | cde999cf10c8af81993d1a10306502cfa6172629cb61af7df771502e35acf5f8 |