mypy type fixes

This commit is contained in:
Michael Lazar 2019-09-23 19:34:38 -04:00
parent 57e1bbee62
commit a2c4a1a28a
1 changed files with 19 additions and 14 deletions

View File

@ -341,19 +341,21 @@ class GeminiRequestHandler:
TIMESTAMP_FORMAT = "%d/%b/%Y:%H:%M:%S %z" TIMESTAMP_FORMAT = "%d/%b/%Y:%H:%M:%S %z"
reader: asyncio.StreamReader
writer: asyncio.StreamWriter
received_timestamp: time.struct_time
remote_addr: str
client_crt: dict
url: str
status: int
meta: str
response_buffer: str
response_size: int
def __init__(self, server: GeminiServer, app: typing.Callable) -> None: def __init__(self, server: GeminiServer, app: typing.Callable) -> None:
self.server = server self.server = server
self.app = app self.app = app
self.reader: typing.Optional[asyncio.StreamReader] = None self.response_size = 0
self.writer: typing.Optional[asyncio.StreamWriter] = None
self.received_timestamp: typing.Optional[time.struct_time] = None
self.remote_addr: typing.Optional[str] = None
self.client_cert: typing.Optional[dict] = None
self.url: typing.Optional[urllib.parse.ParseResult] = None
self.status: typing.Optional[int] = None
self.meta: typing.Optional[str] = None
self.response_buffer: typing.Optional[str] = None
self.response_size: int = 0
async def handle( async def handle(
self, reader: asyncio.StreamReader, writer: asyncio.StreamWriter self, reader: asyncio.StreamReader, writer: asyncio.StreamWriter
@ -467,7 +469,7 @@ class GeminiRequestHandler:
self.response_size += len(data) self.response_size += len(data)
self.writer.write(data) self.writer.write(data)
await self.writer.drain() await self.writer.drain()
self.response_buffer = None self.response_buffer = ""
async def close_connection(self) -> None: async def close_connection(self) -> None:
""" """
@ -522,9 +524,12 @@ class GeminiServer:
self.accept_connection, self.host, self.port, ssl=self.ssl_context self.accept_connection, self.host, self.port, ssl=self.ssl_context
) )
socket_info = server.sockets[0].getsockname() if server.sockets:
socket_host, socket_port = server.sockets[0].getsockname()
else:
socket_host, socket_port = None, None
self.log_message(f"Server hostname is {self.hostname}") self.log_message(f"Server hostname is {self.hostname}")
self.log_message(f"Listening on {socket_info[0]}:{socket_info[1]}") self.log_message(f"Listening on {socket_host}:{socket_port}")
async with server: async with server:
await server.serve_forever() await server.serve_forever()