Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data: option to allow json int/bool as strings #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -321,6 +321,7 @@ LY_ERR lyd_print_all(struct ly_out *, const struct lyd_node *, LYD_FORMAT, uint3
#define LYD_PARSE_OPTS_MASK ...
#define LYD_PARSE_ORDERED ...
#define LYD_PARSE_STRICT ...
#define LYD_PARSE_JSON_STRING_DATATYPES ...

#define LYD_VALIDATE_NO_STATE ...
#define LYD_VALIDATE_PRESENT ...
Expand Down
6 changes: 6 additions & 0 deletions libyang/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ def parse_data(
validate_multi_error: bool = False,
store_only: bool = False,
json_null: bool = False,
json_string_datatypes: bool = False,
) -> Optional[DNode]:
if self.cdata is None:
raise RuntimeError("context already destroyed")
Expand All @@ -536,6 +537,7 @@ def parse_data(
strict=strict,
store_only=store_only,
json_null=json_null,
json_string_datatypes=json_string_datatypes,
)
validation_flgs = validation_flags(
no_state=no_state,
Expand Down Expand Up @@ -595,6 +597,7 @@ def parse_data_mem(
validate_multi_error: bool = False,
store_only: bool = False,
json_null: bool = False,
json_string_datatypes: bool = False,
) -> Optional[DNode]:
return self.parse_data(
fmt,
Expand All @@ -611,6 +614,7 @@ def parse_data_mem(
validate_multi_error=validate_multi_error,
store_only=store_only,
json_null=json_null,
json_string_datatypes=json_string_datatypes,
)

def parse_data_file(
Expand All @@ -628,6 +632,7 @@ def parse_data_file(
validate_multi_error: bool = False,
store_only: bool = False,
json_null: bool = False,
json_string_datatypes: bool = False,
) -> Optional[DNode]:
return self.parse_data(
fmt,
Expand All @@ -644,6 +649,7 @@ def parse_data_file(
validate_multi_error=validate_multi_error,
store_only=store_only,
json_null=json_null,
json_string_datatypes=json_string_datatypes,
)

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 @@ -117,6 +117,7 @@ def parser_flags(
strict: bool = False,
store_only: bool = False,
json_null: bool = False,
json_string_datatypes: bool = False,
) -> int:
flags = 0
if lyb_mod_update:
Expand All @@ -135,6 +136,8 @@ def parser_flags(
flags |= lib.LYD_PARSE_STORE_ONLY
if json_null:
flags |= lib.LYD_PARSE_JSON_NULL
if json_string_datatypes:
flags |= lib.LYD_PARSE_JSON_STRING_DATATYPES
return flags


Expand Down
Loading