Refactor blacklisting into a method in webide

This commit is contained in:
Kristóf Tóth 2018-04-07 14:35:42 +02:00
parent 4a216d8875
commit 8bd6005b5d

View File

@ -65,9 +65,7 @@ class FileManager: # pylint: disable=too-many-instance-attributes
@property
def files(self):
return [self._relpath(file) for file in glob(join(self._workdir, '**/*'), recursive=True)
if isfile(file)
and self._is_whitelisted(file)
and not any(fnmatchcase(file, blacklisted) for blacklisted in self.exclude)]
if isfile(file) and self._is_whitelisted(file) and not self._is_blacklisted(file)]
@property
def file_contents(self):
@ -82,6 +80,9 @@ class FileManager: # pylint: disable=too-many-instance-attributes
def _is_whitelisted(self, file):
return any(realpath(file).startswith(allowed_dir) for allowed_dir in self.allowed_directories)
def _is_blacklisted(self, file):
return any(fnmatchcase(file, blacklisted) for blacklisted in self.exclude)
def _filepath(self, filename):
return join(self._workdir, filename)