Python api 模块,app() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用api.app()

项目:picoCTF    作者:picoCTF    | 项目源码 | 文件源码
def main():
    """
    Runtime management of the CTF API
    """

    parser = ArgumentParser(description="CTF API configuration")

    parser.add_argument("-v", "--verbose", action="count", help="increase verbosity", default=0)

    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.problem.DEBUG_KEY = args.debug_key

    keyword_args, _ = object_from_args(args)

    api.app.config_app().run(host=args.listen, port=args.port, debug=args.debug)
项目:picoCTF    作者:royragsdale    | 项目源码 | 文件源码
def main():
    """
    Runtime management of the CTF API
    """

    parser = ArgumentParser(description="CTF API configuration")

    parser.add_argument("-v", "--verbose", action="count", help="increase verbosity", default=0)

    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.problem.DEBUG_KEY = args.debug_key

    keyword_args, _ = object_from_args(args)

    api.app.config_app().run(host=args.listen, port=args.port, debug=args.debug)
项目:xgovctf    作者:alphagov    | 项目源码 | 文件源码
def main():
    """
    Runtime management of the picoCTF API
    """

    parser = ArgumentParser(description="picoCTF API configuration")

    parser.add_argument("-v", "--verbose", action="count", help="increase verbosity", default=0)

    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)

    args = parser.parse_args()

    keyword_args, _ = object_from_args(args)

    api.app.config_app().run(host=args.listen, port=args.port, debug=args.debug)
项目:dpla-service-hub    作者:KnowledgeLinks    | 项目源码 | 文件源码
def list_routes():
    import urllib.parse
    output = []
    for rule in app.url_map.iter_rules():
        options = {}
        for arg in rule.arguments:
            options[arg] = "[{0}]".format(arg)
        methods = ",".join(rule.methods)
        url = url_for(rule.endpoint, **options)
        line = urllib.parse.unquote("{:50s} {:20s} {}".format(
            rule.endpoint,
            methods,
            url))
        output.append(line)
    for line in sorted(output):
        print(line)
项目:stratego.io    作者:benletchford    | 项目源码 | 文件源码
def test_should_be_able_to_join_game(self, pusher):
        app.post('/api/create', params={'board': json.dumps(FIXTURES.SETUP)})

        game = models.Game.query().get()

        app.post('/api/join', params={
            'board': json.dumps(FIXTURES.SETUP),
            'join_hash': game.join_hash
        })

        game = models.Game.query().get()

        current_state_of_game = copy.deepcopy(FIXTURES.DEFAULT_GAME)

        self.assertEqual(game.get_board(), current_state_of_game)
项目:stratego.io    作者:benletchford    | 项目源码 | 文件源码
def test_should_be_able_to_move(self, pusher):
        app.post('/api/create', params={'board': json.dumps(FIXTURES.SETUP)})

        game = models.Game.query().get()

        app.post('/api/join', params={
            'board': json.dumps(FIXTURES.SETUP),
            'join_hash': game.join_hash
        })

        app.post('/api/move', params={
            'player_hash': game.red_hash,
            'side': 0,
            'from': json.dumps({'x': 5, 'y': 6}),
            'to': json.dumps({'x': 5, 'y': 5})
        })

        game = models.Game.query().get()

        current_state_of_game = copy.deepcopy(FIXTURES.DEFAULT_GAME)

        current_state_of_game[5][5] = {'side': 0, 'rank': '4'}
        current_state_of_game[6][5] = 0

        self.assertEqual(game.get_board(), current_state_of_game)

        # Blue's turn
        self.assertEqual(game.turn, 1)
项目:stratego.io    作者:benletchford    | 项目源码 | 文件源码
def test_should_be_able_to_attack_and_draw(self, pusher):
        app.post('/api/create', params={'board': json.dumps(FIXTURES.SETUP)})

        game = models.Game.query().get()

        app.post('/api/join', params={
            'board': json.dumps(FIXTURES.SETUP),
            'join_hash': game.join_hash
        })

        app.post('/api/move', params={
            'player_hash': game.red_hash,
            'side': 0,
            'from': json.dumps({'x': 5, 'y': 6}),
            'to': json.dumps({'x': 5, 'y': 5})
        })

        app.post('/api/move', params={
            'player_hash': game.blue_hash,
            'side': 1,
            'from': json.dumps({'x': 4, 'y': 6}),
            'to': json.dumps({'x': 4, 'y': 5})
        })

        app.post('/api/move', params={
            'player_hash': game.red_hash,
            'side': 0,
            'from': json.dumps({'x': 5, 'y': 5}),
            'to': json.dumps({'x': 5, 'y': 4})
        })

        game = models.Game.query().get()

        current_state_of_game = copy.deepcopy(FIXTURES.DEFAULT_GAME)

        # These pieces should have been destroyed
        current_state_of_game[3][5] = 0
        current_state_of_game[6][5] = 0

        self.assertEqual(game.get_board(), current_state_of_game)

        self.assertEqual(game.get_last_move(), {
            'type': 'draw',
            'from': {
                'piece': {'side': 0, 'rank': '4'},
                'position': {'x': 5, 'y': 5}
            },
            'to': {
                'piece': {'side': 1, 'rank': '4'},
                'position': {'x': 5, 'y': 4}
            }
        })

        # Blue's turn
        self.assertEqual(game.turn, 1)