Coverage for lst_auto_rta/Server_RTA.py: 0%

21 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-17 14:47 +0000

1#!/usr/bin/env python 

2 

3import argparse 

4import os 

5from http.server import BaseHTTPRequestHandler, HTTPServer 

6from io import BytesIO 

7 

8parser = argparse.ArgumentParser() 

9parser.add_argument("path", type=str, help="path of the file to show") 

10args = parser.parse_args() 

11 

12 

13class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): 

14 def do_GET(self): 

15 try: 

16 self.path = args.path 

17 # ~ elif self.path == '/image2': 

18 # ~ self.path = '/images/example2.jpg' 

19 image = open(self.path, "rb").read() 

20 self.send_response(200) 

21 self.send_header("Content-type", "image/jpg") 

22 self.send_header("Content-length", len(image)) 

23 self.end_headers() 

24 self.wfile.write(BytesIO(image).getvalue()) 

25 except: 

26 self.send_error(404, "File Not Found: %s" % self.path) 

27 

28 

29httpd = HTTPServer(("0.0.0.0", 38100), SimpleHTTPRequestHandler) 

30httpd.serve_forever()