proper separation of get_cache_path
This commit is contained in:
parent
78e428d3a7
commit
279bd12748
25
offpunk.py
25
offpunk.py
|
@ -844,18 +844,6 @@ class GeminiItem():
|
||||||
self.local = True
|
self.local = True
|
||||||
self.host = ""
|
self.host = ""
|
||||||
self.port = None
|
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
|
# file:// is 7 char
|
||||||
if self.url.startswith("file://"):
|
if self.url.startswith("file://"):
|
||||||
self.path = self.url[7:]
|
self.path = self.url[7:]
|
||||||
|
@ -863,8 +851,11 @@ class GeminiItem():
|
||||||
self.path = parsed.path
|
self.path = parsed.path
|
||||||
else:
|
else:
|
||||||
self.path = self.url
|
self.path = self.url
|
||||||
self._cache_path = self.path
|
|
||||||
else:
|
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 self.scheme == "gopher":
|
||||||
if parsed.path and parsed.path[0] == "/" and len(parsed.path) > 1:
|
if parsed.path and parsed.path[0] == "/" and len(parsed.path) > 1:
|
||||||
splitted = parsed.path.split("/")
|
splitted = parsed.path.split("/")
|
||||||
|
@ -898,9 +889,13 @@ class GeminiItem():
|
||||||
# Also, very long query are usually useless stuff
|
# Also, very long query are usually useless stuff
|
||||||
if len(self.path+parsed.query) < 258:
|
if len(self.path+parsed.query) < 258:
|
||||||
self.path += "/" + parsed.query
|
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
|
self._cache_path = self.path
|
||||||
|
#if not local, we create a local cache path.
|
||||||
else:
|
else:
|
||||||
self._cache_path = os.path.expanduser(_CACHE_PATH + self.scheme +\
|
self._cache_path = os.path.expanduser(_CACHE_PATH + self.scheme +\
|
||||||
"/" + self.host + self.path)
|
"/" + self.host + self.path)
|
||||||
|
|
Loading…
Reference in New Issue