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


Python fields.List方法代码示例

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


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

示例1: _model_from_parser

# 需要导入模块: from flask_restx import fields [as 别名]
# 或者: from flask_restx.fields import List [as 别名]
def _model_from_parser(model_name: str, parser: reqparse.RequestParser) -> Model:
    from flask_restx import fields

    base_type_map = {
        "integer": fields.Integer,
        "string": fields.String,
        "number": fields.Float,
    }
    type_factory = {
        "integer": lambda arg: base_type_map["integer"],
        "string": lambda arg: base_type_map["string"],
        "number": lambda arg: base_type_map["number"],
        "array": lambda arg: fields.List(base_type_map[arg["items"]["type"]]),
    }
    return Model(
        model_name,
        {arg["name"]: type_factory[arg["type"]](arg) for arg in parser.__schema__},
    ) 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:20,代码来源:decorators.py

示例2: guarantee_at_most_one_or_retire

# 需要导入模块: from flask_restx import fields [as 别名]
# 或者: from flask_restx.fields import List [as 别名]
def guarantee_at_most_one_or_retire(decks: List[Deck]) -> Optional[Deck]:
    try:
        run = guarantee.at_most_one(decks)
    except TooManyItemsException:
        league.retire_deck(decks[0])
        run = decks[1]
    return run 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:9,代码来源:api.py

示例3: test_unpack_list

# 需要导入模块: from flask_restx import fields [as 别名]
# 或者: from flask_restx.fields import List [as 别名]
def test_unpack_list():
    app = Flask(__name__)
    api = Api(app)
    with patch("flask_accepts.utils.unpack_list", wraps=utils.unpack_list) as mock:
        result = utils.unpack_list(ma.List(ma.Integer()), api=api)

        assert isinstance(result, fr.List)
        assert mock.call_count == 1 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:10,代码来源:utils_test.py

示例4: test_unpack_list_of_list

# 需要导入模块: from flask_restx import fields [as 别名]
# 或者: from flask_restx.fields import List [as 别名]
def test_unpack_list_of_list():
    app = Flask(__name__)
    api = Api(app)
    with patch(
        "flask_accepts.utils.unpack_list", wraps=utils.unpack_list
    ) as mock, patch.dict("flask_accepts.utils.type_map", {ma.List: mock}):

        result = utils.unpack_list(ma.List(ma.List(ma.Integer())), api=api)

        assert isinstance(result, fr.List)
        assert mock.call_count == 2 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:13,代码来源:utils_test.py

示例5: test_ma_field_to_reqparse_argument_list_values

# 需要导入模块: from flask_restx import fields [as 别名]
# 或者: from flask_restx.fields import List [as 别名]
def test_ma_field_to_reqparse_argument_list_values():
    result = utils.ma_field_to_reqparse_argument(ma.List(ma.Integer()))
    assert result["type"] is int
    assert result["required"] is False
    assert result["action"] == "append"
    assert "help" not in result

    result = utils.ma_field_to_reqparse_argument(ma.List(ma.String(), description="A description"))
    assert result["type"] is str
    assert result["required"] is False
    assert result["action"] == "append"
    assert result["help"] == "A description" 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:14,代码来源:utils_test.py

示例6: unpack_list

# 需要导入模块: from flask_restx import fields [as 别名]
# 或者: from flask_restx.fields import List [as 别名]
def unpack_list(val, api, model_name: str = None, operation: str = "dump"):
    model_name = model_name or get_default_model_name()
    return fr.List(
        map_type(val.inner, api, model_name, operation), **_ma_field_to_fr_field(val)
    ) 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:7,代码来源:utils.py

示例7: is_list_field

# 需要导入模块: from flask_restx import fields [as 别名]
# 或者: from flask_restx.fields import List [as 别名]
def is_list_field(field):
    """Returns `True` if the given field is a list type."""
    # Need to handle both flask_restx and marshmallow fields.
    return isinstance(field, ma.List) or isinstance(field, fr.List) 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:6,代码来源:utils.py

示例8: make_preassembly_model

# 需要导入模块: from flask_restx import fields [as 别名]
# 或者: from flask_restx.fields import List [as 别名]
def make_preassembly_model(func):
    """Create new Flask model with function arguments."""
    args = inspect.signature(func).parameters
    # We can reuse Staetments model if only stmts_in or stmts and **kwargs are
    # arguments of the function
    if ((len(args) == 1 and ('stmts_in' in args or 'stmts' in args)) or
            (len(args) == 2 and 'kwargs' in args and
                ('stmts_in' in args or 'stmts' in args))):
        return stmts_model
    # Inherit a model if there are other arguments
    model_fields = {}
    for arg in args:
        if arg != 'stmts_in' and arg != 'stmts' and arg != 'kwargs':
            default = None
            if args[arg].default is not inspect.Parameter.empty:
                default = args[arg].default
            # Need to use default for boolean and example for other types
            if arg in boolean_args:
                model_fields[arg] = fields.Boolean(default=default)
            elif arg in int_args:
                model_fields[arg] = fields.Integer(example=default)
            elif arg in float_args:
                model_fields[arg] = fields.Float(example=0.7)
            elif arg in list_args:
                if arg == 'curations':
                    model_fields[arg] = fields.List(
                        fields.Nested(dict_model),
                        example=[{'pa_hash': '1234', 'source_hash': '2345',
                                  'tag': 'wrong_relation'}])
                else:
                    model_fields[arg] = fields.List(
                        fields.String, example=default)
            elif arg in dict_args:
                model_fields[arg] = fields.Nested(dict_model)
            else:
                model_fields[arg] = fields.String(example=default)
    new_model = api.inherit(
        ('%s_input' % func.__name__), stmts_model, model_fields)
    return new_model 
开发者ID:sorgerlab,项目名称:indra,代码行数:41,代码来源:api.py


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