mirror of
				https://github.com/avatao-content/baseimage-tutorial-framework
				synced 2025-11-04 11:52:54 +00:00 
			
		
		
		
	Command -> handler mapping in SourceCodeEventHandler is now nicer
This commit is contained in:
		@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user