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 <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-11-12 15:59:48 +01:00
commit 9bf5e07da0
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -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