35 lines
1.7 KiB
Python
35 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from typing import Self, Any, Optional, Sequence
|
|
from abc import ABC, abstractmethod
|
|
from Interfaces.Application.NucelarMonitorInterface import NucelarMonitorInterface
|
|
|
|
class WebServerAbstract(ABC):
|
|
|
|
def __init__(self:Self,
|
|
nucelar_monitor:NucelarMonitorInterface,
|
|
inputs:Optional[dict[str, Any|None]|Sequence[Any|None]] = None
|
|
) -> None:
|
|
self.nucelar_monitor:NucelarMonitorInterface = nucelar_monitor
|
|
|
|
index_files:Sequence[str]|str = self.nucelar_monitor.settings.get("index_files", inputs, ["index.html", "index.htm"])
|
|
header_response:str|Sequence[str] = self.nucelar_monitor.settings.get("header_response", inputs, "HTTP/{version} {code} {message}\r\n")
|
|
self._host:str = self.nucelar_monitor.settings.get("host", inputs, "::1")
|
|
self._port:int = self.nucelar_monitor.settings.get("port", inputs, 13000)
|
|
self._header_response:str = header_response if isinstance(header_response, str) else "\r\n".join(header_response) + "\r\n\r\n"
|
|
self._protocol:str = self.nucelar_monitor.settings.get("protocol", inputs, "HTTP")
|
|
self._version:str = self.nucelar_monitor.settings.get("version", inputs, "1.1")
|
|
self._code:int = self.nucelar_monitor.settings.get("code", inputs, 200)
|
|
self._message:str = self.nucelar_monitor.settings.get("message", inputs, "OK")
|
|
self._encoder:str = self.nucelar_monitor.settings.get("encoder", inputs, "utf-8")
|
|
self._index_files:list[str] = [""] + (index_files if isinstance(index_files, list) else [index_files])
|
|
|
|
@abstractmethod
|
|
def start(self:Self) -> bool:pass
|
|
|
|
@abstractmethod
|
|
def stop(self:Self) -> bool:pass
|
|
|
|
@abstractmethod
|
|
def close(self:Self) -> bool:pass |