Browse Source

Minor changes!

devel
Heimbs 5 years ago
parent
commit
487f7cc0d7
1 changed files with 10 additions and 11 deletions
  1. 10
    11
      http-server

+ 10
- 11
http-server View File

@@ -1,4 +1,4 @@
#/usr/bin/env python3
#!/usr/bin/env python3

from http import server
from urllib import parse
@@ -15,16 +15,16 @@ class SimpleHandler(server.BaseHTTPRequestHandler):
query_components = parse.parse_qsl(query)

if path == "/":
self.return_get_components(path, query, query_components)
msg = self.return_get_components(path, query, query_components)
elif path == "/ying":
self.return_ying()
msg = self.return_ying()
elif path == "/yang":
self.return_yang()
msg = self.return_yang()
elif path == "/squares":
self.return_squares(query_components)
msg = self.return_squares(query_components)
else:
msg = "Error 404"
self.wfile.write(msg.encode('utf-8'))
self.wfile.write(msg.encode('utf-8'))

def return_squares(self, query_components):
if len(query_components) != 2:
@@ -44,21 +44,20 @@ class SimpleHandler(server.BaseHTTPRequestHandler):
for i in range(von, bis+1):
msg += f"<tr><td>{i}</td><td>{i**2}</td></tr>"
msg += "</table>"
self.wfile.write(msg.encode('utf-8'))
return msg

def return_ying(self):
msg = "<a href='/yang'>Ying</a>"
self.wfile.write(msg.encode('utf-8'))
return msg
def return_yang(self):
msg = "<a href='/ying'>Yang</a>"
self.wfile.write(msg.encode('utf-8'))
return msg
def return_get_components(self, path, query, query_components):
msg = f"Path: {path}\nQuery: {query}\nComponents: {str(query_components)}"

self.wfile.write(msg.encode('utf-8'))
return msg

if __name__ == "__main__":
port = 60000

Loading…
Cancel
Save