From f0ec2e26ce2514a36bf51afe71e835d2a8548446 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Mon, 4 Sep 2023 21:57:56 +0200 Subject: [PATCH] working webserver --- src/fib.py | 3 +++ src/md5.py | 1 + src/md5range.py | 1 + src/miniweb.py | 19 +++++++++++++------ 4 files changed, 18 insertions(+), 6 deletions(-) mode change 100644 => 100755 src/fib.py mode change 100644 => 100755 src/md5.py mode change 100644 => 100755 src/md5range.py mode change 100644 => 100755 src/miniweb.py diff --git a/src/fib.py b/src/fib.py old mode 100644 new mode 100755 index 3c1fe74..01ab97c --- a/src/fib.py +++ b/src/fib.py @@ -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])) diff --git a/src/md5.py b/src/md5.py old mode 100644 new mode 100755 index a4218b7..9933b50 --- a/src/md5.py +++ b/src/md5.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 import hashlib import sys hashed = hashlib.md5(sys.argv[1].encode()) diff --git a/src/md5range.py b/src/md5range.py old mode 100644 new mode 100755 index 789339e..e93dba6 --- a/src/md5range.py +++ b/src/md5range.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 import hashlib BASE: str = "foobar" MAX = 1000000 diff --git a/src/miniweb.py b/src/miniweb.py old mode 100644 new mode 100755 index 6cdeacd..fa5e2a7 --- a/src/miniweb.py +++ b/src/miniweb.py @@ -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()