Browse Source

Simplify imports

master
Forest Belton 3 years ago
parent
commit
b407718223
1 changed files with 11 additions and 15 deletions
  1. +11
    -15
      paircd/main.py

+ 11
- 15
paircd/main.py View File

@ -1,18 +1,14 @@
import asyncio
from asyncio import create_task, run, start_server
from asyncio.streams import StreamReader, StreamWriter
import logging
import os
from logging import basicConfig, info, INFO
from os import getenv
from paircd.client import Client
from paircd.handlers import handle_cmd, register_cmd_handlers
from paircd.message import parse_message
from paircd.server import Server
logging.basicConfig(
format="%(asctime)s [%(levelname)s] - %(message)s", level=logging.INFO
)
logger = logging.getLogger()
basicConfig(format="%(asctime)s [%(levelname)s] - %(message)s", level=INFO)
async def read_forever(server: Server, client: Client) -> None:
@ -23,8 +19,8 @@ async def read_forever(server: Server, client: Client) -> None:
async def serve() -> None:
bind_addr = os.getenv("BIND_ADDR") or "0.0.0.0"
port = os.getenv("PORT") or 6667
bind_addr = getenv("BIND_ADDR") or "0.0.0.0"
port = getenv("PORT") or 6667
irc_server = Server()
register_cmd_handlers()
@ -35,23 +31,23 @@ async def serve() -> None:
reader=reader,
writer=writer,
)
asyncio.create_task(read_forever(irc_server, client))
asyncio.create_task(client.write_forever())
create_task(read_forever(irc_server, client))
create_task(client.write_forever())
server = await asyncio.start_server(
server = await start_server(
register_client,
bind_addr,
port,
reuse_port=True,
)
logger.info(f"Listening on {bind_addr}:{port}")
info(f"Listening on {bind_addr}:{port}")
async with server:
await server.serve_forever()
def main() -> None:
asyncio.run(serve())
run(serve())
if __name__ == "__main__":

Loading…
Cancel
Save