From 9bf5e07da02aee39b3fe52cd00981f698edf847a Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Thu, 12 Nov 2026 15:59:48 +0100 Subject: [PATCH] lib.FileContext: Add _set / _create_path_filter() Make the __create_path_filter() closure an overwritable, protected method _create_path_filter(), and add _set_path_filter() to allow subclasses to hook into external path filter manipulations, too. Signed-off-by: Jan Lindemann --- src/python/jw/pkg/lib/FileContext.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/python/jw/pkg/lib/FileContext.py b/src/python/jw/pkg/lib/FileContext.py index 2caa26f9..e5ced518 100644 --- a/src/python/jw/pkg/lib/FileContext.py +++ b/src/python/jw/pkg/lib/FileContext.py @@ -124,29 +124,31 @@ class FileContext(abc.ABC): def chroot(self) -> bool: return self.__chroot + def _create_path_filter( + self, candidate: str | PathFilter | Literal[False] | None + ) -> PathFilter | Literal[False]: + if candidate is None or candidate is False: + return False + if isinstance(candidate, PathFilter): + return candidate + return PathFilter.create(spec = candidate, file_context = self) + @property def path_filter(self) -> PathFilter | None: - - def __create_path_filter( - candidate: str | None | PathFilter | Literal[False] - ) -> PathFilter | Literal[False]: - if candidate is None or candidate is False: - return False - if isinstance(candidate, PathFilter): - return candidate - return PathFilter.create(spec = candidate, file_context = self) - if self.__path_filter is None: query = self.__uri.query_dict if self.__uri.query_dict else {} candidate: str | PathFilter | Literal[False] | None = \ query.get('path-filter') if candidate is None: candidate = self.__default_path_filter - self.__path_filter = __create_path_filter(candidate) + self.__path_filter = self._create_path_filter(candidate) return self.__path_filter or None @path_filter.setter def path_filter(self, value: str | PathFilter | None | Literal[False]) -> None: + self._set_path_filter(value) + + def _set_path_filter(self, value: str | PathFilter | None | Literal[False]) -> None: self.__path_filter = None self.__default_path_filter = value