move file serving logic to serveFile(...)
This commit is contained in:
parent
581aa7d1d7
commit
b690b8f571
35
esgd.py
35
esgd.py
|
@ -128,6 +128,18 @@ def gopherRenderer(fileArray):
|
|||
returned.append(i.render())
|
||||
return returned
|
||||
|
||||
def serveFile(file, query, gph, context):
|
||||
if fileCGI(file):
|
||||
if not gph:
|
||||
sendFileArray(cgi(file, query, context), context)
|
||||
else:
|
||||
sendFileArray(gopherRenderer(cgi(file, query, context)), context)
|
||||
elif fileSendable(file):
|
||||
if not gph: sendFile(file, context)
|
||||
else:
|
||||
sendFileArray(gopherRenderer([i.rstrip() for i in open(file).readlines()]), context)
|
||||
else: notFound(context)
|
||||
|
||||
class gopherHandler(socketserver.BaseRequestHandler):
|
||||
def handle(self):
|
||||
decoded = recieveRequest(self)
|
||||
|
@ -141,28 +153,7 @@ class gopherHandler(socketserver.BaseRequestHandler):
|
|||
except RequestError:
|
||||
notFound(self)
|
||||
return
|
||||
if fileCGI(file[0]):
|
||||
if not file[1]:
|
||||
sendFileArray(
|
||||
cgi(file[0], parsed[1], self), self
|
||||
)
|
||||
else:
|
||||
sendFileArray(
|
||||
gopherRenderer(
|
||||
cgi(
|
||||
file[0], parsed[1], self
|
||||
)
|
||||
), self
|
||||
)
|
||||
elif fileSendable(file[0]):
|
||||
if not file[1]: sendFile(file[0], self)
|
||||
else:
|
||||
sendFileArray(
|
||||
gopherRenderer(
|
||||
[i.rstrip() for i in open(file[0]).readlines()]
|
||||
), self
|
||||
)
|
||||
else: notFound(self)
|
||||
serveFile(file[0], parsed[1], file[1], self)
|
||||
|
||||
if __name__ == "__main__":
|
||||
with socketserver.TCPServer((host, port), gopherHandler) as server:
|
||||
|
|
Loading…
Reference in New Issue