Skip to content

Commit c249839

Browse files
committed
data: option to allow json int/bool as strings
Depends on CESNET/libyang#2344 Add support for new option to python bindings. Signed-off-by: Brad House <[email protected]>
1 parent 8534053 commit c249839

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

cffi/cdefs.h

+1
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ LY_ERR lyd_print_all(struct ly_out *, const struct lyd_node *, LYD_FORMAT, uint3
321321
#define LYD_PARSE_OPTS_MASK ...
322322
#define LYD_PARSE_ORDERED ...
323323
#define LYD_PARSE_STRICT ...
324+
#define LYD_PARSE_JSON_STRING_DATATYPES ...
324325

325326
#define LYD_VALIDATE_NO_STATE ...
326327
#define LYD_VALIDATE_PRESENT ...

libyang/context.py

+6
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ def parse_data(
524524
validate_multi_error: bool = False,
525525
store_only: bool = False,
526526
json_null: bool = False,
527+
json_string_datatypes: bool = False,
527528
) -> Optional[DNode]:
528529
if self.cdata is None:
529530
raise RuntimeError("context already destroyed")
@@ -536,6 +537,7 @@ def parse_data(
536537
strict=strict,
537538
store_only=store_only,
538539
json_null=json_null,
540+
json_string_datatypes=json_string_datatypes,
539541
)
540542
validation_flgs = validation_flags(
541543
no_state=no_state,
@@ -595,6 +597,7 @@ def parse_data_mem(
595597
validate_multi_error: bool = False,
596598
store_only: bool = False,
597599
json_null: bool = False,
600+
json_string_datatypes: bool = False,
598601
) -> Optional[DNode]:
599602
return self.parse_data(
600603
fmt,
@@ -611,6 +614,7 @@ def parse_data_mem(
611614
validate_multi_error=validate_multi_error,
612615
store_only=store_only,
613616
json_null=json_null,
617+
json_string_datatypes=json_string_datatypes,
614618
)
615619

616620
def parse_data_file(
@@ -628,6 +632,7 @@ def parse_data_file(
628632
validate_multi_error: bool = False,
629633
store_only: bool = False,
630634
json_null: bool = False,
635+
json_string_datatypes: bool = False,
631636
) -> Optional[DNode]:
632637
return self.parse_data(
633638
fmt,
@@ -644,6 +649,7 @@ def parse_data_file(
644649
validate_multi_error=validate_multi_error,
645650
store_only=store_only,
646651
json_null=json_null,
652+
json_string_datatypes=json_string_datatypes,
647653
)
648654

649655
def __iter__(self) -> Iterator[Module]:

libyang/data.py

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def parser_flags(
117117
strict: bool = False,
118118
store_only: bool = False,
119119
json_null: bool = False,
120+
json_string_datatypes: bool = False,
120121
) -> int:
121122
flags = 0
122123
if lyb_mod_update:
@@ -135,6 +136,8 @@ def parser_flags(
135136
flags |= lib.LYD_PARSE_STORE_ONLY
136137
if json_null:
137138
flags |= lib.LYD_PARSE_JSON_NULL
139+
if json_string_datatypes:
140+
flags |= lib.LYD_PARSE_JSON_STRING_DATATYPES
138141
return flags
139142

140143

0 commit comments

Comments
 (0)