2 from http.server
import HTTPServer, BaseHTTPRequestHandler
6 class Serv(BaseHTTPRequestHandler):
10 self.
path =
'/index.html' 12 if self.
path ==
'/modules_data.json':
13 self.
path =
'/modules_data.json' 16 file_path = self.
path[1:]
19 with open(file_path,
'rb')
as file:
20 file_to_open = file.read()
23 mime_type, _ = mimetypes.guess_type(file_path)
26 self.send_response(200)
28 self.send_header(
"Content-type", mime_type)
32 self.wfile.
write(file_to_open)
34 except FileNotFoundError:
36 self.send_response(404)
37 self.send_header(
"Content-type",
"text/html")
39 self.wfile.
write(bytes(
"File not found",
'utf-8'))
41 except Exception
as e:
43 self.send_response(500)
44 self.send_header(
"Content-type",
"text/html")
46 self.wfile.
write(bytes(f
"Internal server error: {str(e)}",
'utf-8'))
48 def run(server_class=HTTPServer, handler_class=Serv, port=65432):
50 server_address = (
'localhost', port)
51 httpd = server_class(server_address, handler_class)
52 print(f
"Server started at http://localhost:{port}")
55 if __name__ ==
"__main__":
57 parser = argparse.ArgumentParser(description=
'Start a simple HTTP server.')
58 parser.add_argument(
'--port', type=int, default=65432, help=
'Port to serve on (default: 65432)')
59 args = parser.parse_args()
def run(server_class=HTTPServer, handler_class=Serv, port=65432)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)