Skip to main content

dnode

$ pip install dnode

from dnode import *


print('============== load data ===============')

data = {
    'a': 1,
    'b': {'b1': 3},
    'c': {'c1': 1, 'c2': {'c22': 22}},
    'd': ['d1', 'd2', 'd3'],
    'e': [{'ee': 1}, {'ee': 2}, {'ee': 3}],
    'f': [['f11', 'f12'], ['f21', 'f22']],
    'g': [[{'gg': 11}, {'gg': 12}], [{'gg': 21}, {'gg': 22}]],
}

obj = DNode(data)

print(obj.serialize())
assert obj.serialize() == data

print('=========== print object ===============')

print(obj)
obj.pprint()

print('============= print json ===============')

print(obj.json)  
# or print(obj.dumps(indent=4))

print('=========== test getattr ===============')

assert obj.a == 1
assert obj.b.b1 == 3
assert obj.c.c2 == {'c22': 22} == DNode({'c22': 22})
assert obj.d[1] == 'd2'
assert obj.e[1].ee == 2
assert obj.f[0][0] == 'f11'
assert obj.g[0][0].gg == 11

print('=========== test setattr ===============')

obj.a = 'change_a'
obj.b.b1 = 'change_b'
obj.c.c2.c22 = 'change_c'
obj.d[1] = 'change_d'
obj.e[1].ee = 'change_e'
obj.f[0][0] = 'change_f'
obj.g[0][0].gg = 'change_g'

data = obj.serialize()
assert data['a'] == 'change_a'
assert data['b']['b1'] == 'change_b'
assert data['c']['c2']['c22'] == 'change_c'
assert data['d'][1] == 'change_d'
assert data['e'][1]['ee'] == 'change_e'
assert data['f'][0][0] == 'change_f'
assert data['g'][0][0]['gg'] == 'change_g'

print('======== test set non-json type =========')

obj.a = {1, 2, 3}
data = obj.serialize()
assert data['a'] == None

print('============== test clear ===============')

obj.clear()
obj.pprint()

print('============== list init ================')

data = '[ {"a": 1}, [{"b": 2}, {"c": 3}] ]'
rs = DNode(data)
print(rs)
assert isinstance(rs, list)
assert rs[0].a == 1
assert rs[1][0].b == 2
assert rs[1][1].c == 3

print('=========================================')

print('\n\n-------------- test SMNode ---------------')

print('========= test STRUCT_FIELDS ============')

obj = SMNode({})
SMNode.STRUCT_FIELDS = set(['aaa', 'bbb'])
obj.aaa = 123
obj.ccc = 456
print(obj.json)  
print('`ccc` should not in the output')

print('=========================================')

Metadata

Release files for dnode 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dnode 0.2.4
File Size Uploaded Provenance Actions
dnode-0.2.4.tar.gz 4.4 kB Without provenance Details for dnode-0.2.4.tar.gz

Release files / dnode-0.2.4.tar.gz

Download URL dnode-0.2.4.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
74af56fec341c8b880e7e8159ce8dc569180d48d950d4198a5b7dd887fececf1
BLAKE2b-256 checksum
How to use checksums
085bb5b8f6d2deb81fcc985ebd6db466eba4046c563c89a0f8f88cceeb457172
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.14.0 CPython/2.7.12

Security for dnode 0.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page