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


Python fields.Method方法代码示例

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


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

示例1: spec_source_id_fm

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Method [as 别名]
def spec_source_id_fm(value: Union[str, int]):
        """
        method used in spec_source_id field.Method
        If value is int, it is transformed int -> "Source" + str(int)

        ex.
        1 -> "Source1"

        :return str: prepends "Source" in case input value is int
        """
        if value:
            try:
                value = int(value)
            except ValueError:
                # not a number
                pass
            else:
                # is a number!
                value = f"Source{value}"
        return value 
开发者ID:packit-service,项目名称:packit,代码行数:22,代码来源:schema.py

示例2: specfile_path_pre

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Method [as 别名]
def specfile_path_pre(self, data: Dict, **kwargs):
        """
        Method for pre-processing specfile_path value.
        Set it to downstream_package_name if specified, else leave unset.

        :param data: conf dictionary to process
        :return: processed dictionary
        """
        if not data:  # data is None when .packit.yaml is empty
            return data

        specfile_path = data.get("specfile_path", None)
        if not specfile_path:
            downstream_package_name = data.get("downstream_package_name", None)
            if downstream_package_name:
                data["specfile_path"] = f"{downstream_package_name}.spec"
                logger.debug(
                    f'Setting `specfile_path` to "./{downstream_package_name}.spec".'
                )
            else:
                # guess it?
                logger.debug(
                    "Neither `specfile_path` nor `downstream_package_name` set."
                )
        return data 
开发者ID:packit-service,项目名称:packit,代码行数:27,代码来源:schema.py

示例3: test_map_type_dump_ma_method_returns_fr_raw

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Method [as 别名]
def test_map_type_dump_ma_method_returns_fr_raw():
    class TestSchema(Schema):
        method_field = ma.Method()

    TestApi = Api()

    expected_method_field_mapping = fr.Raw
    map_result = utils.map_type(TestSchema, TestApi, 'TestSchema','dump')

    assert isinstance(map_result['method_field'], expected_method_field_mapping) 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:12,代码来源:utils_test.py

示例4: schema

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Method [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: _should_skip_field

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Method [as 别名]
def _should_skip_field(field_name, field_obj, context):
    # type: (str, fields.Field, JitContext) -> bool
    load_only = getattr(field_obj, 'load_only', False)
    dump_only = getattr(field_obj, 'dump_only', False)
    # Marshmallow 2.x.x doesn't properly set load_only or
    # dump_only on Method objects.  This is fixed in 3.0.0
    # https://github.com/marshmallow-code/marshmallow/commit/1b676dd36cbb5cf040da4f5f6d43b0430684325c
    if isinstance(field_obj, fields.Method):
        load_only = (
            bool(field_obj.deserialize_method_name) and
            not bool(field_obj.serialize_method_name)
        )
        dump_only = (
            bool(field_obj.serialize_method_name) and
            not bool(field_obj.deserialize_method_name)
        )

    if load_only and context.is_serializing:
        return True
    if dump_only and not context.is_serializing:
        return True
    if context.only and field_name not in context.only:
        return True
    if context.exclude and field_name in context.exclude:
        return True
    return False 
开发者ID:lyft,项目名称:toasted-marshmallow,代码行数:28,代码来源:jit.py


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