Simplify and unify GeminiItem methods.
This commit is contained in:
parent
b4623c0ccc
commit
518dadb31e
17
av98.py
17
av98.py
|
@ -105,10 +105,10 @@ class GeminiItem():
|
||||||
self.port = parsed.port or standard_ports[self.scheme]
|
self.port = parsed.port or standard_ports[self.scheme]
|
||||||
self.path = parsed.path
|
self.path = parsed.path
|
||||||
|
|
||||||
def root_url(self):
|
def root(self):
|
||||||
return self._derive_url("/")
|
return GeminiItem(self._derive_url("/"))
|
||||||
|
|
||||||
def up_url(self):
|
def up(self):
|
||||||
pathbits = list(os.path.split(self.path))
|
pathbits = list(os.path.split(self.path))
|
||||||
# Get rid of empty string from trailing /
|
# Get rid of empty string from trailing /
|
||||||
while not pathbits[-1]:
|
while not pathbits[-1]:
|
||||||
|
@ -119,9 +119,9 @@ class GeminiItem():
|
||||||
# Get rid of bottom component
|
# Get rid of bottom component
|
||||||
pathbits.pop()
|
pathbits.pop()
|
||||||
new_path = os.path.join(*pathbits)
|
new_path = os.path.join(*pathbits)
|
||||||
return self._derive_url(new_path)
|
return GeminiItem(self._derive_url(new_path))
|
||||||
|
|
||||||
def add_query(self, query):
|
def query(self, query):
|
||||||
return GeminiItem(self._derive_url(query=query))
|
return GeminiItem(self._derive_url(query=query))
|
||||||
|
|
||||||
def _derive_url(self, path="", query=""):
|
def _derive_url(self, path="", query=""):
|
||||||
|
@ -264,8 +264,7 @@ Slow internet connection? Use 'set timeout' to be more patient.""")
|
||||||
# Inputs
|
# Inputs
|
||||||
if status.startswith("1"):
|
if status.startswith("1"):
|
||||||
user_input = input(meta)
|
user_input = input(meta)
|
||||||
new_gi = gi.add_query(user_input)
|
self._go_to_gi(gi.query(user_input))
|
||||||
self._go_to_gi(new_gi)
|
|
||||||
return
|
return
|
||||||
# Redirects
|
# Redirects
|
||||||
elif status.startswith("3"):
|
elif status.startswith("3"):
|
||||||
|
@ -606,7 +605,7 @@ Slow internet connection? Use 'set timeout' to be more patient.""")
|
||||||
@needs_gi
|
@needs_gi
|
||||||
def do_up(self, *args):
|
def do_up(self, *args):
|
||||||
"""Go up one directory in the path."""
|
"""Go up one directory in the path."""
|
||||||
self._go_to_gi(GeminiItem(self.gi.up_url()))
|
self._go_to_gi(self.gi.up()))
|
||||||
|
|
||||||
def do_back(self, *args):
|
def do_back(self, *args):
|
||||||
"""Go back to the previous gemini item."""
|
"""Go back to the previous gemini item."""
|
||||||
|
@ -636,7 +635,7 @@ Slow internet connection? Use 'set timeout' to be more patient.""")
|
||||||
@needs_gi
|
@needs_gi
|
||||||
def do_root(self, *args):
|
def do_root(self, *args):
|
||||||
"""Go to root selector of the server hosting current item."""
|
"""Go to root selector of the server hosting current item."""
|
||||||
self._go_to_gi(GeminiItem(self.gi.root_url()))
|
self._go_to_gi(self.gi.root()))
|
||||||
|
|
||||||
def do_tour(self, line):
|
def do_tour(self, line):
|
||||||
"""Add index items as waypoints on a tour, which is basically a FIFO
|
"""Add index items as waypoints on a tour, which is basically a FIFO
|
||||||
|
|
Loading…
Reference in New Issue