當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。