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:
parent
372356a8df
commit
9bf5e07da0
1 changed files with 13 additions and 11 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue