api.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:cobalt 作者: PressLabs 项目源码 文件源码
def _create_app(volume_manager, testing=False):
        """Factory method to create the Flask app and register all dependencies.

        Args:
            volume_manager (VolumeManager): The volume manager to be used withing the API controller
            testing (bool): Whether or not to set the `TESTING` flag on the newly generated Flask application

        Returns:
            Flask: The application with all the needed dependencies bootstrapped
        """
        unhandled_exception_errors = {
            'EtcdConnectionFailed': {
                'message': "The ETCD cluster is not responding.",
                'status': 503,
            }
        }

        config = {
            'RESTFUL_JSON': {
                'separators': (', ', ': '),
                'indent': 2,
                'sort_keys': False
            },
            'TESTING': testing
        }

        app = Flask(__name__)
        app.config.update(**config)

        api = RestApi(app, errors=unhandled_exception_errors, catch_all_404s=True)
        Api._register_resources(api)

        app.volume_manager = volume_manager
        app.api = api

        return app
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号