当前位置: 首页>>代码示例>>Python>>正文


Python fields.Boolean方法代码示例

本文整理汇总了Python中marshmallow.fields.Boolean方法的典型用法代码示例。如果您正苦于以下问题:Python fields.Boolean方法的具体用法?Python fields.Boolean怎么用?Python fields.Boolean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在marshmallow.fields的用法示例。


在下文中一共展示了fields.Boolean方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: format_data

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Boolean [as 别名]
def format_data(self, data, **_):
        params = {}

        for param, field in data.items():
            env_param = self.prefix + param.upper()

            if env_param in env:  # Prefer environ
                value = env.get(env_param)
                if isinstance(field, fields.Integer):
                    value = int(value)
                if isinstance(field, fields.Boolean):
                    value = str(value).strip().lower() in ["1", "true", "yes"]
            else:
                value = data[param]

            params[param] = value

        return params 
开发者ID:aioli-framework,项目名称:aioli,代码行数:20,代码来源:config.py

示例2: inline

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Boolean [as 别名]
def inline(self, field, context):
        # type: (fields.Field, JitContext) -> Optional[str]
        """Generates a template for inlining boolean serialization.

        For example, generates:

        (
            (value in __some_field_truthy) or
            (False if value in __some_field_falsy else bool(value))
        )

        This is somewhat fragile but it tracks what Marshmallow does.
        """
        if is_overridden(field._serialize, fields.Boolean._serialize):
            return None
        truthy_symbol = '__{0}_truthy'.format(field.name)
        falsy_symbol = '__{0}_falsy'.format(field.name)
        context.namespace[truthy_symbol] = field.truthy
        context.namespace[falsy_symbol] = field.falsy
        result = ('(({0} in ' + truthy_symbol +
                  ') or (False if {0} in ' + falsy_symbol +
                  ' else dict()["error"]))')
        return result + ' if {0} is not None else None' 
开发者ID:lyft,项目名称:toasted-marshmallow,代码行数:25,代码来源:jit.py

示例3: create_app

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Boolean [as 别名]
def create_app(self):
        app = Flask(__name__)
        Rebar().init_app(app=app)

        class Schema(validation.RequestSchema):
            foo = fields.Integer(required=True)
            bar = fields.Boolean()
            baz = validation.CommaSeparatedList(fields.Integer())

        @app.route("/stuffs", methods=["GET"])
        def query_string_handler():
            params = get_query_string_params_or_400(schema=Schema())
            return response(data=params)

        return app 
开发者ID:plangrid,项目名称:flask-rebar,代码行数:17,代码来源:test_errors.py

示例4: schema

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Boolean [as 别名]
def schema():
    class BasicSchema(Schema):
        class Meta:
            ordered = True
        foo = fields.Integer(attribute='@#')
        bar = fields.String()
        raz = fields.Method('raz_')
        meh = fields.String(load_only=True)
        blargh = fields.Boolean()

        def raz_(self, obj):
            return 'Hello!'
    return BasicSchema() 
开发者ID:lyft,项目名称:toasted-marshmallow,代码行数:15,代码来源:test_jit.py

示例5: routes

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Boolean [as 别名]
def routes(app, models, schemas, filter_fields):
    class WidgetViewBase(GenericModelView):
        model = models["widget"]
        schema = schemas["widget"]

    class WidgetListView(WidgetViewBase):
        filtering = Filtering(
            color=operator.eq,
            color_allow_empty=ColumnFilter(
                "color", operator.eq, allow_empty=True
            ),
            size=ColumnFilter(operator.eq, separator="|"),
            size_min=ColumnFilter("size", operator.ge),
            size_divides=ColumnFilter(
                "size", lambda size, value: size % value == 0
            ),
            size_is_odd=ModelFilter(
                fields.Boolean(),
                lambda model, value: model.size % 2 == int(value),
            ),
            size_min_unvalidated=ColumnFilter(
                "size", operator.ge, validate=False
            ),
            size_skip_invalid=ColumnFilter(
                "size", operator.eq, skip_invalid=True
            ),
        )

        def get(self):
            return self.list()

    class WidgetSizeRequiredListView(WidgetViewBase):
        filtering = Filtering(size=ColumnFilter(operator.eq, required=True))

        def get(self):
            return self.list()

    class WidgetColorCustomListView(WidgetViewBase):
        filtering = Filtering(color=filter_fields["color_custom"])

        def get(self):
            return self.list()

    class WidgetDefaultFiltersView(WidgetViewBase):
        filtering = Filtering(
            color=ModelFilter(
                fields.String(missing="red"),
                lambda model, value: model.color == value,
            ),
            size=ColumnFilter(operator.eq, missing=1),
        )

        def get(self):
            return self.list()

    api = Api(app)
    api.add_resource("/widgets", WidgetListView)
    api.add_resource("/widgets_size_required", WidgetSizeRequiredListView)
    api.add_resource("/widgets_color_custom", WidgetColorCustomListView)
    api.add_resource("/widgets_default_filters", WidgetDefaultFiltersView) 
开发者ID:4Catalyzer,项目名称:flask-resty,代码行数:62,代码来源:test_filtering.py


注:本文中的marshmallow.fields.Boolean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。