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


Python fields.Boolean方法代码示例

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


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

示例1: make_preassembly_model

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

示例2: start_service

# 需要导入模块: from flask_restx import fields [as 别名]
# 或者: from flask_restx.fields import Boolean [as 别名]
def start_service(self, port):
        apiserver = self
        self.app = Flask(__name__)
        self.app.wsgi_app = ProxyFix(self.app.wsgi_app)
        self.api = Api(self.app, version='1.0', title='Oxfs Api',
                       description='The Oxfs Api')

        # Response model
        fs_namespace = self.api.namespace('fs', description='fs operations')
        status_model = self.api.model(
            'Status',
            {
                'status': fields.Boolean,
                'data': fields.String
            })

        # Request arguments
        string_args = self.api.parser()
        string_args.add_argument('path', required=True, help='absolute path')

        # Api
        @fs_namespace.route('/reload')
        @fs_namespace.expect(string_args)
        class Reload(Resource):
            @fs_namespace.marshal_with(status_model, envelope='data')
            def post(self):
                args = string_args.parse_args()
                path = apiserver.oxfs_fuse.remotepath(args['path'])
                status = (apiserver.cleanf(path), apiserver.cleand(path))
                return {'status': False not in status, 'data': path}

        @fs_namespace.route('/clear')
        class Clear(Resource):
            @fs_namespace.marshal_with(status_model, envelope='data')
            def delete(self):
                status = apiserver.clear()
                return {'status': True, 'data': 'success'}

        @fs_namespace.route('/directories')
        @fs_namespace.expect(string_args)
        class Directories(Resource):
            @fs_namespace.marshal_with(status_model, envelope='data')
            def get(self):
                args = string_args.parse_args()
                path = apiserver.oxfs_fuse.remotepath(args['path'])
                status, data = apiserver.fetchd(path)
                return {'status': status, 'data': data}

        self.set_flask_env()
        self.app.run(port=port, debug=False) 
开发者ID:RainMark,项目名称:oxfs,代码行数:52,代码来源:apiserver.py


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