diff options
| author | Zach DeCook <zachdecook@librem.one> | 2023-01-14 14:53:31 -0500 |
|---|---|---|
| committer | Zach DeCook <zachdecook@librem.one> | 2023-01-14 14:53:31 -0500 |
| commit | 03c758af3eaebd6b7c18e1e595d49b0552eb5278 (patch) | |
| tree | 45dffb292dbfadd1775b4d8a5e5e2a9049f177c6 | |
| parent | 67bccc9e1a39ac2749806a37cb53b23322645083 (diff) | |
| download | browset-03c758af3eaebd6b7c18e1e595d49b0552eb5278.tar.gz | |
browset: Support data protocol
| -rwxr-xr-x | browset.py | 11 | ||||
| -rw-r--r-- | protocol/data.py | 9 |
2 files changed, 19 insertions, 1 deletions
diff --git a/browset.py b/browset.py index 37e04b1..292b95d 100755 --- a/browset.py +++ b/browset.py @@ -8,6 +8,7 @@ from mime.gemtext import Gemtext from mime.plaintext import Plaintext from mime.highlightedcode import HighlightedCode,mimetolexer from protocol.gemini import GeminiProtocol +from protocol.data import DataProtocol class Browset(App): url = "" @@ -69,8 +70,16 @@ class Browset(App): if histore: self.history.append(self.url) self.url = url - (mime, fp) = GeminiProtocol.get(url) + protocol = url.split(":")[0] + if protocol == "gemini": + (mime, fp) = GeminiProtocol.get(url) + elif protocol == "data": + (mime, fp) = DataProtocol.get(url) + else: + (mime, fp) = ("error", ["Unsupported protocol: " + protocol]) + self.query_one("#content").remove() + if "text/gemini" in mime: content = Gemtext(fp=fp, id="content") elif mime in mimetolexer: diff --git a/protocol/data.py b/protocol/data.py new file mode 100644 index 0000000..a732d14 --- /dev/null +++ b/protocol/data.py @@ -0,0 +1,9 @@ +from base64 import b64decode +class DataProtocol(): + def get(url): + mime = url.split(':')[1].split(',')[0].split(';')[0] + base64 = 'base64' in url.split(',')[0].split(';') + content = ','.join(url.split(',')[1:]) + if base64: + content = b64decode(content) + return (mime or 'text/plain', [content]) |
