From 393e06bb6c978126ad071f65655477c9564f65c3 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 20 Jul 2021 02:13:47 -0500 Subject: [PATCH] add fileToFileArray(...) function --- esgd.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/esgd.py b/esgd.py index 2b3284d..c2325bd 100644 --- a/esgd.py +++ b/esgd.py @@ -90,6 +90,12 @@ def notFound(context): def invalid(context): context.request.sendall(b"3error: selector contains '..'!\r\n.\r\n") +def fileToFileArray(file): + fd = open(file, "r") + ret = [i.rstrip() for i in fd.readlines()] + fd.close() + return ret + def sendFileArray(arr, context): [context.request.sendall( (i.rstrip() + "\r\n").encode("utf-8") @@ -128,7 +134,7 @@ def serveFile(file, query, gph, context): if fileCGI(file): fa = cgi(file, query, context) elif fileSendable(file): - fa = [i.rstrip() for i in open(file).readlines()] + fa = fileToFileArray(file) else: notFound(context) return