當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。