add perimitive gopher parser
This commit is contained in:
parent
44213df44a
commit
b6de76f44d
44
esgd.py
44
esgd.py
|
@ -5,6 +5,50 @@ import os
|
|||
class GopherError(BaseException): pass
|
||||
class RequestError(GopherError): pass
|
||||
|
||||
class GopherLine:
|
||||
def __init__(self, line):
|
||||
self.item = "i"
|
||||
self.text = ""
|
||||
self.location = "null"
|
||||
self.host = "null.host"
|
||||
self.port = "0"
|
||||
self.line = line
|
||||
self.parse()
|
||||
def parse(self):
|
||||
split = self.line.rstrip().split('\t')
|
||||
location = False
|
||||
print(split)
|
||||
if len(split) == 1:
|
||||
self.text = split[0]
|
||||
return
|
||||
|
||||
try: self.item = split[0][0]
|
||||
except IndexError: pass
|
||||
|
||||
try: self.text = split[0][1:]
|
||||
except IndexError: pass
|
||||
|
||||
try:
|
||||
self.location = split[1]
|
||||
location = True
|
||||
except IndexError: pass
|
||||
|
||||
try: self.host = split[2]
|
||||
except IndexError:
|
||||
if location == True: self.host = "beepboop.systems"
|
||||
|
||||
try: self.port = split[3]
|
||||
except IndexError:
|
||||
if location == True: self.port = "70"
|
||||
def render(self):
|
||||
return "{}{}\t{}\t{}\t{}".format(
|
||||
self.item,
|
||||
self.text,
|
||||
self.location,
|
||||
self.host,
|
||||
self.port
|
||||
)
|
||||
|
||||
def recieveRequest(context):
|
||||
data = b""
|
||||
while data[-2:] != b"\r\n":
|
||||
|
|
Loading…
Reference in New Issue