From cca6ad22958a0d3dbb50df8f6c1e5ceb8ada5839 Mon Sep 17 00:00:00 2001 From: Stephen Early Date: Sat, 6 Jul 2024 12:01:32 +0100 Subject: [PATCH] Add support for RXKB_CONTEXT_NO_SECURE_GETENV Introduced in libxkbregistry-1.5 --- .github/workflows/run-tests.yml | 2 +- tests/test_rxkb.py | 2 ++ xkbregistry/ffi_build.py | 3 ++- xkbregistry/rxkb.py | 18 +++++++++++++++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 405d95b..c393132 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -9,7 +9,7 @@ jobs: matrix: python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] - runs-on: 'ubuntu-latest' + runs-on: 'ubuntu-24.04' steps: - uses: actions/checkout@v4 diff --git a/tests/test_rxkb.py b/tests/test_rxkb.py index 340e03b..edbb321 100644 --- a/tests/test_rxkb.py +++ b/tests/test_rxkb.py @@ -24,6 +24,8 @@ def test_create(self): rxkb.Context) self.assertIsInstance(rxkb.Context(load_exotic_rules=True), rxkb.Context) + self.assertIsInstance(rxkb.Context(no_secure_getenv=True), + rxkb.Context) def test_include_path_append(self): ctx = rxkb.Context(no_default_includes=True) diff --git a/xkbregistry/ffi_build.py b/xkbregistry/ffi_build.py index 5a94331..b6eb237 100644 --- a/xkbregistry/ffi_build.py +++ b/xkbregistry/ffi_build.py @@ -1,7 +1,7 @@ from cffi import FFI ffibuilder = FFI() -# Currently implemented with reference to libxkbcommon-1.0 +# Currently implemented with reference to libxkbcommon-1.5 ffibuilder.set_source("xkbregistry._ffi", """ #include @@ -55,6 +55,7 @@ RXKB_CONTEXT_NO_FLAGS = ..., RXKB_CONTEXT_NO_DEFAULT_INCLUDES = ..., RXKB_CONTEXT_LOAD_EXOTIC_RULES = ..., + RXKB_CONTEXT_NO_SECURE_GETENV = ..., }; enum rxkb_log_level { diff --git a/xkbregistry/rxkb.py b/xkbregistry/rxkb.py index 4e7879a..ce52070 100644 --- a/xkbregistry/rxkb.py +++ b/xkbregistry/rxkb.py @@ -76,12 +76,28 @@ class Context: different contexts are completely separated and do not share any memory or state. """ - def __init__(self, no_default_includes=False, load_exotic_rules=False): + def __init__(self, no_default_includes=False, load_exotic_rules=False, + no_secure_getenv=False): + """Create a new context. + + Keyword arguments: + + no_default_includes: if set, create this context with an empty + include path. + + load_exotic_rules: if set, load the extra items that are + considered too exotic for the default list. + + no_secure_getenv: if set, use getenv() instead of + secure_getenv() to obtain environment variables. + """ flags = lib.RXKB_CONTEXT_NO_FLAGS if no_default_includes: flags = flags | lib.RXKB_CONTEXT_NO_DEFAULT_INCLUDES if load_exotic_rules: flags = flags | lib.RXKB_CONTEXT_LOAD_EXOTIC_RULES + if no_secure_getenv: + flags = flags | lib.RXKB_CONTEXT_NO_SECURE_GETENV context = lib.rxkb_context_new(flags) if not context: raise RXKBError("Couldn't create RXKB context")