Skip to content

Commit d3af53b

Browse files
committed
load_module: Add missing parameters for ly_ctx_load_module
1 parent 76504c4 commit d3af53b

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

libyang/context.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# SPDX-License-Identifier: MIT
55

66
import os
7-
from typing import IO, Any, Callable, Iterator, Optional, Tuple, Union
7+
from typing import IO, Any, Callable, Iterator, Optional, Sequence, Tuple, Union
88

99
from _libyang import ffi, lib
1010
from .data import (
@@ -16,7 +16,7 @@
1616
validation_flags,
1717
)
1818
from .schema import Module, SNode, schema_in_format
19-
from .util import DataType, IOType, LibyangError, c2str, data_load, str2c
19+
from .util import DataType, IOType, LibyangError, c2str, data_load, str2c, strlist2c
2020

2121

2222
# -------------------------------------------------------------------------------------
@@ -338,10 +338,19 @@ def parse_module_file(
338338
def parse_module_str(self, s: str, fmt: str = "yang", features=None) -> Module:
339339
return self.parse_module(s, IOType.MEMORY, fmt, features)
340340

341-
def load_module(self, name: str) -> Module:
341+
def load_module(
342+
self,
343+
name: str,
344+
revision: Optional[str] = None,
345+
enabled_features: Sequence[str] = (),
346+
) -> Module:
342347
if self.cdata is None:
343348
raise RuntimeError("context already destroyed")
344-
mod = lib.ly_ctx_load_module(self.cdata, str2c(name), ffi.NULL, ffi.NULL)
349+
if enabled_features:
350+
features = tuple([str2c(f) for f in enabled_features] + [ffi.NULL])
351+
else:
352+
features = ffi.NULL
353+
mod = lib.ly_ctx_load_module(self.cdata, str2c(name), str2c(revision), features)
345354
if mod == ffi.NULL:
346355
raise self.error("cannot load module")
347356

libyang/util.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: MIT
44

55
import enum
6-
from typing import Optional
6+
from typing import List, Optional
77
import warnings
88

99
from _libyang import ffi, lib
@@ -46,6 +46,15 @@ def p_str2c(s: Optional[str], encode: bool = True):
4646
return ffi.new("char **", s_p)
4747

4848

49+
# -------------------------------------------------------------------------------------
50+
def strlist2c(l: Optional[List[str]], encode: bool = True):
51+
if l is None:
52+
return ffi.NULL
53+
items = [str2c(s, encode) for s in l] + [ffi.NULL]
54+
c_strlist = ffi.new("char *[]", items)
55+
return c_strlist
56+
57+
4958
# -------------------------------------------------------------------------------------
5059
def ly_array_count(cdata):
5160
if cdata == ffi.NULL:

0 commit comments

Comments
 (0)