gusmobile

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

commit c8867e2a90165958ae58e444791c0003329c6501
parent 676c60b98528669c8a6befcf62f6fd76f46bfbd8
Author: Natalie Pendragon <natpen@natpen.net>
Date:   Wed,  3 Jun 2020 16:11:03 -0400

Return charset

Diffstat:
Mgusmobile/client.py | 10+++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/gusmobile/client.py b/gusmobile/client.py @@ -39,16 +39,18 @@ GEMINI_TIMEOUT = 15 class Response: content = None content_type = None + charset = None url = None status = None status_meta = None prompt = None def __init__( - self, content=None, content_type=None, url=None, status=None, status_meta=None, prompt=None + self, content=None, content_type=None, charset=None, url=None, status=None, status_meta=None, prompt=None ): self.content = content self.content_type = content_type + self.charset = charset self.url = url self.status = status self.status_meta = status_meta @@ -148,7 +150,8 @@ def fetch(raw_url): if mime == "": mime = "text/gemini; charset=utf-8" mime, mime_options = cgi.parse_header(mime) - charset = "utf-8" + default_charset = "utf-8" + charset = None if "charset" in mime_options: try: codecs.lookup(mime_options["charset"]) @@ -164,7 +167,7 @@ def fetch(raw_url): return if mime.startswith("text/"): try: - content = codecs.decode(body, charset) + content = codecs.decode(body, charset or default_charset) except: # print("ERROR: problem decoding content with %s charset" % charset) return @@ -173,6 +176,7 @@ def fetch(raw_url): return Response( content=content, content_type=mime, + charset=charset, url=url.geturl(), status=status, )