From 44213df44a880ab2ea9299894ba76e748858d6f6 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 19 Jul 2021 16:16:54 -0500 Subject: [PATCH] replace the quotes --- esgd.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/esgd.py b/esgd.py index 7fb4ad4..cd4f119 100644 --- a/esgd.py +++ b/esgd.py @@ -5,21 +5,19 @@ import os class GopherError(BaseException): pass class RequestError(GopherError): pass -print(os.getcwd()) - def recieveRequest(context): - data = b'' - while data[-2:] != b'\r\n': + data = b"" + while data[-2:] != b"\r\n": data += context.request.recv(1) - decoded = data[:-2].decode('utf-8') + decoded = data[:-2].decode("utf-8") return decoded def requestParser(request): - if '..' in request: raise RequestError + if ".." in request: raise RequestError try: - if request[0] == '/': request = request[1:] + if request[0] == "/": request = request[1:] except IndexError: pass - request = request.replace('?', '\t').split('\t') + request = request.replace("?", "\t").split("\t") try: return (request[0], request[1]) except IndexError: return (request[0], "") @@ -32,7 +30,7 @@ def returnRelative(file): ret = file + "/gophermap" gph = True elif os.path.isfile(file): ret = file - else: raise RequestError('unreachable state') + else: raise RequestError("unreachable state") return (ret, gph) def fileSendable(file): return os.access(file, os.F_OK|os.R_OK) @@ -58,9 +56,9 @@ def sendFileArray(arr, context): def cgi(file, query, context): env = {} - env['QUERY_STRING'] = query - env['SCRIPT_NAME'] = "/" + file - env['REMOTE_ADDR'] = context.client_address[0] + env["QUERY_STRING"] = query + env["SCRIPT_NAME"] = "/" + file + env["REMOTE_ADDR"] = context.client_address[0] proc = subprocess.Popen( [os.getcwd() + "/" + file], @@ -73,7 +71,7 @@ def cgi(file, query, context): proc.kill() out, err = proc.communicate() - return out.decode('utf-8').replace('\r', '').split('\n') + return out.decode("utf-8").replace("\r", "").split("\n") class gopherHandler(socketserver.BaseRequestHandler): def handle(self): @@ -94,7 +92,7 @@ class gopherHandler(socketserver.BaseRequestHandler): else: notFound(self) if __name__ == "__main__": - HOST, PORT = "localhost", 75 + HOST, PORT = "localhost", 70 with socketserver.TCPServer((HOST, PORT), gopherHandler) as server: server.serve_forever()