How to use the aiohttp.web.TCPSite function in aiohttp

To help you get started, we’ve selected a few aiohttp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FAForever / server / tests / unit_tests / test_geoip_service.py View on Github external
if request.rel_url.query.get("suffix").endswith("md5"):
            return web.Response(text=checksum)

        # Fake database
        resp = web.StreamResponse()
        await resp.prepare(request)
        await resp.write(tarred_text)
        await resp.write_eof()
        return resp

    app = web.Application()
    app.add_routes([web.get('/', file_download)])

    runner = web.AppRunner(app)
    await runner.setup()
    await web.TCPSite(runner, 'localhost', PORT).start()

    # Test geoip update
    if os.path.isfile(fake_geoip_path):
        os.remove(fake_geoip_path)
    # Need to call it like this because the function is mocked
    await GeoIpService.download_geoip_db(fake_geoip_service)
    assert os.path.isfile(fake_geoip_path) is True
    with open(fake_geoip_path) as f:
        assert f.read() == random_text

    await runner.cleanup()
github aio-libs / aiohttp-sse / tests / test_sse.py View on Github external
async def make_runner(app, host, port):
    runner = web.AppRunner(app)
    await runner.setup()
    site = web.TCPSite(runner, host, port)
    await site.start()
    return runner
github FAForever / server / tests / integration_tests / test_oauth_session.py View on Github external
async def start_app():
        await runner.setup()
        site = web.TCPSite(runner, host, port)
        await site.start()
github aio-libs / aiohttp-devtools / aiohttp_devtools / runserver / serve.py View on Github external
async def start_main_app(config: Config, app_factory, loop):
    app = await config.load_app(app_factory)

    modify_main_app(app, config)

    await check_port_open(config.main_port, loop)
    runner = web.AppRunner(app, access_log_class=AccessLogger)
    await runner.setup()
    site = web.TCPSite(runner, host=HOST, port=config.main_port, shutdown_timeout=0.1)
    await site.start()
    return runner
github intel / dffml / service / http / dffml_service_http / cli.py View on Github external
async def start(self):
        if self.insecure:
            self.site = web.TCPSite(
                self.runner, host=self.addr, port=self.port
            )
        else:
            ssl_context = ssl.create_default_context(
                purpose=ssl.Purpose.SERVER_AUTH, cafile=self.cert
            )
            ssl_context.load_cert_chain(self.cert, self.key)
            self.site = web.TCPSite(
                self.runner,
                host=self.addr,
                port=self.port,
                ssl_context=ssl_context,
            )
        await self.site.start()
        self.logger.info(f"Serving on {self.addr}:{self.port}")
github koursaros-ai / nboost / neural_rerank / base / server.py View on Github external
async def create_site():
            app = web.Application(middlewares=[self.middleware])
            app.add_routes(routes)
            runner = web.AppRunner(app)
            await runner.setup()
            site = web.TCPSite(runner, self.host, self.port)
            await site.start()
            self.logger.critical('LISTENING: %s:%d' % (self.host, self.port))
            self.logger.critical('ROUTES: %s' % self.handler.routes)
            self.is_ready.set()
github gearbot / GearBot / GearBot / Cogs / PromMonitoring.py View on Github external
async def create_site(self):
        await asyncio.sleep(15)
        metrics_app = web.Application()
        metrics_app.add_routes([web.get("/metrics", self.serve_metrics)])

        runner = web.AppRunner(metrics_app)
        await self.bot.loop.create_task(runner.setup())
        site = web.TCPSite(runner, 'localhost', 8090 + self.bot.cluster)
        await site.start()

        self.metric_server = site
github gdassori / spruned / spruned / application / jsonrpc_server.py View on Github external
methods.add(self.getrawtransaction)
        methods.add(self.gettxout)
        methods.add(self.getpeerinfo)
        methods.add(self.sendrawtransaction)
        methods.add(self.stop)
        methods.add(self.getmempoolinfo)
        methods.add(self.getchaintxstats)
        methods.add(self.getmininginfo)
        methods.add(self.getrawmempool)
        methods.add(self.getnetworkinfo)
        methods.add(self.uptime)
        methods.add(self.getnettotals)
        methods.add(self.validateaddress)
        methods.add(self.dev_memorysummary, name="dev-gc-stats")
        methods.add(self.dev_collect, name="dev-gc-collect")
        return await web.TCPSite(runner, host=self.host, port=self.port).start()
github Magic-Bots / xenon / xenon / cogs / api.py View on Github external
async def start_app(self):
        await self.runner.setup()
        site = web.TCPSite(self.runner, port=9090)
        await site.start()
github mushorg / snare / snare / server.py View on Github external
async 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(
            self.meta['/status_404']['hash'],
            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)))