def test_blob_and_binary_field(self): byte_count = 256 data = ''.join(chr(i) for i in range(256)) blob = BlobModel.create(data=data) # pull from db and check binary data res = BlobModel.get(BlobModel.id == blob.id) self.assertTrue(isinstance(res.data, binary_types)) self.assertEqual(len(res.data), byte_count) db_data = res.data binary_data = binary_construct(data) if db_data != binary_data and sys.version_info[:3] >= (3, 3, 3): db_data = db_data.tobytes() self.assertEqual(db_data, binary_data) # try querying the blob field binary_data = res.data # use the string representation res = BlobModel.get(BlobModel.data == data) self.assertEqual(res.id, blob.id) # use the binary representation res = BlobModel.get(BlobModel.data == binary_data) self.assertEqual(res.id, blob.id)
def db_value(self, value): if value is not None: return binary_construct(self.encrypt(value))
def db_value(self, value): if value is not None: return self.compress( binary_construct(value), self.compression_level)
def gzip(data, compression=9): return zlib.compress(binary_construct(data), compression)
def gzip(data, compression=9): return binary_construct(zlib.compress(data, compression))
def db_value(self, value): if value is not None: return self.compress(binary_construct(value), self.compression_level)