MCPcopy Create free account
hub / github.com/ndleah/python-mini-project / get_content

Function get_content

Simple_Http_Server/mhttp.py:11–27  ·  view source on GitHub ↗
(path)

Source from the content-addressed store, hash-verified

9FOLDER = '.' if len(sys.argv) < 2 else sys.argv[1]
10
11def get_content(path):
12 ext = "html"
13 if path == "/":
14 try:
15 with open(FOLDER + "/index.html", "r") as f:
16 content = f.read()
17 except FileNotFoundError:
18 content = "The Server is working! but there is no index.html file to render"
19 else:
20 try:
21 with open(FOLDER + path, "r") as f:
22 if Path(FOLDER + path).suffix != ".html":
23 ext = "plain"
24 content = f.read()
25 except FileNotFoundError:
26 return 404, "File not found", ext
27 return 200, content, ext
28
29with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
30 try:

Callers 1

mhttp.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected