Exemple #1
0
 def wait_message(self, socket):
     while (len(self.__buffer) < 2):
         self.__buffer.extend(socket.recv(1))
     wl = Request.calculate_message_length(self.__buffer)
     while len(self.__buffer) < wl:
         self.__buffer.extend(socket.recv(1))
     msg = self.__buffer[0:wl]
     self.__buffer = self.__buffer[wl:]
     req = Request(msg)
     logging.debug("request:  %s" % req)
     res = self.__protocol.send(req)
     msg = res.get_message()
     logging.debug("response: %s" % bytes(msg))
     socket.sendall(msg)
Exemple #2
0
 def test_calculate_message_length(self):
     self.assertEqual(8, Request.calculate_message_length(b'Q\x00'))
     self.assertEqual(8, Request.calculate_message_length(b'Q\x0f'))
     self.assertEqual(8, Request.calculate_message_length(b'Q\xff'))
     self.assertEqual(16, Request.calculate_message_length(b'W\x02'))