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):
@wraps(func)
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)
raise ValueError('Forbidden path.')
return wrapper
@ -23,7 +23,7 @@ class FileManager: # pylint: disable=too-many-instance-attributes
path
for pattern in self.patterns
for path in glob(pattern, recursive=True)
if isfile(path) and self._is_allowed(path)
if isfile(path) and self.is_allowed(path)
))
@property
@ -39,7 +39,7 @@ class FileManager: # pylint: disable=too-many-instance-attributes
pattern = dirname(pattern)
return pattern
def _is_allowed(self, filepath):
def is_allowed(self, filepath):
return any(
fnmatchcase(realpath(filepath), pattern)
for pattern in self.patterns