From afc84e1d1a1c2bc71292d0c88ebfa0eb06d04b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Mon, 4 Jun 2018 21:47:10 +0200 Subject: [PATCH] Conciliate FileManager attribute names and formatting --- lib/tfw/components/ide_event_handler.py | 30 ++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/tfw/components/ide_event_handler.py b/lib/tfw/components/ide_event_handler.py index 72fc073..327f6ef 100644 --- a/lib/tfw/components/ide_event_handler.py +++ b/lib/tfw/components/ide_event_handler.py @@ -41,8 +41,8 @@ class FileManager: # pylint: disable=too-many-instance-attributes def workdir(self, directory): if not exists(directory) or not isdir(directory): raise EnvironmentError(f'"{directory}" is not a directory!') - if not self._is_in_whitelisted_dir(directory): - raise EnvironmentError(f'Directory "{directory}" is not in whitelist!') + if not self._is_in_allowed_dir(directory): + raise EnvironmentError(f'Directory "{directory}" is not allowed!') self._workdir = directory @property @@ -65,8 +65,11 @@ 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_in_whitelisted_dir(file) and not self._is_blacklisted(file)] + return [self._relpath(file) + for file in glob(join(self._workdir, '**/*'), recursive=True) + if isfile(file) + and self._is_in_allowed_dir(file) + and not self._is_blacklisted(file)] @property def file_contents(self): @@ -78,8 +81,9 @@ class FileManager: # pylint: disable=too-many-instance-attributes with open(self._filepath(self.filename), 'w', errors='surrogateescape') as ofile: ofile.write(value) - def _is_in_whitelisted_dir(self, path): - return any(realpath(path).startswith(allowed_dir) for allowed_dir in self.allowed_directories) + def _is_in_allowed_dir(self, path): + return any(realpath(path).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) @@ -110,16 +114,22 @@ class IdeEventHandler(EventHandlerBase, MonitorManagerMixin): """ :param key: the key this instance should listen to :param directory: working directory which the EventHandler should serve files from - :param allowed_directories: list of directories that can be switched to using the selectdir command + :param allowed_directories: list of directories that can be switched to using selectdir :param selected_file: file that is selected by default :param exclude: list of filenames that should not appear between files (for .o, .pyc, etc.) """ super().__init__(key) try: - self.filemanager = FileManager(allowed_directories=allowed_directories, working_directory=directory, - selected_file=selected_file, exclude=exclude) + self.filemanager = FileManager( + allowed_directories=allowed_directories, + working_directory=directory, + selected_file=selected_file, + exclude=exclude + ) except IndexError: - raise EnvironmentError(f'No file(s) in IdeEventHandler working_directory "{directory}"!') + raise EnvironmentError( + f'No file(s) in IdeEventHandler working_directory "{directory}"!' + ) MonitorManagerMixin.__init__( self,