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


Python web.AppRunner方法代码示例

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


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

示例1: start

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import AppRunner [as 别名]
def start(self):
        app = web.Application(client_max_size=JSON_RPC_CLIENT_REQUEST_MAX_SIZE)
        cors = aiohttp_cors.setup(app)
        route = app.router.add_post("/", self.__handle)
        cors.add(
            route,
            {
                "*": aiohttp_cors.ResourceOptions(
                    allow_credentials=True,
                    expose_headers=("X-Custom-Server-Header",),
                    allow_methods=["POST", "PUT"],
                    allow_headers=("X-Requested-With", "Content-Type"),
                )
            },
        )
        self.runner = web.AppRunner(app, access_log=None)
        self.loop.run_until_complete(self.runner.setup())
        site = web.TCPSite(self.runner, self.host, self.port)
        self.loop.run_until_complete(site.start()) 
开发者ID:QuarkChain,项目名称:pyquarkchain,代码行数:21,代码来源:jsonrpc.py

示例2: start

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import AppRunner [as 别名]
def start(self) -> None:
        """
        Start this transport.

        Raises:
            InboundTransportSetupError: If there was an error starting the webserver

        """
        app = await self.make_application()
        runner = web.AppRunner(app)
        await runner.setup()
        self.site = web.TCPSite(runner, host=self.host, port=self.port)
        try:
            await self.site.start()
        except OSError:
            raise InboundTransportSetupError(
                "Unable to start websocket server with host "
                + f"'{self.host}' and port '{self.port}'\n"
            ) 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:21,代码来源:ws.py

示例3: start

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import AppRunner [as 别名]
def start(self) -> None:
        """
        Start this transport.

        Raises:
            InboundTransportSetupError: If there was an error starting the webserver

        """
        app = await self.make_application()
        runner = web.AppRunner(app)
        await runner.setup()
        self.site = web.TCPSite(runner, host=self.host, port=self.port)
        try:
            await self.site.start()
        except OSError:
            raise InboundTransportSetupError(
                "Unable to start webserver with host "
                + f"'{self.host}' and port '{self.port}'\n"
            ) 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:21,代码来源:http.py

示例4: http_endpoint

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import AppRunner [as 别名]
def http_endpoint(config, suite):
    """Create http server task."""

    async def handle(request):
        """aiohttp handle POST."""
        response = []
        with suite.reply(response.append):
            await suite.handle(await request.read())

        if response:
            return web.Response(body=response.pop())

        raise web.HTTPAccepted()

    app = web.Application()
    app.router.add_post('/', handle)
    runner = web.AppRunner(app)
    await runner.setup()
    site = web.TCPSite(runner, config['host'], config['port'])
    server_task = asyncio.ensure_future(site.start())
    yield
    server_task.cancel()
    with suppress(asyncio.CancelledError):
        await server_task
    await runner.cleanup() 
开发者ID:hyperledger,项目名称:aries-protocol-test-suite,代码行数:27,代码来源:conftest.py

示例5: run_server

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import AppRunner [as 别名]
def run_server():
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)

    app = web.Application(debug=False)
    app.add_routes([web.get('/', say_hello)])
    app.add_routes([web.get('/401', four_hundred_one)])
    app.add_routes([web.get('/500', five_hundred)])
    app.add_routes([web.get('/exception', raise_exception)])

    runner = web.AppRunner(app)
    loop.run_until_complete(runner.setup())
    site = web.TCPSite(runner, '127.0.0.1', testenv["aiohttp_port"])

    loop.run_until_complete(site.start())
    loop.run_forever() 
开发者ID:instana,项目名称:python-sensor,代码行数:18,代码来源:app_aiohttp.py

示例6: start_site

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import AppRunner [as 别名]
def start_site(self, app, address='localhost', port=8080, usessl=False):
        runner = web.AppRunner(app)
        self.runners.append(runner)
        await runner.setup()
        if usessl:
            ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
            ssl_ctx.load_cert_chain(bumper.server_cert, bumper.server_key)
            site = web.TCPSite(
                runner,
                host=address,
                port=port,
                ssl_context=ssl_ctx,
            )

        else:
            site = web.TCPSite(
                runner, host=address, port=port
            )

        await site.start() 
开发者ID:bmartin5692,项目名称:bumper,代码行数:22,代码来源:confserver.py

示例7: start

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import AppRunner [as 别名]
def start(self):
        app = web.Application()
        app.add_routes([web.route('*', '/{tail:.*}', self.handle_request)])
        aiohttp_jinja2.setup(
            app, loader=jinja2.FileSystemLoader(self.dir)
        )
        middleware = SnareMiddleware(
            error_404=self.meta['/status_404'].get('hash'),
            headers=self.meta['/status_404'].get('headers', []),
            server_header=self.run_args.server_header
        )
        middleware.setup_middlewares(app)

        self.runner = web.AppRunner(app)
        await self.runner.setup()
        site = web.TCPSite(
            self.runner,
            self.run_args.host_ip,
            self.run_args.port)

        await site.start()
        names = sorted(str(s.name) for s in self.runner.sites)
        print("======== Running on {} ========\n"
              "(Press CTRL+C to quit)".format(', '.join(names))) 
开发者ID:mushorg,项目名称:snare,代码行数:26,代码来源:server.py

示例8: start

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import AppRunner [as 别名]
def start(self, host: str = "127.0.0.1", port: int = 8080) -> None:
        connector = None
        self.log.debug(f"Starting appservice web server on {host}:{port}")
        if self.server.startswith("https://") and not self.verify_ssl:
            connector = aiohttp.TCPConnector(verify_ssl=False)
        self._http_session = aiohttp.ClientSession(loop=self.loop, connector=connector)
        self._intent = AppServiceAPI(base_url=self.server, bot_mxid=self.bot_mxid, log=self.log,
                                     token=self.as_token, state_store=self.state_store,
                                     real_user_content_key=self.real_user_content_key,
                                     client_session=self._http_session).bot_intent()
        ssl_ctx = None
        if self.tls_cert and self.tls_key:
            ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
            ssl_ctx.load_cert_chain(self.tls_cert, self.tls_key)
        self.runner = web.AppRunner(self.app)
        await self.runner.setup()
        site = web.TCPSite(self.runner, host, port, ssl_context=ssl_ctx)
        await site.start() 
开发者ID:tulir,项目名称:mautrix-python,代码行数:20,代码来源:appservice.py

示例9: webhook

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import AppRunner [as 别名]
def webhook(self):
        async def vote_handler(request):
            req_auth = request.headers.get('Authorization')
            if self.webhook_auth == req_auth:
                data = await request.json()
                if data.get('type') == 'upvote':
                    event_name = 'dbl_vote'
                elif data.get('type') == 'test':
                    event_name = 'dbl_test'
                self.bot.dispatch(event_name, data)
                return web.Response()
            else:
                return web.Response(status=401)

        app = web.Application(loop=self.loop)
        app.router.add_post(self.webhook_path, vote_handler)
        runner = web.AppRunner(app)
        await runner.setup()
        self._webserver = web.TCPSite(runner, '0.0.0.0', self.webhook_port)
        await self._webserver.start() 
开发者ID:DiscordBotList,项目名称:DBL-Python-Library,代码行数:22,代码来源:client.py

示例10: __init__

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import AppRunner [as 别名]
def __init__(self, config, session_manager: ClientSessionManager, loop, **kwargs):
        """Initialize a new instance."""
        super().__init__(session_manager, config.get_service(Protocol.DMAP))
        self._loop = loop
        self._zeroconf = kwargs.get(
            "zeroconf", Zeroconf(loop, address_family=[netifaces.AF_INET])
        )
        self._name = kwargs.get("name", "pyatv")
        self.app = web.Application()
        self.app.router.add_routes([web.get("/pairing", self.handle_request)])
        self.runner = web.AppRunner(self.app)
        self.site = None
        self._pin_code = None
        self._has_paired = False
        self._pairing_guid = (
            kwargs.get("pairing_guid", None) or _generate_random_guid()
        )[2:].upper() 
开发者ID:postlund,项目名称:pyatv,代码行数:19,代码来源:pairing.py

示例11: listening_endpoint

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import AppRunner [as 别名]
def listening_endpoint(connection, unused_tcp_port):
    """Create http server task."""

    async def handle(request):
        """aiohttp handle POST."""
        await connection.handle(await request.read())
        raise web.HTTPAccepted()

    app = web.Application()
    app.router.add_post('/', handle)
    runner = web.AppRunner(app)
    await runner.setup()
    site = web.TCPSite(runner, 'localhost', unused_tcp_port)
    server_task = asyncio.ensure_future(site.start())
    yield 'http://localhost:{}'.format(unused_tcp_port)
    server_task.cancel()
    with suppress(asyncio.CancelledError):
        await server_task
    await runner.cleanup() 
开发者ID:hyperledger,项目名称:aries-staticagent-python,代码行数:21,代码来源:test_examples.py

示例12: test_startup_initializes_an_web_application

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import AppRunner [as 别名]
def test_startup_initializes_an_web_application(self, start):
        self.app.routes_registry = self.routes_registry

        await self.signal_handler.startup(self.app)

        self.assertIsInstance(self.app[RouteTypes.HTTP]["app"], web.Application)
        self.assertIsInstance(
            self.app[RouteTypes.HTTP]["runner"], web.AppRunner
        )
        site: web.TCPSite = self.app[RouteTypes.HTTP]["site"]
        self.assertIsInstance(site, web.TCPSite)

        self.assertEqual(site._port, settings.HTTP_PORT)
        self.assertEqual(site._host, settings.HTTP_HOST)

        start.assert_awaited_once() 
开发者ID:b2wdigital,项目名称:async-worker,代码行数:18,代码来源:test_http.py

示例13: start

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import AppRunner [as 别名]
def start(self):
        self.runner = web.AppRunner(self.app)
        await self.runner.setup()
        self.port = os.environ.get("PORT", 8080)
        site = web.TCPSite(self.runner, None, self.port)
        await site.start()
        self.running.set() 
开发者ID:friendly-telegram,项目名称:friendly-telegram,代码行数:9,代码来源:core.py

示例14: __init__

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import AppRunner [as 别名]
def __init__(self, management_api: web.Application, config: Config,
                 loop: asyncio.AbstractEventLoop) -> None:
        self.loop = loop or asyncio.get_event_loop()
        self.app = web.Application(loop=self.loop, client_max_size=100 * 1024 * 1024)
        self.config = config

        self.setup_appservice()
        self.app.add_subapp(config["server.base_path"], management_api)
        self.setup_instance_subapps()
        self.setup_management_ui()

        self.runner = web.AppRunner(self.app, access_log_class=AccessLogger) 
开发者ID:maubot,项目名称:maubot,代码行数:14,代码来源:server.py

示例15: run

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import AppRunner [as 别名]
def run(self):
        print("> Fake Server:",self.root)

        async def start():
            runner = web.AppRunner(self.app)
            await runner.setup()
            self.site=web.TCPSite(runner, 'localhost', self.port)
            await self.site.start()
        
            while self._exit==False:
                await asyncio.sleep(0.333333)

            await self.site.stop()
            await runner.shutdown()

        asyncio.set_event_loop(asyncio.new_event_loop())
        loop=asyncio.get_event_loop()


        async def wait():
            while not isFree("127.0.0.1",self.port):
                await asyncio.sleep(0.5)

        loop.run_until_complete(wait()) 
        loop.run_until_complete(start())       
        loop.run_until_complete(wait()) 

        # gracefull death
        tasks = asyncio.all_tasks(loop) #py37
        for task in tasks: task.cancel()
        try:
            loop.run_until_complete(asyncio.gather(*tasks))
        except:
            pass
        loop.close() 
开发者ID:manatlan,项目名称:reqman,代码行数:37,代码来源:fakereqman.py


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