|
|
|
|
|
|
|
|
|
|
|
import http.server |
|
|
|
|
|
import urllib.parse |
|
|
|
|
|
|
|
|
|
|
|
class MyHandler(http.server.BaseHTTPRequestHandler): |
|
|
|
|
|
|
|
|
|
|
|
def do_GET(self): |
|
|
|
|
|
self.send_response(200) |
|
|
|
|
|
self.end_headers() |
|
|
|
|
|
|
|
|
|
|
|
parsed = urllib.parse.urlparse(self.path) |
|
|
|
|
|
path = parsed.path |
|
|
|
|
|
msg = '' |
|
|
|
|
|
|
|
|
|
|
|
if path == '/ying': |
|
|
|
|
|
msg = """ |
|
|
|
|
|
<html> |
|
|
|
|
|
<head> |
|
|
|
|
|
<title> Ying und Yang </title> |
|
|
|
|
|
</head> |
|
|
|
|
|
<body> |
|
|
|
|
|
ying |
|
|
|
|
|
<a href="yang">click here</a> |
|
|
|
|
|
</body> |
|
|
|
|
|
</html> |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
if path == '/yang': |
|
|
|
|
|
msg = """ |
|
|
|
|
|
<html> |
|
|
|
|
|
<head> |
|
|
|
|
|
<title> Ying und Yang </title> |
|
|
|
|
|
</head> |
|
|
|
|
|
<body> |
|
|
|
|
|
yang |
|
|
|
|
|
<a href="ying">click here</a> |
|
|
|
|
|
</body> |
|
|
|
|
|
</html> |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
self.wfile.write(msg.encode('utf-8')) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
port = 12345 |
|
|
|
|
|
handler = MyHandler |
|
|
|
|
|
address = ('', port) |
|
|
|
|
|
|
|
|
|
|
|
server = http.server.HTTPServer(address, handler) |
|
|
|
|
|
server.serve_forever() |
|
|
|
|
|
|