From ad855aa4dd99cef3b81ea9d7357c668aa2bf46ff Mon Sep 17 00:00:00 2001 From: supakeen Date: Thu, 26 Mar 2020 20:31:52 +0000 Subject: [PATCH 1/3] Use the new pinnwand JSON API. --- bpython/config.py | 6 +---- bpython/paste.py | 26 +++++++++------------ bpython/repl.py | 2 -- doc/sphinx/source/configuration-options.rst | 23 ++++-------------- 4 files changed, 17 insertions(+), 40 deletions(-) diff --git a/bpython/config.py b/bpython/config.py index 456479b7a..f074fb745 100644 --- a/bpython/config.py +++ b/bpython/config.py @@ -81,9 +81,7 @@ def loadini(struct, configfile): "pastebin_confirm": True, "pastebin_expiry": "1week", "pastebin_helper": "", - "pastebin_removal_url": "https://bpaste.net/remove/$removal_id", - "pastebin_show_url": "https://bpaste.net/show/$paste_id", - "pastebin_url": "https://bpaste.net/json/new", + "pastebin_url": "https://bpaste.net", "save_append_py": False, "single_undo_time": 1.0, "syntax": True, @@ -224,8 +222,6 @@ def get_key_no_doublebind(command): struct.pastebin_confirm = config.getboolean("general", "pastebin_confirm") struct.pastebin_url = config.get("general", "pastebin_url") - struct.pastebin_show_url = config.get("general", "pastebin_show_url") - struct.pastebin_removal_url = config.get("general", "pastebin_removal_url") struct.pastebin_expiry = config.get("general", "pastebin_expiry") struct.pastebin_helper = config.get("general", "pastebin_helper") diff --git a/bpython/paste.py b/bpython/paste.py index b68e9688b..5bc30968c 100644 --- a/bpython/paste.py +++ b/bpython/paste.py @@ -40,35 +40,31 @@ class PasteFailed(Exception): class PastePinnwand(object): - def __init__(self, url, expiry, show_url, removal_url): + def __init__(self, url, expiry): self.url = url self.expiry = expiry - self.show_url = show_url - self.removal_url = removal_url def paste(self, s): """Upload to pastebin via json interface.""" - url = urljoin(self.url, "/json/new") - payload = {"code": s, "lexer": "pycon", "expiry": self.expiry} + url = urljoin(self.url, "/api/v1/paste") + payload = { + "expiry": self.expiry, + "files": [ + {"lexer": "pycon", "content": s} + ], + } try: - response = requests.post(url, data=payload, verify=True) + response = requests.post(url, json=payload, verify=True) response.raise_for_status() except requests.exceptions.RequestException as exc: raise PasteFailed(exc.message) data = response.json() - paste_url_template = Template(self.show_url) - paste_id = urlquote(data["paste_id"]) - paste_url = paste_url_template.safe_substitute(paste_id=paste_id) - - removal_url_template = Template(self.removal_url) - removal_id = urlquote(data["removal_id"]) - removal_url = removal_url_template.safe_substitute( - removal_id=removal_id - ) + paste_url = data["link"] + removal_url = data["removal"] return (paste_url, removal_url) diff --git a/bpython/repl.py b/bpython/repl.py index cfac71244..c3ce0bb08 100644 --- a/bpython/repl.py +++ b/bpython/repl.py @@ -477,8 +477,6 @@ def __init__(self, interp, config): self.paster = PastePinnwand( self.config.pastebin_url, self.config.pastebin_expiry, - self.config.pastebin_show_url, - self.config.pastebin_removal_url, ) @property diff --git a/doc/sphinx/source/configuration-options.rst b/doc/sphinx/source/configuration-options.rst index c51eb7efd..b1eeb068a 100644 --- a/doc/sphinx/source/configuration-options.rst +++ b/doc/sphinx/source/configuration-options.rst @@ -91,10 +91,9 @@ pastebin_helper ^^^^^^^^^^^^^^^ The name of a helper executable that should perform pastebin upload on bpython's -behalf. If set, this overrides `pastebin_url`. It also overrides -`pastebin_show_url`, as the helper is expected to return the full URL to the -pastebin as the first word of its output. The data is supplied to the helper via -STDIN. +behalf. If set, this overrides `pastebin_url`. The helper is expected to return +the full URL to the pastebin as the first word of its output. The data is +supplied to the helper via STDIN. An example helper program is ``pastebinit``, available for most systems. The following helper program can be used to create `gists @@ -141,23 +140,11 @@ following helper program can be used to create `gists .. versionadded:: 0.12 -pastebin_show_url -^^^^^^^^^^^^^^^^^ -The url under which the new paste can be reached. ``$paste_id`` will be replaced -by the ID of the new paste (default: https://bpaste.net/show/$paste_id/). - -pastebin_removal_url -^^^^^^^^^^^^^^^^^^^^ -The url under which a paste can be removed. ``$removal_id`` will be replaced by -the removal ID of the paste (default: https://bpaste.net/remova/$removal_id/). - -.. versionadded:: 0.14 - pastebin_url ^^^^^^^^^^^^ The pastebin url to post to (without a trailing slash). This pastebin has to be -a pastebin which uses provides a similar interface to ``bpaste.net``'s JSON -interface (default: https://bpaste.net/json/new). +a pastebin which provides a similar interface to ``bpaste.net``'s JSON +interface (default: https://bpaste.net). save_append_py ^^^^^^^^^^^^^^ From 74fe1a9b7189fcb663375b879a85f72d71a5e2b3 Mon Sep 17 00:00:00 2001 From: supakeen Date: Thu, 26 Mar 2020 20:32:43 +0000 Subject: [PATCH 2/3] Use the new `pinnwand` API. --- CHANGELOG | 1 + bpython/paste.py | 4 +--- bpython/repl.py | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2425e6a96..133dbc17e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,7 @@ General information: * Usage in combination with Python 2 has been deprecated. This does not mean that support is dropped instantly but rather that at some point in the future we will stop running our testcases against Python 2. +* The new pinnwand API is used for the pastebin functionality. New features: diff --git a/bpython/paste.py b/bpython/paste.py index 5bc30968c..ec29a6da5 100644 --- a/bpython/paste.py +++ b/bpython/paste.py @@ -50,9 +50,7 @@ def paste(self, s): url = urljoin(self.url, "/api/v1/paste") payload = { "expiry": self.expiry, - "files": [ - {"lexer": "pycon", "content": s} - ], + "files": [{"lexer": "pycon", "content": s}], } try: diff --git a/bpython/repl.py b/bpython/repl.py index c3ce0bb08..f966b3faa 100644 --- a/bpython/repl.py +++ b/bpython/repl.py @@ -475,8 +475,7 @@ def __init__(self, interp, config): self.paster = PasteHelper(self.config.pastebin_helper) else: self.paster = PastePinnwand( - self.config.pastebin_url, - self.config.pastebin_expiry, + self.config.pastebin_url, self.config.pastebin_expiry, ) @property From 949c633e3350ebb653fcbbce6e0e9df3b7d9c584 Mon Sep 17 00:00:00 2001 From: supakeen Date: Sun, 29 Mar 2020 20:48:20 +0200 Subject: [PATCH 3/3] Mention removed configuration options. --- CHANGELOG | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 133dbc17e..3f410525d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,7 +10,10 @@ General information: * Usage in combination with Python 2 has been deprecated. This does not mean that support is dropped instantly but rather that at some point in the future we will stop running our testcases against Python 2. -* The new pinnwand API is used for the pastebin functionality. +* The new pinnwand API is used for the pastebin functionality. We have dropped + two configuration options: `pastebin_show_url` and `pastebin_removal_url`. If + you have your bpython configured to run against an old version of `pinnwand` + please update it. New features: