import os import shutil from functools import partial from http.server import HTTPServer, SimpleHTTPRequestHandler from pathlib import Path def read_file(file_path): with open(file_path, 'r') as f: file_content = f.read() return file_content def write_file(file_path, content): with open(file_path, 'w') as f: f.write(content) def copy_file(src, dst): os.makedirs(os.path.dirname(dst), exist_ok=True) shutil.copy2(src, dst) # Функция для запуска веб-сервера def start_httpd(directory: Path, port: int = 8000, interface: str = 'localhost'): print(f"Listen on http://{interface}:{port}, serving from '{directory}' directory...") handler = partial(SimpleHTTPRequestHandler, directory=directory) httpd = HTTPServer((interface, port), handler) httpd.serve_forever()