#!/usr/bin/env python3 from http import server from urllib import parse class SimpleHandler(server.BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.end_headers() parsed = parse.urlparse(self.path) path = parsed.path query = parsed.query query_components = parse.parse_qsl(query) if path == "/": msg = self.return_get_components(path, query, query_components) elif path == "/ying": msg = self.return_ying() elif path == "/yang": msg = self.return_yang() elif path == "/squares": msg = self.return_squares(query_components) else: msg = "Error 404" self.wfile.write(msg.encode('utf-8')) def return_squares(self, query_components): if len(query_components) != 2: msg = "Invalid number of Query Components! Two components needed." else: if query_components[0][0] != 'von' or query_components[1][0] != 'bis': msg = "Invalid Query Components! First key should be 'von', second key 'bis'." self.wfile.write(msg.encode('utf-8')) else: try: von = int(query_components[0][1]) bis = int(query_components[1][1]) except: msg = "One or both query values are not integer." else: msg = "
{i} | {i**2} |