|
|
|
|
|
|
|
|
#/usr/bin/env python3 |
|
|
|
|
|
|
|
|
#!/usr/bin/env python3 |
|
|
|
|
|
|
|
|
from http import server |
|
|
from http import server |
|
|
from urllib import parse |
|
|
from urllib import parse |
|
|
|
|
|
|
|
|
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: |
|
|
|
|
|
|
|
|
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)}" |
|
|
|
|
|
|
|
|
self.wfile.write(msg.encode('utf-8')) |
|
|
|
|
|
|
|
|
return msg |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
if __name__ == "__main__": |
|
|
port = 60000 |
|
|
port = 60000 |