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


Python api.create_app方法代码示例

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


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

示例1: client

# 需要导入模块: import api [as 别名]
# 或者: from api import create_app [as 别名]
def client(postgres):
    config_dict = {
        "SQLALCHEMY_DATABASE_URI": postgres.url(),
        "DEBUG": True,
        "SQLALCHEMY_TRACK_MODIFICATIONS": False,
    }
    app = create_app(config_dict)
    app.app_context().push()

    time.sleep(2)
    from api.models import db

    db.create_all()
    # for test client api reference
    # http://flask.pocoo.org/docs/1.0/api/#test-client
    client = app.test_client()
    yield client 
开发者ID:tko22,项目名称:flask-boilerplate,代码行数:19,代码来源:conftest.py

示例2: main

# 需要导入模块: import api [as 别名]
# 或者: from api import create_app [as 别名]
def main():
    """Parse web API startup flags."""
    parser = ArgumentParser(description="CTF API configuration")
    parser.add_argument(
        "-p",
        "--port",
        action="store",
        help="port the server should listen on.",
        type=int,
        default=8000,
    )
    parser.add_argument(
        "-l",
        "--listen",
        action="store",
        help="host the server should listen on.",
        default="0.0.0.0",
    )
    parser.add_argument(
        "-d",
        "--debug",
        action="store_true",
        help="run the server in debug mode.",
        default=False,
    )
    parser.add_argument(
        "-k",
        "--debug-key",
        action="store",
        help="debug key for problem grading; only applies if debug is enabled",
        type=str,
        default=None,
    )
    args = parser.parse_args()

    if args.debug:
        api.submissions.DEBUG_KEY = args.debug_key

    api.create_app().run(
        host=args.listen, port=args.port, debug=args.debug,
    ) 
开发者ID:picoCTF,项目名称:picoCTF,代码行数:43,代码来源:run.py

示例3: client

# 需要导入模块: import api [as 别名]
# 或者: from api import create_app [as 别名]
def client():
    """Create a test client of the Flask app."""
    app = api.create_app(
        {
            "TESTING": True,
            "MONGO_DB_NAME": TESTING_DB_NAME,
            "MONGO_PORT": 27018,
            "RATE_LIMIT_BYPASS_KEY": RATE_LIMIT_BYPASS_KEY,
        }
    )
    return app.test_client() 
开发者ID:picoCTF,项目名称:picoCTF,代码行数:13,代码来源:common.py

示例4: app

# 需要导入模块: import api [as 别名]
# 或者: from api import create_app [as 别名]
def app():
    """Create an instance of the Flask app for testing."""
    app = api.create_app(
        {"TESTING": True, "MONGO_DB_NAME": TESTING_DB_NAME, "MONGO_PORT": 27018}
    )
    return app 
开发者ID:picoCTF,项目名称:picoCTF,代码行数:8,代码来源:common.py

示例5: initialize_test_client

# 需要导入模块: import api [as 别名]
# 或者: from api import create_app [as 别名]
def initialize_test_client(self):
        from api import create_app
        self.app = create_app(testing=True)
        self.app_context = self.app.test_request_context()                      
        self.app_context.push()                           
        self.client = self.app.test_client()

        # Hopefully temporary hack to ensure session is cleared after each test
        import api
        api.db.session.close() 
开发者ID:IntegralDefense,项目名称:ACE,代码行数:12,代码来源:test.py

示例6: execute_api_server

# 需要导入模块: import api [as 别名]
# 或者: from api import create_app [as 别名]
def execute_api_server(self, listen_address=None, listen_port=None, ssl_cert=None, ssl_key=None):

        # https://gist.github.com/rduplain/1705072
        # this is a bit weird because I want the urls to be the same as they
        # are configured for apache, where they are all starting with /api
        
        import api
        from saq.database import initialize_database

        app = api.create_app(testing=True)
        from werkzeug.serving import run_simple
        from werkzeug.wsgi import DispatcherMiddleware
        from flask import Flask
        app.config['DEBUG'] = True
        app.config['APPLICATION_ROOT'] = '/api'
        application = DispatcherMiddleware(Flask('dummy_app'), {
            app.config['APPLICATION_ROOT']: app,
        })

        if listen_address is None:
            listen_address = saq.CONFIG.get('api', 'listen_address')
        if listen_port is None:
            listen_port = saq.CONFIG.getint('api', 'listen_port')
        ssl_context = (
            saq.CONFIG.get('api', 'ssl_cert') if ssl_cert is None else ssl_cert,
            saq.CONFIG.get('api', 'ssl_key') if ssl_key is None else ssl_key )

        initialize_database()
        saq.db = api.db.session

        logging.info(f"starting api server on {listen_address} port {listen_port}")
        run_simple(listen_address, listen_port, application, ssl_context=ssl_context, use_reloader=False) 
开发者ID:IntegralDefense,项目名称:ACE,代码行数:34,代码来源:test.py

示例7: app

# 需要导入模块: import api [as 别名]
# 或者: from api import create_app [as 别名]
def app():
    APP_CONFIG.update({'TESTING': True})
    app = create_app(APP_CONFIG)
    yield app 
开发者ID:aalises,项目名称:age-of-empires-II-api,代码行数:6,代码来源:conftest.py

示例8: setUp

# 需要导入模块: import api [as 别名]
# 或者: from api import create_app [as 别名]
def setUp(self):
        self.app = create_app(environment="Testing") 
开发者ID:xmm,项目名称:flask-restful-example,代码行数:4,代码来源:test_api_v2.py

示例9: run

# 需要导入模块: import api [as 别名]
# 或者: from api import create_app [as 别名]
def run():
    """Run the stat caching daemon."""
    with api.create_app().app_context():

        def cache(f, *args, **kwargs):
            result = f(reset_cache=True, *args, **kwargs)
            return result

        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect(("8.8.8.8", 80))
        host = s.getsockname()[0]
        s.close()

        _cache = api.cache.get_cache()
        active_stat_host = _cache.get("active_stat_host")
        if active_stat_host is not None and host != active_stat_host:
            print("Another ctf-stats is primary, exiting...")
            raise SystemExit
        else:
            _cache.set("active_stat_host", host, COOLDOWN_TIME)

        print("Caching registration stats...")
        cache(get_registration_count)

        print("Caching the scoreboards...")
        for scoreboard in api.scoreboards.get_all_scoreboards():
            get_all_team_scores(scoreboard_id=scoreboard["sid"])

        print("Caching the score progressions for each scoreboard...")
        for scoreboard in api.scoreboards.get_all_scoreboards():
            cache(
                get_top_teams_score_progressions,
                limit=5,
                scoreboard_id=scoreboard["sid"],
            )

        print("Caching the scores and score progressions for each group...")
        for group in api.group.get_all_groups():
            get_group_scores(gid=group["gid"])
            cache(get_top_teams_score_progressions, limit=5, group_id=group["gid"])

        print("Caching number of solves for each problem...")
        for problem in api.problem.get_all_problems():
            print(problem["name"], cache(get_problem_solves, problem["pid"])) 
开发者ID:picoCTF,项目名称:picoCTF,代码行数:46,代码来源:cache_stats.py


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