From 792981742c97144f201a4e2c15cb236e34af20e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Thu, 8 Feb 2018 15:10:37 +0100 Subject: [PATCH] Make SourceCodeEventHandler command handlers data_json['data'] based --- .../source_code_event_handler.py | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/event_handlers/source_code_event_handler.py b/src/event_handlers/source_code_event_handler.py index 942a9e1..51cff20 100644 --- a/src/event_handlers/source_code_event_handler.py +++ b/src/event_handlers/source_code_event_handler.py @@ -65,28 +65,27 @@ class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin): copy('source_code_server/server.py', LOGIN_APP_DIR) copy('source_code_server/users.db', LOGIN_APP_DIR) - def read(self, data_json): - data_json['data'] = { - 'filename': self.filemanager.filename, - 'content': self.filemanager.file_contents, - 'language': self.filemanager.language, - 'files': self.filemanager.files - } + def read(self, data): + data['filename'] = self.filemanager.filename + data['content'] = self.filemanager.file_contents + data['language'] = self.filemanager.language + data['files'] = self.filemanager.files + return data - def write(self, data_json): - self.filemanager.file_contents = data_json['data']['content'] - data_json['data']['files'] = self.filemanager.files + def write(self, data): + self.filemanager.file_contents = data['content'] + data['files'] = self.filemanager.files self.restart_process() + return data - def select(self, data_json): - try: - self.filemanager.select_file(data_json['data']['filename']) - except EnvironmentError: - log.critical('Failed to select file "{}"'.format(data_json['data']['filename'])) + def select(self, data): + try: self.filemanager.select_file(data['filename']) + except EnvironmentError: log.critical('Failed to select file "{}"'.format(data['filename'])) + return data def handle_event(self, anchor, data_json): data = data_json['data'] - self.commands[data['command']](data_json) + data_json['data'] = self.commands[data['command']](data) return data_json