diff --git a/CHANGELOG b/CHANGELOG index 2425e6a96..3f410525d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +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. 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: 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..ec29a6da5 100644 --- a/bpython/paste.py +++ b/bpython/paste.py @@ -40,35 +40,29 @@ 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..f966b3faa 100644 --- a/bpython/repl.py +++ b/bpython/repl.py @@ -475,10 +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_show_url, - self.config.pastebin_removal_url, + self.config.pastebin_url, self.config.pastebin_expiry, ) @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 ^^^^^^^^^^^^^^