Example #1
0
 def rewind(self, position=0):
     if position < 0 or position > len(self._data):
         error_msg = "Invalid position to rewind cursor to: {}.".format(
             position)
         logger.error(error_msg)
         raise Exception(error_msg)
     self._position = position
Example #2
0
    async def start(self) -> bool:
        # TODO PiDAL need authentication feature.
        client = await TCPClient().connect("127.0.0.1", 3306,
                                           timeout=60)  # TODO
        packet_header = await client.read_bytes(4)
        bytes_to_read, packet_number = self._parse_header(packet_header)
        if packet_number != 0:
            logger.error("recv to xxx handshake packet_number is %s",
                         packet_number)

        recv_data = await client.read_bytes(bytes_to_read)
        await self.stream.write(packet_header + recv_data)

        packet_header = await self.stream.read_bytes(4)
        bytes_to_read, packet_number = self._parse_header(packet_header)
        recv_data = await self.stream.read_bytes(bytes_to_read)
        await client.write(packet_header + recv_data)

        packet_header = await client.read_bytes(4)
        bytes_to_read, packet_number = self._parse_header(packet_header)
        recv_data = await client.read_bytes(bytes_to_read)
        await self.stream.write(packet_header + recv_data)
        p_reader = PacketBytesReader(recv_data)
        if p_reader.is_ok_packet():
            return True
        return False
Example #3
0
 def advance(self, length):
     new_position = self._position + length
     if new_position < 0 or new_position > len(self._data):
         error_msg = "Invalid advance amount ({}) for cursor. \
                 Position={}".format(length, new_position)
         logger.error(error_msg)
         raise Exception(error_msg)
     self._position = new_position
Example #4
0
 def read(self, size) -> bytes:
     result = self._data[self._position:(self._position + size)]
     if len(result) != size:
         error_msg = "Result length not requested length. \
                     Expected={}.  Actual={}.\
                     Position: {}.  Data Length: {}".format(
             size, len(result), self._position, len(self._data))
         logger.error(error_msg)
         raise AssertionError(error_msg)
     self._position += size
     return result
Example #5
0
 def read_length_encoded_integer(self) -> int:
     c = self.read_uint8()
     if c < UNSIGNED_CHAR_COLUMN:
         return c
     elif c == UNSIGNED_SHORT_COLUMN:
         return self.read_uint16()
     elif c == UNSIGNED_INT24_COLUMN:
         return self.read_uint24()
     elif c == UNSIGNED_INT64_COLUMN:
         return self.read_uint64()
     logger.error("unknown length integer %s.", c)
     raise Exception("unknown length integer {}.".format(c))