Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cffi/cdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ LY_ERR lyd_print_all(struct ly_out *, const struct lyd_node *, LYD_FORMAT, uint3
#define LYD_PARSE_LYB_MOD_UPDATE ...
#define LYD_PARSE_NO_STATE ...
#define LYD_PARSE_STORE_ONLY ...
#define LYD_PARSE_JSON_NULL ...
#define LYD_PARSE_ONLY ...
#define LYD_PARSE_OPAQ ...
#define LYD_PARSE_OPTS_MASK ...
Expand Down
6 changes: 6 additions & 0 deletions libyang/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ def parse_data(
validate_present: bool = False,
validate_multi_error: bool = False,
store_only: bool = False,
json_null: bool = False,
) -> Optional[DNode]:
if self.cdata is None:
raise RuntimeError("context already destroyed")
Expand All @@ -531,6 +532,7 @@ def parse_data(
ordered=ordered,
strict=strict,
store_only=store_only,
json_null=json_null,
)
validation_flgs = validation_flags(
no_state=no_state,
Expand Down Expand Up @@ -589,6 +591,7 @@ def parse_data_mem(
validate_present: bool = False,
validate_multi_error: bool = False,
store_only: bool = False,
json_null: bool = False,
) -> Optional[DNode]:
return self.parse_data(
fmt,
Expand All @@ -604,6 +607,7 @@ def parse_data_mem(
validate_present=validate_present,
validate_multi_error=validate_multi_error,
store_only=store_only,
json_null=json_null,
)

def parse_data_file(
Expand All @@ -620,6 +624,7 @@ def parse_data_file(
validate_present: bool = False,
validate_multi_error: bool = False,
store_only: bool = False,
json_null: bool = False,
) -> Optional[DNode]:
return self.parse_data(
fmt,
Expand All @@ -635,6 +640,7 @@ def parse_data_file(
validate_present=validate_present,
validate_multi_error=validate_multi_error,
store_only=store_only,
json_null=json_null,
)

def __iter__(self) -> Iterator[Module]:
Expand Down
3 changes: 3 additions & 0 deletions libyang/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def parser_flags(
ordered: bool = False,
strict: bool = False,
store_only: bool = False,
json_null: bool = False,
) -> int:
flags = 0
if lyb_mod_update:
Expand All @@ -132,6 +133,8 @@ def parser_flags(
flags |= lib.LYD_PARSE_STRICT
if store_only:
flags |= lib.LYD_PARSE_STORE_ONLY
if json_null:
flags |= lib.LYD_PARSE_JSON_NULL
return flags


Expand Down
6 changes: 6 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,3 +1131,9 @@ def test_merge_builtin_plugins_only(self):
self.assertIsInstance(dnode, DLeaf)
self.assertEqual(dnode.value(), "test")
dnode.free()

def test_dnode_parse_json_null(self):
JSON = """{"yolo-nodetypes:ip-address": null}"""
dnode = self.ctx.parse_data_mem(JSON, "json", json_null=True)
dnode_names = [d.name() for d in dnode.siblings()]
self.assertFalse("ip-address" in dnode_names)
Loading