add fileToFileArray(...) function

This commit is contained in:
randomuser 2021-07-20 02:13:47 -05:00
parent 6902236940
commit 393e06bb6c
1 changed files with 7 additions and 1 deletions

View File

@ -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