Move commands to class variable

This commit is contained in:
Bálint Bokros 2018-01-18 14:35:53 +01:00 committed by Kristóf Tóth
parent 677bd57ba4
commit ce07c4d6ec

View File

@ -14,6 +14,10 @@ class SourceCodeEventHandler(EventHandlerBase):
self.filename = filename self.filename = filename
self.language = map_file_extension_to_language(filename) self.language = map_file_extension_to_language(filename)
self.process_name = process_name or splitext(filename)[0] self.process_name = process_name or splitext(filename)[0]
self.commands = {
'read': self.read_file,
'write': self.write_file
}
server = xmlrpc.client.ServerProxy(SUPERVISOR_HTTP_URI) server = xmlrpc.client.ServerProxy(SUPERVISOR_HTTP_URI)
self.supervisor = server.supervisor self.supervisor = server.supervisor
@ -22,9 +26,7 @@ class SourceCodeEventHandler(EventHandlerBase):
def handle_event(self, anchor, data_json): def handle_event(self, anchor, data_json):
data = data_json['data'] data = data_json['data']
command_handlers = {'read': self.read_file, self.commands[data['command']](data_json)
'write': self.write_file}
command_handlers[data['command']](data_json)
return data_json return data_json
def handle_reset(self, data_json): def handle_reset(self, data_json):