gusmobile

Unnamed repository; edit this file 'description' to name the repository.
git clone git://code.clttr.info/gusmobile.git
Log | Files | Refs | LICENSE

commit 72e639c07d06c48c5b545d238e35e406c1aece89
parent ef7315f7d2719b452bdd412d560bd5875ae68b8d
Author: Natalie Pendragon <natpen@natpen.net>
Date:   Sun, 23 Feb 2020 09:46:46 -0500

Hack client to work with GUS v1

Diffstat:
Mgusmobile/client.py | 31+++++++++++++++++++++++++------
Msetup.py | 6+-----
2 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/gusmobile/client.py b/gusmobile/client.py @@ -56,7 +56,7 @@ class Response: def fetch(url): # Do everything which touches the network in one block, # so we only need to catch exceptions once - url = urllib.parse.urlparse(url) + url = urllib.parse.urlparse(url, 'gemini') header = "" try: # Is this a local file? @@ -74,15 +74,19 @@ def fetch(url): # Print an error message if isinstance(err, socket.gaierror): print("ERROR: DNS error!") + return elif isinstance(err, ConnectionRefusedError): print("ERROR: Connection refused!") + return elif isinstance(err, ConnectionResetError): print("ERROR: Connection reset!") + return elif isinstance(err, (TimeoutError, socket.timeout)): print( """ERROR: Connection timed out! Slow internet connection? Use 'set timeout' to be more patient.""" ) + return else: print("ERROR: " + str(err)) return @@ -94,17 +98,26 @@ def fetch(url): return # Handle headers. Not all headers are handled yet. + # Input if status.startswith("1"): raise NotImplementedError() # Redirects elif status.startswith("3"): - raise NotImplementedError() + # print("REDIRECT: %s" % meta) + return Response( + content=None, + content_type=None, + url=urllib.parse.urlparse(meta).geturl(), + status=status, + ) # Errors elif status.startswith("4") or status.startswith("5"): - raise NotImplementedError() + print("ERROR: %s" % status) + return # Client cert elif status.startswith("6"): - raise NotImplementedError() + print("ERROR: The requested resource requires client-certificate") + return # Invalid status elif not status.startswith("2"): print("ERROR: Server returned undefined status code %s!" % status) @@ -126,8 +139,13 @@ def fetch(url): return # Read the response body over the network body = f.read() + try: + content = codecs.decode(body, charset) + except: + # print("ERROR: problem decoding content with %s charset" % charset) + return return Response( - content=codecs.decode(body, charset), + content=content, content_type=mime, url=url.geturl(), status=status, @@ -137,7 +155,8 @@ def fetch(url): def _send_request(url): """Send a selector to a given host and port. Returns the resolved address and binary file with the reply.""" - addresses = _get_addresses(url.hostname, url.port) + port = url.port if url.port is not None else 1965 + addresses = _get_addresses(url.hostname, port) # Connect to remote host by any address possible err = None for address in addresses: diff --git a/setup.py b/setup.py @@ -2,10 +2,6 @@ import os from setuptools import setup -def read(fname): - return os.open(os.path.join(os.path.dirname(__file__), fname)).read() - - setup( name="gusmobile", version="0.1.0", @@ -18,7 +14,7 @@ setup( keywords="gemini client internet", url="https://git.carcosa.net/jmcbray/gusmobile/", packages=["gusmobile", "tests"], - long_description=read("README.rst"), + long_description="gemini client lib", classifiers=[ "Development Status :: 3 - Alpha", "Intended Audience :: Developers",