From 8bd6005b5dd0c0f45e8a65298c2eb2d4a9a1ec8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sat, 7 Apr 2018 14:35:42 +0200 Subject: [PATCH] Refactor blacklisting into a method in webide --- lib/tfw/components/webide_event_handler.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/tfw/components/webide_event_handler.py b/lib/tfw/components/webide_event_handler.py index d3992b4..30c3e98 100644 --- a/lib/tfw/components/webide_event_handler.py +++ b/lib/tfw/components/webide_event_handler.py @@ -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)