CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
server.Serv Class Reference
Inheritance diagram for server.Serv:

Public Member Functions

def do_GET (self)
 

Public Attributes

 path
 

Detailed Description

Definition at line 6 of file server.py.

Member Function Documentation

◆ do_GET()

def server.Serv.do_GET (   self)

Definition at line 7 of file server.py.

7  def do_GET(self):
8  # Default route to serve the index.html file
9  if self.path == '/':
10  self.path = '/index.html'
11  # Serve the uploaded JavaScript file if requested
12  if self.path == '/modules_data.json':
13  self.path = '/modules_data.json'
14 
15  try:
16  file_path = self.path[1:] # Remove leading '/' to get the file path
17 
18  # Read the requested file
19  with open(file_path, 'rb') as file:
20  file_to_open = file.read()
21 
22  # MIME type of the file
23  mime_type, _ = mimetypes.guess_type(file_path)
24 
25  # Send the HTTP response
26  self.send_response(200)
27  if mime_type:
28  self.send_header("Content-type", mime_type)
29  self.end_headers()
30 
31  # Write the file content to the response
32  self.wfile.write(file_to_open)
33 
34  except FileNotFoundError:
35  # Handle file not found error
36  self.send_response(404)
37  self.send_header("Content-type", "text/html")
38  self.end_headers()
39  self.wfile.write(bytes("File not found", 'utf-8'))
40 
41  except Exception as e:
42  # Handle any other internal server errors
43  self.send_response(500)
44  self.send_header("Content-type", "text/html")
45  self.end_headers()
46  self.wfile.write(bytes(f"Internal server error: {str(e)}", 'utf-8'))
47 

Member Data Documentation

◆ path

server.Serv.path

Definition at line 9 of file server.py.

Referenced by python.rootplot.rootmath.Target.__repr__().