Skip to content

Commit d5f48d6

Browse files
stewegsamuel-gauthier
authored andcommitted
context: add LY_CTX_LEAFREF_EXTENDED option
This patch adds the ability to create context with an additional option for extended leafrefs, which can use deref() functions. Fixes: #85 Signed-off-by: Stefan Gula <steweg@gmail.com> Signed-off-by: Samuel Gauthier <samuel.gauthier@6wind.com>
1 parent 6423bab commit d5f48d6

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

cffi/cdefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct ly_ctx;
1414
#define LY_CTX_EXPLICIT_COMPILE ...
1515
#define LY_CTX_REF_IMPLEMENTED ...
1616
#define LY_CTX_SET_PRIV_PARSED ...
17+
#define LY_CTX_LEAFREF_EXTENDED ...
1718

1819

1920
typedef enum {

cffi/source.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
#if (LY_VERSION_MAJOR != 2)
1010
#error "This version of libyang bindings only works with libyang 2.x"
1111
#endif
12-
#if (LY_VERSION_MINOR < 25)
13-
#error "Need at least libyang 2.25"
12+
#if (LY_VERSION_MINOR < 37)
13+
#error "Need at least libyang 2.37"
1414
#endif

libyang/context.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def __init__(
2828
search_path: Optional[str] = None,
2929
disable_searchdir_cwd: bool = True,
3030
explicit_compile: Optional[bool] = False,
31+
leafref_extended: bool = False,
3132
yanglib_path: Optional[str] = None,
3233
yanglib_fmt: str = "json",
3334
cdata=None, # C type: "struct ly_ctx *"
@@ -41,6 +42,8 @@ def __init__(
4142
options |= lib.LY_CTX_DISABLE_SEARCHDIR_CWD
4243
if explicit_compile:
4344
options |= lib.LY_CTX_EXPLICIT_COMPILE
45+
if leafref_extended:
46+
options |= lib.LY_CTX_LEAFREF_EXTENDED
4447
# force priv parsed
4548
options |= lib.LY_CTX_SET_PRIV_PARSED
4649

tests/test_context.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,8 @@ def test_ctx_parse_module(self):
106106
with Context(YANG_DIR) as ctx:
107107
mod = ctx.parse_module_file(f, features=["turbo-boost", "networking"])
108108
self.assertIsInstance(mod, Module)
109+
110+
def test_ctx_leafref_extended(self):
111+
with Context(YANG_DIR, leafref_extended=True) as ctx:
112+
mod = ctx.load_module("yolo-leafref-extended")
113+
self.assertIsInstance(mod, Module)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module yolo-leafref-extended {
2+
yang-version 1.1;
3+
namespace "urn:yang:yolo:leafref-extended";
4+
prefix leafref-ext;
5+
6+
revision 2025-01-25 {
7+
description
8+
"Initial version.";
9+
}
10+
11+
list list1 {
12+
key leaf1;
13+
leaf leaf1 {
14+
type string;
15+
}
16+
leaf-list leaflist2 {
17+
type string;
18+
}
19+
}
20+
21+
leaf ref1 {
22+
type leafref {
23+
path "../list1/leaf1";
24+
}
25+
}
26+
leaf ref2 {
27+
type leafref {
28+
path "deref(../ref1)/../leaflist2";
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)