Skip to content

Commit

Permalink
Add support for RXKB_CONTEXT_NO_SECURE_GETENV
Browse files Browse the repository at this point in the history
Introduced in libxkbregistry-1.5
  • Loading branch information
sde1000 committed Jul 6, 2024
1 parent 17ef67c commit cca6ad2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/test_rxkb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion xkbregistry/ffi_build.py
Original file line number Diff line number Diff line change
@@ -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 <stdarg.h>
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 17 additions & 1 deletion xkbregistry/rxkb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit cca6ad2

Please sign in to comment.