forked from solderpunk/AV-98
Compare commits
7 Commits
Author | SHA1 | Date |
---|---|---|
Ploum | dc75136d07 | |
Ploum | 51aa7fe853 | |
Ploum | 9a7e88d01b | |
Étienne Mollier | 339acef720 | |
Ploum | 9c8693dc09 | |
Ploum | 4e3d3ce62d | |
Ploum | d427287784 |
|
@ -1,5 +1,12 @@
|
|||
# Offpunk History
|
||||
|
||||
## 2.3 - Unreleased
|
||||
- offpunk/netcache: fix IPv6 as an URL (bug #40)
|
||||
- ansicat: display empty files (instead of opening them with xdg-open)
|
||||
- fix escape sequence warning in python 3.12 (by Étienne Mollier) (Debian #1064209)
|
||||
- ansicat : fix crash when feedparser is crashing on bad RSS
|
||||
- netcache: fix spartan protocol error
|
||||
- opnk: fix a crash when caching returns None
|
||||
|
||||
## 2.2 - February 13th 2023
|
||||
- cache folder is now configurable through $OFFPUNK_CACHE_PATH environment variable (by prx)
|
||||
|
|
21
ansicat.py
21
ansicat.py
|
@ -727,6 +727,13 @@ class GemtextRenderer(AbstractRenderer):
|
|||
links += hidden_links
|
||||
return r.get_final(), links
|
||||
|
||||
class EmptyRenderer(GemtextRenderer):
|
||||
def get_mime(self):
|
||||
return "text/empty"
|
||||
def prepare(self,body,mode=None):
|
||||
text= "(empty file)"
|
||||
return [[text, "GemtextRenderer"]]
|
||||
|
||||
class GopherRenderer(AbstractRenderer):
|
||||
def get_mime(self):
|
||||
return "text/gopher"
|
||||
|
@ -870,10 +877,15 @@ class FeedRenderer(GemtextRenderer):
|
|||
return "application/rss+xml"
|
||||
def is_valid(self):
|
||||
if _DO_FEED:
|
||||
parsed = feedparser.parse(self.body)
|
||||
try:
|
||||
parsed = feedparser.parse(self.body)
|
||||
except:
|
||||
parsed = False
|
||||
else:
|
||||
return False
|
||||
if parsed.bozo:
|
||||
if not parsed:
|
||||
return False
|
||||
elif parsed.bozo:
|
||||
return False
|
||||
else:
|
||||
#If no content, then fallback to HTML
|
||||
|
@ -1312,11 +1324,16 @@ _FORMAT_RENDERERS = {
|
|||
"text/gopher": GopherRenderer,
|
||||
"image/*": ImageRenderer,
|
||||
"application/javascript": HtmlRenderer,
|
||||
"application/json": HtmlRenderer,
|
||||
"text/empty": EmptyRenderer,
|
||||
}
|
||||
def get_mime(path,url=None):
|
||||
#Beware, this one is really a shaddy ad-hoc function
|
||||
if not path:
|
||||
return None
|
||||
#If the file is empty, simply returns it
|
||||
elif os.path.exists(path) and os.stat(path).st_size == 0:
|
||||
return "text/empty"
|
||||
elif url and url.startswith("gopher://"):
|
||||
#special case for gopher
|
||||
#code copy/pasted from netcache
|
||||
|
|
|
@ -656,6 +656,9 @@ def _fetch_gemini(url,timeout=DEFAULT_TIMEOUT,interactive=True,accept_bad_ssl_ce
|
|||
# Send request and wrap response in a file descriptor
|
||||
url = urllib.parse.urlparse(url)
|
||||
new_netloc = host
|
||||
#Handle IPV6 hostname
|
||||
if ":" in new_netloc:
|
||||
new_netloc = "[" + new_netloc + "]"
|
||||
if port != standard_ports["gemini"]:
|
||||
new_netloc += ":" + str(port)
|
||||
url = urllib.parse.urlunparse(url._replace(netloc=new_netloc))
|
||||
|
@ -799,8 +802,10 @@ def fetch(url,offline=False,download_image_first=True,images_mode="readable",val
|
|||
path=_fetch_finger(url,**kwargs)
|
||||
elif scheme == "gemini":
|
||||
path,newurl=_fetch_gemini(url,**kwargs)
|
||||
elif scheme == "spartan":
|
||||
path,newurl=_fetch_spartan(url,**kwargs)
|
||||
else:
|
||||
print("scheme %s not implemented yet")
|
||||
print("scheme %s not implemented yet"%scheme)
|
||||
except UserAbortException:
|
||||
return None, newurl
|
||||
except Exception as err:
|
||||
|
|
13
offutils.py
13
offutils.py
|
@ -99,7 +99,7 @@ def fix_ipv6_url(url):
|
|||
netloc, rest = schemaless.split("/",1)
|
||||
if netloc.count(":") > 2 and "[" not in netloc and "]" not in netloc:
|
||||
schemaless = "[" + netloc + "]" + "/" + rest
|
||||
elif schemaless.count(":") > 2:
|
||||
elif schemaless.count(":") > 2 and "[" not in schemaless and "]" not in schemaless:
|
||||
schemaless = "[" + schemaless + "]/"
|
||||
if schema:
|
||||
return schema + "://" + schemaless
|
||||
|
@ -121,7 +121,16 @@ def looks_like_url(word):
|
|||
if mailto:
|
||||
return "@" in word
|
||||
elif not local:
|
||||
return start and ("." in word or "localhost" in word)
|
||||
if start:
|
||||
#IPv4
|
||||
if "." in word or "localhost" in word:
|
||||
return True
|
||||
#IPv6
|
||||
elif "[" in word and ":" in word and "]" in word:
|
||||
return True
|
||||
else: return False
|
||||
else: return False
|
||||
return start and ("." in word or "localhost" in word or ":" in word)
|
||||
else:
|
||||
return "/" in word
|
||||
except ValueError:
|
||||
|
|
7
opnk.py
7
opnk.py
|
@ -49,7 +49,7 @@ else:
|
|||
# are there on purpose (surch in asciiart)
|
||||
#--incsearch : incremental search starting rev581
|
||||
def less_cmd(file, histfile=None,cat=False,grep=None):
|
||||
less_prompt = "page %%d/%%D- lines %%lb/%%L - %%Pb\%%"
|
||||
less_prompt = "page %%d/%%D- lines %%lb/%%L - %%Pb\\%%"
|
||||
if less_version >= 581:
|
||||
less_base = "less --incsearch --save-marks -~ -XRfWiS -P \"%s\""%less_prompt
|
||||
elif less_version >= 572:
|
||||
|
@ -159,7 +159,10 @@ class opencache():
|
|||
if inpath in self.renderer_time.keys():
|
||||
last_downloaded = netcache.cache_last_modified(inpath)
|
||||
last_cached = self.renderer_time[inpath]
|
||||
usecache = last_cached > last_downloaded
|
||||
if last_cached and last_downloaded:
|
||||
usecache = last_cached > last_downloaded
|
||||
else:
|
||||
usecache = False
|
||||
else:
|
||||
usecache = False
|
||||
if not usecache:
|
||||
|
|
Loading…
Reference in New Issue