示例#1
0
    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)
示例#2
0
文件: test_fields.py 项目: xs/peewee
    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)
示例#3
0
 def db_value(self, value):
     if value is not None:
         return binary_construct(self.encrypt(value))
示例#4
0
 def db_value(self, value):
     if value is not None:
         return self.compress(
             binary_construct(value), self.compression_level)
示例#5
0
 def gzip(data, compression=9):
     return zlib.compress(binary_construct(data), compression)
示例#6
0
 def gzip(data, compression=9):
     return binary_construct(zlib.compress(data, compression))
示例#7
0
 def db_value(self, value):
     if value is not None:
         return binary_construct(self.encrypt(value))
示例#8
0
 def db_value(self, value):
     if value is not None:
         return self.compress(binary_construct(value),
                              self.compression_level)