working webserver

This commit is contained in:
Christoph J. Scherr 2023-09-04 21:57:56 +02:00
parent 3106a55d8e
commit f0ec2e26ce
4 changed files with 18 additions and 6 deletions

3
src/fib.py Normal file → Executable file
View File

@ -1,6 +1,9 @@
#!/usr/bin/env python3
import sys
def fib(n):
fibs = [0, 1]
for i in range(2, n+1):
fibs.append(fibs[i-1] + fibs[i-2])
print(fibs)
return fibs[n]
fib(int(sys.argv[1]))

1
src/md5.py Normal file → Executable file
View File

@ -1,3 +1,4 @@
#!/usr/bin/env python3
import hashlib
import sys
hashed = hashlib.md5(sys.argv[1].encode())

1
src/md5range.py Normal file → Executable file
View File

@ -1,3 +1,4 @@
#!/usr/bin/env python3
import hashlib
BASE: str = "foobar"
MAX = 1000000

19
src/miniweb.py Normal file → Executable file
View File

@ -1,15 +1,22 @@
#!/usr/bin/env python3
import http.server
import io
class MyHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
self.send_head()
def send_head(self):
body = "hello world"
TEXT = """Hello world!
If you're reading this, this web server is working!
"""
class MyHandler(http.server.SimpleHTTPRequestHandler):
def send_head(self) -> io.BytesIO:
body = TEXT.encode()
self.send_response(200)
self.send_header("Content-type", "text/html; charset=utf-8")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
return io.StringIO(body)
return io.BytesIO(body)
addtrss = ("127.0.0.1", 8080)
srv = http.server.HTTPServer(addtrss, MyHandler)
srv.serve_forever()