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