forked from solderpunk/AV-98
Fixes bug #26
- make python-requests optional again - reimplement --disable-http which had no effect
This commit is contained in:
parent
8d082cb2df
commit
ac78e85d04
|
@ -1,5 +1,10 @@
|
||||||
# Offpunk History
|
# Offpunk History
|
||||||
|
|
||||||
|
## 2.0 (beta3 ?) - Unreleased
|
||||||
|
Changes since beta2:
|
||||||
|
- bug #25 : makes python-requests optional again
|
||||||
|
- --disable-http had no effect: reimplemented
|
||||||
|
|
||||||
## 2.0-beta2 - November 8th 2023
|
## 2.0-beta2 - November 8th 2023
|
||||||
Changes since beta1
|
Changes since beta1
|
||||||
- IMPORTANT: migrating from flit to hatchling (patch by Jean Abou Samra)
|
- IMPORTANT: migrating from flit to hatchling (patch by Jean Abou Samra)
|
||||||
|
|
16
netcache.py
16
netcache.py
|
@ -3,7 +3,6 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import argparse
|
import argparse
|
||||||
import requests
|
|
||||||
import codecs
|
import codecs
|
||||||
import getpass
|
import getpass
|
||||||
import socket
|
import socket
|
||||||
|
@ -30,6 +29,11 @@ try:
|
||||||
_BACKEND = default_backend()
|
_BACKEND = default_backend()
|
||||||
except(ModuleNotFoundError,ImportError):
|
except(ModuleNotFoundError,ImportError):
|
||||||
_HAS_CRYPTOGRAPHY = False
|
_HAS_CRYPTOGRAPHY = False
|
||||||
|
try:
|
||||||
|
import requests
|
||||||
|
_DO_HTTP = True
|
||||||
|
except (ModuleNotFoundError,ImportError):
|
||||||
|
_DO_HTTP = False
|
||||||
|
|
||||||
if not os.path.exists(_CACHE_PATH):
|
if not os.path.exists(_CACHE_PATH):
|
||||||
print("Creating cache directory {}".format(_CACHE_PATH))
|
print("Creating cache directory {}".format(_CACHE_PATH))
|
||||||
|
@ -290,6 +294,7 @@ def set_error(url,err):
|
||||||
return cache
|
return cache
|
||||||
|
|
||||||
def _fetch_http(url,max_size=None,timeout=DEFAULT_TIMEOUT,accept_bad_ssl_certificates=False,**kwargs):
|
def _fetch_http(url,max_size=None,timeout=DEFAULT_TIMEOUT,accept_bad_ssl_certificates=False,**kwargs):
|
||||||
|
if not _DO_HTTP: return None
|
||||||
def too_large_error(url,length,max_size):
|
def too_large_error(url,length,max_size):
|
||||||
err = "Size of %s is %s Mo\n"%(url,length)
|
err = "Size of %s is %s Mo\n"%(url,length)
|
||||||
err += "Offpunk only download automatically content under %s Mo\n" %(max_size/1000000)
|
err += "Offpunk only download automatically content under %s Mo\n" %(max_size/1000000)
|
||||||
|
@ -782,7 +787,10 @@ def fetch(url,offline=False,download_image_first=True,images_mode="readable",val
|
||||||
print("%s is not a supported protocol"%scheme)
|
print("%s is not a supported protocol"%scheme)
|
||||||
path = None
|
path = None
|
||||||
elif scheme in ("http","https"):
|
elif scheme in ("http","https"):
|
||||||
path=_fetch_http(url,**kwargs)
|
if _DO_HTTP:
|
||||||
|
path=_fetch_http(url,**kwargs)
|
||||||
|
else:
|
||||||
|
print("HTTP requires python-requests")
|
||||||
elif scheme == "gopher":
|
elif scheme == "gopher":
|
||||||
path=_fetch_gopher(url,**kwargs)
|
path=_fetch_gopher(url,**kwargs)
|
||||||
elif scheme == "finger":
|
elif scheme == "finger":
|
||||||
|
@ -815,13 +823,13 @@ def fetch(url,offline=False,download_image_first=True,images_mode="readable",val
|
||||||
print("""ERROR5: Trying to create a directory which already exists
|
print("""ERROR5: Trying to create a directory which already exists
|
||||||
in the cache : """)
|
in the cache : """)
|
||||||
print(err)
|
print(err)
|
||||||
elif isinstance(err,requests.exceptions.SSLError):
|
elif _DO_HTTP and isinstance(err,requests.exceptions.SSLError):
|
||||||
if print_error:
|
if print_error:
|
||||||
print("""ERROR6: Bad SSL certificate:\n""")
|
print("""ERROR6: Bad SSL certificate:\n""")
|
||||||
print(err)
|
print(err)
|
||||||
print("""\n If you know what you are doing, you can try to accept bad certificates with the following command:\n""")
|
print("""\n If you know what you are doing, you can try to accept bad certificates with the following command:\n""")
|
||||||
print("""set accept_bad_ssl_certificates True""")
|
print("""set accept_bad_ssl_certificates True""")
|
||||||
elif isinstance(err,requests.exceptions.ConnectionError):
|
elif _DO_HTTP and isinstance(err,requests.exceptions.ConnectionError):
|
||||||
if print_error:
|
if print_error:
|
||||||
print("""ERROR7: Cannot connect to URL:\n""")
|
print("""ERROR7: Cannot connect to URL:\n""")
|
||||||
print(str(err))
|
print(str(err))
|
||||||
|
|
14
offpunk.py
14
offpunk.py
|
@ -36,11 +36,6 @@ try:
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
_HAS_SETPROCTITLE = False
|
_HAS_SETPROCTITLE = False
|
||||||
_HAS_XSEL = shutil.which('xsel')
|
_HAS_XSEL = shutil.which('xsel')
|
||||||
try:
|
|
||||||
import requests
|
|
||||||
_DO_HTTP = True
|
|
||||||
except ModuleNotFoundError:
|
|
||||||
_DO_HTTP = False
|
|
||||||
## }}} end of imports
|
## }}} end of imports
|
||||||
|
|
||||||
# Command abbreviations
|
# Command abbreviations
|
||||||
|
@ -152,7 +147,7 @@ class GeminiClient(cmd.Cmd):
|
||||||
# Sync-only mode is restriced by design
|
# Sync-only mode is restriced by design
|
||||||
self.offline_only = False
|
self.offline_only = False
|
||||||
self.sync_only = False
|
self.sync_only = False
|
||||||
self.support_http = _DO_HTTP
|
self.support_http = netcache._DO_HTTP
|
||||||
self.automatic_choice = "n"
|
self.automatic_choice = "n"
|
||||||
self.client_certs = {
|
self.client_certs = {
|
||||||
"active": None
|
"active": None
|
||||||
|
@ -349,7 +344,8 @@ class GeminiClient(cmd.Cmd):
|
||||||
self._update_history(modedurl)
|
self._update_history(modedurl)
|
||||||
else:
|
else:
|
||||||
#we are asked not to handle or in sync_only mode
|
#we are asked not to handle or in sync_only mode
|
||||||
netcache.fetch(url,**params)
|
if self.support_http or not parsed.scheme in ["http","https"] :
|
||||||
|
netcache.fetch(url,**params)
|
||||||
|
|
||||||
@needs_gi
|
@needs_gi
|
||||||
def _show_lookup(self, offset=0, end=None, show_url=False):
|
def _show_lookup(self, offset=0, end=None, show_url=False):
|
||||||
|
@ -877,7 +873,7 @@ Marks are temporary until shutdown (not saved to disk)."""
|
||||||
output += " - python-cryptography : " + has(netcache._HAS_CRYPTOGRAPHY)
|
output += " - python-cryptography : " + has(netcache._HAS_CRYPTOGRAPHY)
|
||||||
output += " - xdg-open : " + has(opnk._HAS_XDGOPEN)
|
output += " - xdg-open : " + has(opnk._HAS_XDGOPEN)
|
||||||
output += "\nWeb browsing:\n"
|
output += "\nWeb browsing:\n"
|
||||||
output += " - python-requests : " + has(_DO_HTTP)
|
output += " - python-requests : " + has(netcache._DO_HTTP)
|
||||||
output += " - python-feedparser : " + has(ansicat._DO_FEED)
|
output += " - python-feedparser : " + has(ansicat._DO_FEED)
|
||||||
output += " - python-bs4 : " + has(ansicat._HAS_SOUP)
|
output += " - python-bs4 : " + has(ansicat._HAS_SOUP)
|
||||||
output += " - python-readability : " + has(ansicat._HAS_READABILITY)
|
output += " - python-readability : " + has(ansicat._HAS_READABILITY)
|
||||||
|
@ -898,7 +894,7 @@ Marks are temporary until shutdown (not saved to disk)."""
|
||||||
output += " - Render images (python-pil, chafa or timg) : " + has(ansicat._RENDER_IMAGE)
|
output += " - Render images (python-pil, chafa or timg) : " + has(ansicat._RENDER_IMAGE)
|
||||||
output += " - Render HTML (bs4, readability) : " + has(ansicat._DO_HTML)
|
output += " - Render HTML (bs4, readability) : " + has(ansicat._DO_HTML)
|
||||||
output += " - Render Atom/RSS feeds (feedparser) : " + has(ansicat._DO_FEED)
|
output += " - Render Atom/RSS feeds (feedparser) : " + has(ansicat._DO_FEED)
|
||||||
output += " - Connect to http/https (requests) : " + has(_DO_HTTP)
|
output += " - Connect to http/https (requests) : " + has(netcache._DO_HTTP)
|
||||||
output += " - Detect text encoding (python-chardet) : " + has(netcache._HAS_CHARDET)
|
output += " - Detect text encoding (python-chardet) : " + has(netcache._HAS_CHARDET)
|
||||||
output += " - copy to/from clipboard (xsel) : " + has(_HAS_XSEL)
|
output += " - copy to/from clipboard (xsel) : " + has(_HAS_XSEL)
|
||||||
output += " - restore last position (less 572+) : " + has(opnk._LESS_RESTORE_POSITION)
|
output += " - restore last position (less 572+) : " + has(opnk._LESS_RESTORE_POSITION)
|
||||||
|
|
Loading…
Reference in New Issue