diff options
-rw-r--r-- | pypaste/client/__init__.py | 3 | ||||
-rw-r--r-- | pypaste/client/__main__.py | 8 | ||||
-rw-r--r-- | pypaste/client/plugins/pgz/__init__.py | 4 | ||||
-rw-r--r-- | pypaste/client/plugins/zen/__init__.py | 5 |
4 files changed, 12 insertions, 8 deletions
diff --git a/pypaste/client/__init__.py b/pypaste/client/__init__.py index 28582ac..0456110 100644 --- a/pypaste/client/__init__.py +++ b/pypaste/client/__init__.py @@ -1,10 +1,9 @@ -import io from typing import Protocol, List, Optional class PasteService(Protocol): - def paste(self, buffer: io.BytesIO, syntax: Optional[str], raw: bool) -> str: + def paste(self, text: str, syntax: Optional[str], raw: bool) -> str: pass def supported_syntaxes(self) -> List[str]: diff --git a/pypaste/client/__main__.py b/pypaste/client/__main__.py index dc6172a..a1b5f53 100644 --- a/pypaste/client/__main__.py +++ b/pypaste/client/__main__.py @@ -53,7 +53,13 @@ def main() -> int: return 1 try: - url = service.paste(sys.stdin.buffer, syntax, args.raw) + text = sys.stdin.read() + except UnicodeError: + print("failed to decode stdin", file=sys.stderr) + return 1 + + try: + url = service.paste(text, syntax, args.raw) except Exception as e: print(e) return 1 diff --git a/pypaste/client/plugins/pgz/__init__.py b/pypaste/client/plugins/pgz/__init__.py index fd7720c..834ae96 100644 --- a/pypaste/client/plugins/pgz/__init__.py +++ b/pypaste/client/plugins/pgz/__init__.py @@ -9,8 +9,8 @@ URL: str = "https://paste.gentoo.zip" @register_service("pgz") class Pgz: - def paste(self, buffer: io.BytesIO, syntax: Optional[str], raw: bool) -> str: - files = {"file": ("pypaste-upload", buffer, "multipart/form-data")} + def paste(self, text: str, syntax: Optional[str], raw: bool) -> str: + files = {"file": ("pypaste-upload", io.StringIO(text), "multipart/form-data")} req = requests.post(URL, files=files) diff --git a/pypaste/client/plugins/zen/__init__.py b/pypaste/client/plugins/zen/__init__.py index 6ef8348..53a4673 100644 --- a/pypaste/client/plugins/zen/__init__.py +++ b/pypaste/client/plugins/zen/__init__.py @@ -1,4 +1,3 @@ -import io import requests from pypaste.client.plugins import register_service from typing import Optional, List @@ -614,7 +613,7 @@ URL: str = "https://zen.jturnerusa.dev/paste" @register_service("zen") class Zen: - def paste(self, buffer: io.BytesIO, syntax: Optional[str], raw: bool) -> str: + def paste(self, text: str, syntax: Optional[str], raw: bool) -> str: params = {} if syntax is not None: @@ -623,7 +622,7 @@ class Zen: if raw: params["raw"] = "true" - req = requests.post(URL, params=params, data=buffer) + req = requests.post(URL, params=params, data=text) if req.status_code != 200: raise Exception( |