Compare commits

...

7 Commits
v2.2 ... master

Author SHA1 Message Date
Ploum dc75136d07 fix a crash in opnk when cached but not downloaded 2024-05-11 22:49:03 +02:00
Ploum 51aa7fe853 fix spartan protocol error 2024-05-08 11:58:06 +02:00
Ploum 9a7e88d01b fix crash when feedparser is crashing on a bad RSS 2024-04-23 13:07:23 +02:00
Étienne Mollier 339acef720 opnk.py: fix warning with python3.12.
As initially identified by Paul Wise in [Debian Bug#1064209], opnk.py
experiences the following warning when running under python3.12:

	$ python3.12 opnk.py gemini://ploum.net >/dev/null
	/home/emollier/debian/forward-upstream/offpunk/opnk.py:52: SyntaxWarning: invalid escape sequence '\%'
	  less_prompt = "page %%d/%%D- lines %%lb/%%L - %%Pb\%%"

This is due to the interpretation of escape sequences being less
relaxed in the new Python interpreter version.  Doubling the backslash
is one way to resolve this issue.

[Debian Bug#1064209]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1064209

Signed-off-by: Étienne Mollier <emollier@debian.org>
2024-02-20 15:16:51 +01:00
Ploum 9c8693dc09 display empty files instead of opening them with xdg-open 2024-02-20 10:45:43 +01:00
Ploum 4e3d3ce62d netcache: add support for IPv6 hostname bug #40 2024-02-15 22:59:27 +01:00
Ploum d427287784 offpunk: fix IPv6 as an URL (bug #40) 2024-02-15 16:16:37 +01:00
5 changed files with 48 additions and 7 deletions

View File

@ -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)

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -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: