From 863cc304ad588bd34528eb39b5c0fcf1fd25d5f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 17 Jan 2018 14:46:30 +0100 Subject: [PATCH] Command -> handler mapping in SourceCodeEventHandler is now nicer --- src/event_handlers/source_code_event_handler.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/event_handlers/source_code_event_handler.py b/src/event_handlers/source_code_event_handler.py index 2113699..c41c517 100644 --- a/src/event_handlers/source_code_event_handler.py +++ b/src/event_handlers/source_code_event_handler.py @@ -24,10 +24,9 @@ class SourceCodeEventHandler(EventHandlerBase): data = data_json['data'] if anchor == b'reset': self.file = self.create_initial_state(process_is_running=True) - if data['command'] == 'read': - self.read_file(data_json) - elif data['command'] == 'write': - self.write_file(data) + command_handlers = {'read': self.read_file, + 'write': self.write_file} + command_handlers[data['command']](data_json) return data_json def read_file(self, data_json): @@ -39,7 +38,8 @@ class SourceCodeEventHandler(EventHandlerBase): 'language': self.language } - def write_file(self, data): + def write_file(self, data_json): + data = data_json['data'] with open(self.file, 'w') as ofile: ofile.write(data['content']) self.supervisor.stopProcess(self.process_name)