From 28259587c6f9f5d66a06627a7f6cf0df5bfa4226 Mon Sep 17 00:00:00 2001 From: Stefan Gula Date: Wed, 28 Feb 2024 13:09:20 +0100 Subject: [PATCH] context: add disable_searchdirs options This patch adds support to disable searching of local directories during loading of module Signed-off-by: Stefan Gula --- libyang/context.py | 7 +++++++ tests/test_context.py | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/libyang/context.py b/libyang/context.py index eefc4e05..1dc021a7 100644 --- a/libyang/context.py +++ b/libyang/context.py @@ -26,6 +26,7 @@ class Context: def __init__( self, search_path: Optional[str] = None, + disable_searchdirs: bool = False, disable_searchdir_cwd: bool = True, explicit_compile: Optional[bool] = False, leafref_extended: bool = False, @@ -33,11 +34,17 @@ def __init__( yanglib_fmt: str = "json", cdata=None, # C type: "struct ly_ctx *" ): + self._module_data_clb = None + self._cffi_handle = ffi.new_handle(self) + self._cdata_modules = [] + if cdata is not None: self.cdata = ffi.cast("struct ly_ctx *", cdata) return # already initialized options = 0 + if disable_searchdirs: + options |= lib.LY_CTX_DISABLE_SEARCHDIRS if disable_searchdir_cwd: options |= lib.LY_CTX_DISABLE_SEARCHDIR_CWD if explicit_compile: diff --git a/tests/test_context.py b/tests/test_context.py index 59839284..c05f0a6d 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -111,3 +111,8 @@ def test_ctx_leafref_extended(self): with Context(YANG_DIR, leafref_extended=True) as ctx: mod = ctx.load_module("yolo-leafref-extended") self.assertIsInstance(mod, Module) + + def test_ctx_disable_searchdirs(self): + with Context(YANG_DIR, disable_searchdirs=True) as ctx: + with self.assertRaises(LibyangError): + ctx.load_module("yolo-nodetypes")