proper separation of get_cache_path

This commit is contained in:
Lionel Dricot 2022-02-17 12:48:39 +01:00
parent 78e428d3a7
commit 279bd12748
1 changed files with 66 additions and 71 deletions

View File

@ -844,18 +844,6 @@ class GeminiItem():
self.local = True
self.host = ""
self.port = None
else:
self.local = False
self.host = parsed.hostname
self.port = parsed.port or standard_ports.get(self.scheme, 0)
self._cache_path = self.get_cache_path()
def get_cache_path(self):
if self._cache_path and not os.path.isdir(self._cache_path):
return self._cache_path
else:
parsed = urllib.parse.urlparse(self.url)
if self.scheme in ["file","mailto"]:
# file:// is 7 char
if self.url.startswith("file://"):
self.path = self.url[7:]
@ -863,8 +851,11 @@ class GeminiItem():
self.path = parsed.path
else:
self.path = self.url
self._cache_path = self.path
else:
self.local = False
self.host = parsed.hostname
self.port = parsed.port or standard_ports.get(self.scheme, 0)
# special gopher selector case
if self.scheme == "gopher":
if parsed.path and parsed.path[0] == "/" and len(parsed.path) > 1:
splitted = parsed.path.split("/")
@ -898,9 +889,13 @@ class GeminiItem():
# Also, very long query are usually useless stuff
if len(self.path+parsed.query) < 258:
self.path += "/" + parsed.query
#if not local, we create a local cache path.
if self.local:
def get_cache_path(self):
if self._cache_path and not os.path.isdir(self._cache_path):
return self._cache_path
elif self.local:
self._cache_path = self.path
#if not local, we create a local cache path.
else:
self._cache_path = os.path.expanduser(_CACHE_PATH + self.scheme +\
"/" + self.host + self.path)