Ejemplo n.º 1
0
def update_thread(manager, connection, stop):
    while True:

        # Read the size and position of the update message
        data = b''
        while True:
            try:
                data += connection.partial_receive(1)
                size = Decoder.decode_message_size(data)
                break
            except IndexError:
                pass
            except:  # pylint: disable=bare-except
                # TODO: is there a better way to catch exceptions when the
                #      thread is forcibly stopped (e.g. by CTRL+c)?
                return
            if stop.is_set():
                connection.close()
                return

        # Read and decode the update message
        data = connection.receive(size)
        update = Decoder.decode_message(data, KRPC.StreamUpdate)

        # Add the data to the cache
        manager.update(update.results)
Ejemplo n.º 2
0
    def receive_message(self, typ):
        """ Receive a protobuf message and decode it """

        # Read the size and position of the response message
        data = b''
        while True:
            try:
                data += self.partial_receive(1)
                size = Decoder.decode_message_size(data)
                break
            except IndexError:
                pass

        # Read and decode the response message
        data = self.receive(size)
        return Decoder.decode_message(data, typ)
Ejemplo n.º 3
0
 def test_message_size(self):
     message = '1c'
     size = Decoder.decode_message_size(unhexlify(message))
     self.assertEqual(28, size)
Ejemplo n.º 4
0
 def test_message_size(self):
     message = '1c'
     size = Decoder.decode_message_size(unhexlify(message))
     self.assertEqual(28, size)