52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from abc import ABC, abstractmethod
|
|
from typing import Any, Self, Optional, Sequence
|
|
from Interfaces.Application.AnPInterface import AnPInterface
|
|
from Utils.Common import Common
|
|
|
|
class HTTPServersAbstract(ABC):
|
|
|
|
DEFAULT_PORT:int = 8000
|
|
DEFAULT_HOST:str = ""
|
|
|
|
def __init__(self:Self, anp:AnPInterface, inputs:Optional[dict[str, Any|None]|Sequence[Any|None]] = None) -> None:
|
|
self.anp:AnPInterface = anp
|
|
self.__inputs:dict[str, Any|None] = Common.get_dictionary(inputs)
|
|
self.host:str = self.DEFAULT_PORT
|
|
self.port:int = self.DEFAULT_HOST
|
|
self._print_data:dict[str, Any|None] = {
|
|
"port": self.port,
|
|
"host": self.host
|
|
}
|
|
|
|
self.update()
|
|
|
|
def __update_print_data(self:Self) -> None:
|
|
self._print_data["port"] = self.port
|
|
self._print_data["host"] = self.host
|
|
|
|
@abstractmethod
|
|
def start(self:Self) -> None:pass
|
|
|
|
@abstractmethod
|
|
def close(self:Self) -> None:pass
|
|
|
|
def update(self:Self) -> None:
|
|
|
|
self.close()
|
|
|
|
self.port = self.anp.settings.get(("http_server_port", "http_port", "port"), self.__inputs, self.DEFAULT_PORT)
|
|
self.host = self.anp.settings.get(("http_server_host", "http_host", "host"), self.__inputs, self.DEFAULT_HOST)
|
|
self.__update_print_data()
|
|
|
|
self.anp.settings.get(("http_server_autostart", "http_autostart", "autostart")) and self.start()
|
|
|
|
def reset(self:Self) -> None:
|
|
|
|
self.port = self.DEFAULT_PORT
|
|
self.host = self.DEFAULT_HOST
|
|
self.__update_print_data()
|
|
|
|
self.update() |