replace the quotes
This commit is contained in:
parent
bd50cd7e1e
commit
44213df44a
26
esgd.py
26
esgd.py
|
@ -5,21 +5,19 @@ import os
|
||||||
class GopherError(BaseException): pass
|
class GopherError(BaseException): pass
|
||||||
class RequestError(GopherError): pass
|
class RequestError(GopherError): pass
|
||||||
|
|
||||||
print(os.getcwd())
|
|
||||||
|
|
||||||
def recieveRequest(context):
|
def recieveRequest(context):
|
||||||
data = b''
|
data = b""
|
||||||
while data[-2:] != b'\r\n':
|
while data[-2:] != b"\r\n":
|
||||||
data += context.request.recv(1)
|
data += context.request.recv(1)
|
||||||
decoded = data[:-2].decode('utf-8')
|
decoded = data[:-2].decode("utf-8")
|
||||||
return decoded
|
return decoded
|
||||||
|
|
||||||
def requestParser(request):
|
def requestParser(request):
|
||||||
if '..' in request: raise RequestError
|
if ".." in request: raise RequestError
|
||||||
try:
|
try:
|
||||||
if request[0] == '/': request = request[1:]
|
if request[0] == "/": request = request[1:]
|
||||||
except IndexError: pass
|
except IndexError: pass
|
||||||
request = request.replace('?', '\t').split('\t')
|
request = request.replace("?", "\t").split("\t")
|
||||||
try: return (request[0], request[1])
|
try: return (request[0], request[1])
|
||||||
except IndexError: return (request[0], "")
|
except IndexError: return (request[0], "")
|
||||||
|
|
||||||
|
@ -32,7 +30,7 @@ def returnRelative(file):
|
||||||
ret = file + "/gophermap"
|
ret = file + "/gophermap"
|
||||||
gph = True
|
gph = True
|
||||||
elif os.path.isfile(file): ret = file
|
elif os.path.isfile(file): ret = file
|
||||||
else: raise RequestError('unreachable state')
|
else: raise RequestError("unreachable state")
|
||||||
return (ret, gph)
|
return (ret, gph)
|
||||||
|
|
||||||
def fileSendable(file): return os.access(file, os.F_OK|os.R_OK)
|
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):
|
def cgi(file, query, context):
|
||||||
env = {}
|
env = {}
|
||||||
env['QUERY_STRING'] = query
|
env["QUERY_STRING"] = query
|
||||||
env['SCRIPT_NAME'] = "/" + file
|
env["SCRIPT_NAME"] = "/" + file
|
||||||
env['REMOTE_ADDR'] = context.client_address[0]
|
env["REMOTE_ADDR"] = context.client_address[0]
|
||||||
|
|
||||||
proc = subprocess.Popen(
|
proc = subprocess.Popen(
|
||||||
[os.getcwd() + "/" + file],
|
[os.getcwd() + "/" + file],
|
||||||
|
@ -73,7 +71,7 @@ def cgi(file, query, context):
|
||||||
proc.kill()
|
proc.kill()
|
||||||
out, err = proc.communicate()
|
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):
|
class gopherHandler(socketserver.BaseRequestHandler):
|
||||||
def handle(self):
|
def handle(self):
|
||||||
|
@ -94,7 +92,7 @@ class gopherHandler(socketserver.BaseRequestHandler):
|
||||||
else: notFound(self)
|
else: notFound(self)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
HOST, PORT = "localhost", 75
|
HOST, PORT = "localhost", 70
|
||||||
|
|
||||||
with socketserver.TCPServer((HOST, PORT), gopherHandler) as server:
|
with socketserver.TCPServer((HOST, PORT), gopherHandler) as server:
|
||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
|
|
Loading…
Reference in New Issue