forked from solderpunk/AV-98
Merge pull request 'Add gemini:// support directly to urllib.parse' (#16) from dancek/AV-98:simplify-urljoin into master
Thanks a lot! I've never bothered to poke inside `urljoin` before so didn't realise this was so easy to do. I agree that this is far more readable and maintainable.
This commit is contained in:
commit
fd8ee5bfb7
18
av98.py
18
av98.py
|
@ -86,6 +86,12 @@ _MIME_HANDLERS = {
|
||||||
"text/gemini": "cat %s",
|
"text/gemini": "cat %s",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# monkey-patch Gemini support in urllib.parse
|
||||||
|
# see https://github.com/python/cpython/blob/master/Lib/urllib/parse.py
|
||||||
|
urllib.parse.uses_relative.append("gemini")
|
||||||
|
urllib.parse.uses_netloc.append("gemini")
|
||||||
|
|
||||||
|
|
||||||
def fix_ipv6_url(url):
|
def fix_ipv6_url(url):
|
||||||
if not url.count(":") > 2: # Best way to detect them?
|
if not url.count(":") > 2: # Best way to detect them?
|
||||||
return url
|
return url
|
||||||
|
@ -159,17 +165,7 @@ class GeminiItem():
|
||||||
Convert a relative URL to an absolute URL by using the URL of this
|
Convert a relative URL to an absolute URL by using the URL of this
|
||||||
GeminiItem as a base.
|
GeminiItem as a base.
|
||||||
"""
|
"""
|
||||||
# Absolutise URL, which annoyingly needs a valid scheme...
|
return urllib.parse.urljoin(self.url, relative_url)
|
||||||
if self.url.startswith("gemini://"):
|
|
||||||
base_url = self.url.replace("gemini://", "https://")
|
|
||||||
was_gemini = True
|
|
||||||
else:
|
|
||||||
base_url = self.url
|
|
||||||
was_gemini = False
|
|
||||||
absolute = urllib.parse.urljoin(base_url, relative_url)
|
|
||||||
if absolute != relative_url and was_gemini:
|
|
||||||
absolute = absolute.replace("https://", "gemini://")
|
|
||||||
return absolute
|
|
||||||
|
|
||||||
def to_map_line(self, name=None):
|
def to_map_line(self, name=None):
|
||||||
if name or self.name:
|
if name or self.name:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user