Python peewee 模块,BlobField() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用peewee.BlobField()

项目:fillmydb    作者:vladcalin    | 项目源码 | 文件源码
def test_get_fields(self):
        handler = PeeweeHandler(User)

        fields_objs, fields_names = handler.get_fields()
        self.assertIsInstance(fields_objs, list)
        self.assertIsInstance(fields_names, list)

        expected_fields = ["id", "name", "username", "password_hash", "email", "visits", "description"]
        self.assertCountEqual(fields_names, expected_fields)

        for field in fields_objs:
            self.assertIsInstance(field, Field)

        self.assertIsInstance(fields_objs[fields_names.index("id")], IntegerField)
        self.assertIsInstance(fields_objs[fields_names.index("name")], CharField)
        self.assertIsInstance(fields_objs[fields_names.index("username")], CharField)
        self.assertIsInstance(fields_objs[fields_names.index("password_hash")], BlobField)
        self.assertIsInstance(fields_objs[fields_names.index("email")], CharField)
        self.assertIsInstance(fields_objs[fields_names.index("visits")], IntegerField)
        self.assertIsInstance(fields_objs[fields_names.index("description")], CharField)
项目:slim    作者:fy0    | 项目源码 | 文件源码
def _get_args(self, args):
        pw_args = []
        for field_name, op, value in args:
            field = self.view.fields[field_name]
            if isinstance(field, peewee.ForeignKeyField):
                tfield = field.to_field
            else:
                tfield = field

            conv_func = None
            # ?????? peewee ????? int/float ???????????
            if isinstance(tfield, peewee.BlobField):
                conv_func = to_bin
            elif isinstance(tfield, peewee.BooleanField):
                conv_func = bool_parse

            if conv_func:
                try:
                    if op == 'in':
                        value = list(map(conv_func, value))
                    else:
                        value = conv_func(value)
                except binascii.Error:
                    self.err = RETCODE.INVALID_HTTP_PARAMS, 'Invalid query value for blob: Odd-length string'
                    return
                except ValueError as e:
                    self.err = RETCODE.INVALID_HTTP_PARAMS, ' '.join(map(str, e.args))

            pw_args.append(getattr(field, _peewee_method_map[op])(value))
        return pw_args
项目:peewee-moves    作者:timster    | 项目源码 | 文件源码
def test_column_aliases():
    tc = TableCreator('awesome')
    tc.bare('col_bare')
    tc.biginteger('col_biginteger')
    tc.binary('col_binary')
    tc.blob('col_blob')
    tc.bool('col_bool')
    tc.char('col_char')
    tc.date('col_date')
    tc.datetime('col_datetime')
    tc.decimal('col_decimal')
    tc.double('col_double')
    tc.fixed('col_fixed')
    tc.float('col_float')
    tc.int('col_int')
    tc.integer('col_integer')
    tc.smallint('col_smallint')
    tc.smallinteger('col_smallinteger')
    tc.text('col_text')
    tc.time('col_time')
    tc.uuid('col_uuid')

    assert isinstance(tc.model.col_bare, peewee.BareField)
    assert isinstance(tc.model.col_biginteger, peewee.BigIntegerField)
    assert isinstance(tc.model.col_binary, peewee.BlobField)
    assert isinstance(tc.model.col_blob, peewee.BlobField)
    assert isinstance(tc.model.col_bool, peewee.BooleanField)
    assert isinstance(tc.model.col_char, peewee.CharField)
    assert isinstance(tc.model.col_date, peewee.DateField)
    assert isinstance(tc.model.col_datetime, peewee.DateTimeField)
    assert isinstance(tc.model.col_decimal, peewee.DecimalField)
    assert isinstance(tc.model.col_double, peewee.DoubleField)
    assert isinstance(tc.model.col_fixed, peewee.CharField)
    assert isinstance(tc.model.col_float, peewee.FloatField)
    assert isinstance(tc.model.col_int, peewee.IntegerField)
    assert isinstance(tc.model.col_integer, peewee.IntegerField)
    assert isinstance(tc.model.col_smallint, peewee.SmallIntegerField)
    assert isinstance(tc.model.col_smallinteger, peewee.SmallIntegerField)
    assert isinstance(tc.model.col_text, peewee.TextField)
    assert isinstance(tc.model.col_time, peewee.TimeField)
    assert isinstance(tc.model.col_uuid, peewee.UUIDField)
项目:peewee-moves    作者:timster    | 项目源码 | 文件源码
def test_column():
    tc = TableCreator('awesome')
    tc.primary_key('id')
    tc.column('bare', 'col_bare')
    tc.column('biginteger', 'col_biginteger')
    tc.column('binary', 'col_binary')
    tc.column('blob', 'col_blob')
    tc.column('bool', 'col_bool')
    tc.column('char', 'col_char')
    tc.column('date', 'col_date')
    tc.column('datetime', 'col_datetime')
    tc.column('decimal', 'col_decimal')
    tc.column('double', 'col_double')
    tc.column('fixed', 'col_fixed')
    tc.column('float', 'col_float')
    tc.column('int', 'col_int')
    tc.column('integer', 'col_integer')
    tc.column('smallint', 'col_smallint')
    tc.column('smallinteger', 'col_smallinteger')
    tc.column('text', 'col_text')
    tc.column('time', 'col_time')
    tc.column('uuid', 'col_uuid')

    assert isinstance(tc.model.id, peewee.PrimaryKeyField)
    assert isinstance(tc.model.col_bare, peewee.BareField)
    assert isinstance(tc.model.col_biginteger, peewee.BigIntegerField)
    assert isinstance(tc.model.col_binary, peewee.BlobField)
    assert isinstance(tc.model.col_blob, peewee.BlobField)
    assert isinstance(tc.model.col_bool, peewee.BooleanField)
    assert isinstance(tc.model.col_char, peewee.CharField)
    assert isinstance(tc.model.col_date, peewee.DateField)
    assert isinstance(tc.model.col_datetime, peewee.DateTimeField)
    assert isinstance(tc.model.col_decimal, peewee.DecimalField)
    assert isinstance(tc.model.col_double, peewee.DoubleField)
    assert isinstance(tc.model.col_fixed, peewee.CharField)
    assert isinstance(tc.model.col_float, peewee.FloatField)
    assert isinstance(tc.model.col_int, peewee.IntegerField)
    assert isinstance(tc.model.col_integer, peewee.IntegerField)
    assert isinstance(tc.model.col_smallint, peewee.SmallIntegerField)
    assert isinstance(tc.model.col_smallinteger, peewee.SmallIntegerField)
    assert isinstance(tc.model.col_text, peewee.TextField)
    assert isinstance(tc.model.col_time, peewee.TimeField)
    assert isinstance(tc.model.col_uuid, peewee.UUIDField)