Minor changes!
This commit is contained in:
parent
9bd7777457
commit
487f7cc0d7
21
http-server
21
http-server
@ -1,4 +1,4 @@
|
|||||||
#/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from http import server
|
from http import server
|
||||||
from urllib import parse
|
from urllib import parse
|
||||||
@ -15,16 +15,16 @@ class SimpleHandler(server.BaseHTTPRequestHandler):
|
|||||||
query_components = parse.parse_qsl(query)
|
query_components = parse.parse_qsl(query)
|
||||||
|
|
||||||
if path == "/":
|
if path == "/":
|
||||||
self.return_get_components(path, query, query_components)
|
msg = self.return_get_components(path, query, query_components)
|
||||||
elif path == "/ying":
|
elif path == "/ying":
|
||||||
self.return_ying()
|
msg = self.return_ying()
|
||||||
elif path == "/yang":
|
elif path == "/yang":
|
||||||
self.return_yang()
|
msg = self.return_yang()
|
||||||
elif path == "/squares":
|
elif path == "/squares":
|
||||||
self.return_squares(query_components)
|
msg = self.return_squares(query_components)
|
||||||
else:
|
else:
|
||||||
msg = "Error 404"
|
msg = "Error 404"
|
||||||
self.wfile.write(msg.encode('utf-8'))
|
self.wfile.write(msg.encode('utf-8'))
|
||||||
|
|
||||||
def return_squares(self, query_components):
|
def return_squares(self, query_components):
|
||||||
if len(query_components) != 2:
|
if len(query_components) != 2:
|
||||||
@ -44,21 +44,20 @@ class SimpleHandler(server.BaseHTTPRequestHandler):
|
|||||||
for i in range(von, bis+1):
|
for i in range(von, bis+1):
|
||||||
msg += f"<tr><td>{i}</td><td>{i**2}</td></tr>"
|
msg += f"<tr><td>{i}</td><td>{i**2}</td></tr>"
|
||||||
msg += "</table>"
|
msg += "</table>"
|
||||||
self.wfile.write(msg.encode('utf-8'))
|
return msg
|
||||||
|
|
||||||
|
|
||||||
def return_ying(self):
|
def return_ying(self):
|
||||||
msg = "<a href='/yang'>Ying</a>"
|
msg = "<a href='/yang'>Ying</a>"
|
||||||
self.wfile.write(msg.encode('utf-8'))
|
return msg
|
||||||
|
|
||||||
def return_yang(self):
|
def return_yang(self):
|
||||||
msg = "<a href='/ying'>Yang</a>"
|
msg = "<a href='/ying'>Yang</a>"
|
||||||
self.wfile.write(msg.encode('utf-8'))
|
return msg
|
||||||
|
|
||||||
def return_get_components(self, path, query, query_components):
|
def return_get_components(self, path, query, query_components):
|
||||||
msg = f"Path: {path}\nQuery: {query}\nComponents: {str(query_components)}"
|
msg = f"Path: {path}\nQuery: {query}\nComponents: {str(query_components)}"
|
||||||
|
return msg
|
||||||
self.wfile.write(msg.encode('utf-8'))
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
port = 60000
|
port = 60000
|
||||||
|
Loading…
x
Reference in New Issue
Block a user