Start shuffling things around.

master
Simon de Vlieger 3 years ago
parent 6a8a464d58
commit f664261e26

@ -91,7 +91,7 @@ def main(
logging.basicConfig(level=logging.INFO)
server = modes[mode](str(path), magic, encoding)
server = modes[mode](str(path), "localhost", 7070, magic, encoding)
server.listen(port)
server.start(0)

@ -8,11 +8,13 @@ class Entry:
https://en.wikipedia.org/wiki/Gopher_(protocol)#Item_types"""
# TODO make this come from somewhere
host = "localhost"
port = "7070"
host: str
port: int
def __init__(self, host: str, port: int, text: str, selector: str) -> None:
self.host = host
self.port = port
def __init__(self, text: str, selector: str) -> None:
self.text = text
self.selector = selector
@ -24,9 +26,10 @@ class Text(Entry):
class Directory(Entry):
code = 1
def __init__(self, text: str, selector: str) -> None:
def __init__(self, host: str, port: int, text: str, selector: str) -> None:
super().__init__(host, port, text, selector)
self.text = text + "/"
self.selector = selector
class CCSO(Entry):

@ -8,8 +8,13 @@ import gb.magic
class Mode:
def __init__(self, base_path: str, magic: bool) -> None:
def __init__(
self, base_path: str, host: str, port: int, magic: bool
) -> None:
self.base_path = os.path.abspath(base_path)
self.host = host
self.port = port
self.magic = magic
def lookup(self, path: str) -> str:
@ -53,7 +58,12 @@ class ImplicitMode(Mode):
item = gb.entry.Binary # type: ignore
response.add_entry(
item(os.path.basename(entry), entry[len(self.base_path) :])
item(
self.host,
self.port,
os.path.basename(entry),
entry[len(self.base_path) :],
)
)
return str(response)

@ -86,10 +86,12 @@ class ImplicitGopherServer(GopherServer):
while auto generating indexes for directories. If magic is enabled then
the mode will auto-guess filetypes."""
def __init__(self, path: str, magic: bool, encoding: str) -> None:
def __init__(
self, path: str, host: str, port: int, magic: bool, encoding: str
) -> None:
super().__init__()
log.info("Starting ImplicitGopherServer with path %s", path)
self.encoding = encoding
self.mode = gb.mode.ImplicitMode(path, magic)
self.mode = gb.mode.ImplicitMode(path, host, port, magic)

Loading…
Cancel
Save