def write_message(self, tag, *fields): buffer = BytesIO() buffer.write(bytearray([0xB0 + len(fields), tag])) pack(buffer, *fields) buffer.seek(0) while self._write_chunk(buffer.read(0x7FFF)): pass
def pack_and_unpack(value): buffer = BytesIO() pack(buffer, value) b = buffer.getvalue() unpacked = UnpackStream(b).unpack() return b, unpacked
def test_packing_unknown_type(): buffer = BytesIO() with raises(TypeError): pack(buffer, object())
def test_4d_point(): with raises(ValueError): _ = pack(Point((0, 0, 0, 0)), version=(2, 0))
def test_3d_point(cls, srid): b, unpacked = pack_and_unpack(cls((0, 0, 0)), version=(2, 0)) assert b == b"\xB4Y" + pack(srid) + b"\x00\x00\x00" assert unpacked == cls((0, 0, 0))
def test_2d_point(cls, srid): b, unpacked = pack_and_unpack(cls((0, 0)), version=(2, 0)) assert b == b"\xB3X" + pack(srid) + b"\x00\x00" assert unpacked == Structure(ord(b"X"), srid, 0, 0)