def handle(self): self.logger.debug("slim request handle started") self.wfile.write(b'Slim -- V0.3\n') running = True while running: instructionLength = int(self.rfile.read(6)) self.rfile.read(1) instructions = self.rfile.read(instructionLength).decode('utf-8') self.logger.debug("len={} data={}".format(instructionLength, instructions)) if instructions == 'bye': self.logger.debug("'bye' received") running = False else: statements = ListDeserializer.deserialize(instructions) self.executor = ListExecutor() results = self.executor.execute(statements) x = ListSerializer.serialize(results) response = '%06d:%s' % (len(x), x) self.logger.debug("reponse={}".format(response)) self.wfile.write(response.encode('utf-8')) self.logger.debug("server shutdown requested") self.server.done()
def handle(self): self.wfile.write('Slim -- V0.0\n') while True: instructionLength = int(self.rfile.read(6)) self.rfile.read(1) instructions = self.rfile.read(instructionLength) if instructions == 'bye': return log('instructions {%s}' % instructions) statements = ListDeserializer.deserialize(instructions) self.executor = ListExecutor() results = self.executor.execute(statements) x = ListSerializer.serialize(results) log(x) self.wfile.write('%06d:%s' % (len(x), x))
def dataReceived(self, data): #log('dataReceived ' + data) try: self.file = FileAdapter(data) instructionLength = int(self.file.read(6)) self.file.read(1) instructions = self.file.read(instructionLength) if instructions == 'bye': #self.transport.loseConnection() reactor.stop() return log('instructions {%s}' % instructions) statements = ListDeserializer.deserialize(instructions) self.executor = ListExecutor() results = self.executor.execute(statements) x = ListSerializer.serialize(results) log(x) self.transport.write('%06d:%s' % (len(x), x)) except Exception, e: log(traceback.format_exc())