Skip to content

Commit a0c29aa

Browse files
committed
libyang3-py3: patch to support json int/bool as strings
CESNET/libyang-python#134 needed for backwards compatibility for existing configurations.
1 parent 46e0c89 commit a0c29aa

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
From ca54ed6e849582fec90f7a2f05e4cc13247b8846 Mon Sep 17 00:00:00 2001
2+
From: Brad House <[email protected]>
3+
Date: Sun, 16 Feb 2025 10:18:20 -0500
4+
Subject: [PATCH] data: option to allow json int/bool as strings
5+
6+
Depends on https://github.com/CESNET/libyang/pull/2344
7+
8+
Add support for new option to python bindings.
9+
10+
Signed-off-by: Brad House <[email protected]>
11+
---
12+
cffi/cdefs.h | 1 +
13+
libyang/context.py | 6 ++++++
14+
libyang/data.py | 3 +++
15+
3 files changed, 10 insertions(+)
16+
17+
diff --git a/cffi/cdefs.h b/cffi/cdefs.h
18+
index aa75004..de05f4a 100644
19+
--- a/cffi/cdefs.h
20+
+++ b/cffi/cdefs.h
21+
@@ -321,6 +321,7 @@ LY_ERR lyd_print_all(struct ly_out *, const struct lyd_node *, LYD_FORMAT, uint3
22+
#define LYD_PARSE_OPTS_MASK ...
23+
#define LYD_PARSE_ORDERED ...
24+
#define LYD_PARSE_STRICT ...
25+
+#define LYD_PARSE_JSON_STRING_DATATYPES ...
26+
27+
#define LYD_VALIDATE_NO_STATE ...
28+
#define LYD_VALIDATE_PRESENT ...
29+
diff --git a/libyang/context.py b/libyang/context.py
30+
index fb4a330..2781f4c 100644
31+
--- a/libyang/context.py
32+
+++ b/libyang/context.py
33+
@@ -524,6 +524,7 @@ def parse_data(
34+
validate_multi_error: bool = False,
35+
store_only: bool = False,
36+
json_null: bool = False,
37+
+ json_strings: bool = False,
38+
) -> Optional[DNode]:
39+
if self.cdata is None:
40+
raise RuntimeError("context already destroyed")
41+
@@ -536,6 +537,7 @@ def parse_data(
42+
strict=strict,
43+
store_only=store_only,
44+
json_null=json_null,
45+
+ json_string_datatypes=json_string_datatypes,
46+
)
47+
validation_flgs = validation_flags(
48+
no_state=no_state,
49+
@@ -595,6 +597,7 @@ def parse_data_mem(
50+
validate_multi_error: bool = False,
51+
store_only: bool = False,
52+
json_null: bool = False,
53+
+ json_string_datatypes: bool = False,
54+
) -> Optional[DNode]:
55+
return self.parse_data(
56+
fmt,
57+
@@ -611,6 +614,7 @@ def parse_data_mem(
58+
validate_multi_error=validate_multi_error,
59+
store_only=store_only,
60+
json_null=json_null,
61+
+ json_string_datatypes=json_string_datatypes,
62+
)
63+
64+
def parse_data_file(
65+
@@ -628,6 +632,7 @@ def parse_data_file(
66+
validate_multi_error: bool = False,
67+
store_only: bool = False,
68+
json_null: bool = False,
69+
+ json_string_datatypes: bool = False,
70+
) -> Optional[DNode]:
71+
return self.parse_data(
72+
fmt,
73+
@@ -644,6 +649,7 @@ def parse_data_file(
74+
validate_multi_error=validate_multi_error,
75+
store_only=store_only,
76+
json_null=json_null,
77+
+ json_string_datatypes=json_string_datatypes,
78+
)
79+
80+
def __iter__(self) -> Iterator[Module]:
81+
diff --git a/libyang/data.py b/libyang/data.py
82+
index 0d63d3c..0d6f6cf 100644
83+
--- a/libyang/data.py
84+
+++ b/libyang/data.py
85+
@@ -117,6 +117,7 @@ def parser_flags(
86+
strict: bool = False,
87+
store_only: bool = False,
88+
json_null: bool = False,
89+
+ json_string_datatypes: bool = False,
90+
) -> int:
91+
flags = 0
92+
if lyb_mod_update:
93+
@@ -135,6 +136,8 @@ def parser_flags(
94+
flags |= lib.LYD_PARSE_STORE_ONLY
95+
if json_null:
96+
flags |= lib.LYD_PARSE_JSON_NULL
97+
+ if json_string_datatypes:
98+
+ flags |= lib.LYD_PARSE_JSON_STRING_DATATYPES
99+
return flags
100+
101+

src/libyang3-py3.patch/series

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
0001-debian.patch
2+
0002-pr134-json-string-datatypes.patch

0 commit comments

Comments
 (0)