Basic inbox implementation

This commit is contained in:
Anthony Wang 2022-10-01 09:22:53 -04:00
parent acbad59116
commit 1e841569ea
Signed by: a
GPG key ID: 42A5B952E6DD8D38
3 changed files with 18 additions and 1 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
__pycache__

10
inbox.py Normal file
View file

@ -0,0 +1,10 @@
inbox = {}
def Send(data, recipient):
if recipient not in inbox.keys():
inbox[recipient] = []
inbox[recipient].append(data)
def Fetch(user):
return inbox[user]

View file

@ -1,4 +1,5 @@
from http.server import HTTPServer, BaseHTTPRequestHandler
from inbox import Send, Fetch
class HTTPRequestHandler(BaseHTTPRequestHandler):
@ -6,7 +7,12 @@ class HTTPRequestHandler(BaseHTTPRequestHandler):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(self.path.encode('utf-8'))
self.wfile.write(str(Fetch(self.path)).encode('utf-8'))
def do_POST(self):
Send(self.rfile.read(), self.path)
self.send_response(200)
self.end_headers()
server = HTTPServer(("0.0.0.0", 8000), HTTPRequestHandler)