integrate parser into server
This commit is contained in:
parent
b6de76f44d
commit
6c711ae3da
38
esgd.py
38
esgd.py
|
@ -2,6 +2,9 @@ import socketserver
|
|||
import subprocess
|
||||
import os
|
||||
|
||||
host = "localhost"
|
||||
port = 70
|
||||
|
||||
class GopherError(BaseException): pass
|
||||
class RequestError(GopherError): pass
|
||||
|
||||
|
@ -35,11 +38,11 @@ class GopherLine:
|
|||
|
||||
try: self.host = split[2]
|
||||
except IndexError:
|
||||
if location == True: self.host = "beepboop.systems"
|
||||
if location == True: self.host = host
|
||||
|
||||
try: self.port = split[3]
|
||||
except IndexError:
|
||||
if location == True: self.port = "70"
|
||||
if location == True: self.port = str(port)
|
||||
def render(self):
|
||||
return "{}{}\t{}\t{}\t{}".format(
|
||||
self.item,
|
||||
|
@ -117,6 +120,15 @@ def cgi(file, query, context):
|
|||
|
||||
return out.decode("utf-8").replace("\r", "").split("\n")
|
||||
|
||||
def gopherRenderer(fileArray):
|
||||
gopherlines = []
|
||||
for i in fileArray:
|
||||
gopherlines.append(GopherLine(i))
|
||||
returned = []
|
||||
for i in gopherlines:
|
||||
returned.append(i.render())
|
||||
return returned
|
||||
|
||||
class gopherHandler(socketserver.BaseRequestHandler):
|
||||
def handle(self):
|
||||
decoded = recieveRequest(self)
|
||||
|
@ -131,8 +143,26 @@ class gopherHandler(socketserver.BaseRequestHandler):
|
|||
notFound(self)
|
||||
return
|
||||
if fileCGI(file[0]):
|
||||
sendFileArray(cgi(file[0], parsed[1], self), self)
|
||||
elif fileSendable(file[0]): sendFile(file[0], self)
|
||||
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)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue