Make Filemanager.is_allowed() public

This commit is contained in:
Kristóf Tóth 2019-09-02 15:49:13 +02:00
parent 57ce35d99d
commit 1d8de09c2a

View File

@ -7,7 +7,7 @@ from os.path import dirname, isdir, isfile, realpath
def _with_is_allowed(func): def _with_is_allowed(func):
@wraps(func) @wraps(func)
def wrapper(self, *args, **kwargs): def wrapper(self, *args, **kwargs):
if self._is_allowed(args[0]): # pylint: disable=protected-access if self.is_allowed(args[0]): # pylint: disable=protected-access
return func(self, *args, **kwargs) return func(self, *args, **kwargs)
raise ValueError('Forbidden path.') raise ValueError('Forbidden path.')
return wrapper return wrapper
@ -23,7 +23,7 @@ class FileManager: # pylint: disable=too-many-instance-attributes
path path
for pattern in self.patterns for pattern in self.patterns
for path in glob(pattern, recursive=True) for path in glob(pattern, recursive=True)
if isfile(path) and self._is_allowed(path) if isfile(path) and self.is_allowed(path)
)) ))
@property @property
@ -39,7 +39,7 @@ class FileManager: # pylint: disable=too-many-instance-attributes
pattern = dirname(pattern) pattern = dirname(pattern)
return pattern return pattern
def _is_allowed(self, filepath): def is_allowed(self, filepath):
return any( return any(
fnmatchcase(realpath(filepath), pattern) fnmatchcase(realpath(filepath), pattern)
for pattern in self.patterns for pattern in self.patterns