Avoid duplication of calls to of urlunparse.
This commit is contained in:
parent
b75b1d94ff
commit
6c8921a219
21
av98.py
21
av98.py
|
@ -106,10 +106,7 @@ class GeminiItem():
|
||||||
self.path = parsed.path
|
self.path = parsed.path
|
||||||
|
|
||||||
def root_url(self):
|
def root_url(self):
|
||||||
return urllib.parse.urlunparse((self.scheme,
|
return self._derive_url("/")
|
||||||
# Don't include redundant ports in the netloc
|
|
||||||
self.host if self.port == standard_ports[self.scheme] else self.host + ":" + str(self.port),
|
|
||||||
"/", "", "", ""))
|
|
||||||
|
|
||||||
def up_url(self):
|
def up_url(self):
|
||||||
pathbits = list(os.path.split(self.path))
|
pathbits = list(os.path.split(self.path))
|
||||||
|
@ -122,15 +119,19 @@ 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 urllib.parse.urlunparse((self.scheme,
|
return self._derive_url(new_path)
|
||||||
self.host if self.port == standard_ports[self.scheme] else self.host + ":" + str(self.port),
|
|
||||||
new_path, "", "", ""))
|
|
||||||
|
|
||||||
def add_query(self, query):
|
def add_query(self, query):
|
||||||
new_url = urllib.parse.urlunparse((self.scheme,
|
return GeminiItem(self._derive_url(query=query))
|
||||||
|
|
||||||
|
def _derive_url(self, path="", query=""):
|
||||||
|
"""
|
||||||
|
A thin wrapper around urlunparse which avoids inserting standard ports
|
||||||
|
into URLs just to keep things clean.
|
||||||
|
"""
|
||||||
|
return = urllib.parse.urlunparse((self.scheme,
|
||||||
self.host if self.port == standard_ports[self.scheme] else self.host + ":" + str(self.port),
|
self.host if self.port == standard_ports[self.scheme] else self.host + ":" + str(self.port),
|
||||||
self.path, "", query, ""))
|
path or self.path, "", query, ""))
|
||||||
return GeminiItem(new_url)
|
|
||||||
|
|
||||||
def absolutise_url(self, relative_url):
|
def absolutise_url(self, relative_url):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user