Skip to content

Commit ad855aa

Browse files
committed
Use the new pinnwand JSON API.
1 parent e4a88c2 commit ad855aa

File tree

4 files changed

+17
-40
lines changed

4 files changed

+17
-40
lines changed

bpython/config.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ def loadini(struct, configfile):
8181
"pastebin_confirm": True,
8282
"pastebin_expiry": "1week",
8383
"pastebin_helper": "",
84-
"pastebin_removal_url": "https://bpaste.net/remove/$removal_id",
85-
"pastebin_show_url": "https://bpaste.net/show/$paste_id",
86-
"pastebin_url": "https://bpaste.net/json/new",
84+
"pastebin_url": "https://bpaste.net",
8785
"save_append_py": False,
8886
"single_undo_time": 1.0,
8987
"syntax": True,
@@ -224,8 +222,6 @@ def get_key_no_doublebind(command):
224222

225223
struct.pastebin_confirm = config.getboolean("general", "pastebin_confirm")
226224
struct.pastebin_url = config.get("general", "pastebin_url")
227-
struct.pastebin_show_url = config.get("general", "pastebin_show_url")
228-
struct.pastebin_removal_url = config.get("general", "pastebin_removal_url")
229225
struct.pastebin_expiry = config.get("general", "pastebin_expiry")
230226
struct.pastebin_helper = config.get("general", "pastebin_helper")
231227

bpython/paste.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,31 @@ class PasteFailed(Exception):
4040

4141

4242
class PastePinnwand(object):
43-
def __init__(self, url, expiry, show_url, removal_url):
43+
def __init__(self, url, expiry):
4444
self.url = url
4545
self.expiry = expiry
46-
self.show_url = show_url
47-
self.removal_url = removal_url
4846

4947
def paste(self, s):
5048
"""Upload to pastebin via json interface."""
5149

52-
url = urljoin(self.url, "/json/new")
53-
payload = {"code": s, "lexer": "pycon", "expiry": self.expiry}
50+
url = urljoin(self.url, "/api/v1/paste")
51+
payload = {
52+
"expiry": self.expiry,
53+
"files": [
54+
{"lexer": "pycon", "content": s}
55+
],
56+
}
5457

5558
try:
56-
response = requests.post(url, data=payload, verify=True)
59+
response = requests.post(url, json=payload, verify=True)
5760
response.raise_for_status()
5861
except requests.exceptions.RequestException as exc:
5962
raise PasteFailed(exc.message)
6063

6164
data = response.json()
6265

63-
paste_url_template = Template(self.show_url)
64-
paste_id = urlquote(data["paste_id"])
65-
paste_url = paste_url_template.safe_substitute(paste_id=paste_id)
66-
67-
removal_url_template = Template(self.removal_url)
68-
removal_id = urlquote(data["removal_id"])
69-
removal_url = removal_url_template.safe_substitute(
70-
removal_id=removal_id
71-
)
66+
paste_url = data["link"]
67+
removal_url = data["removal"]
7268

7369
return (paste_url, removal_url)
7470

bpython/repl.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,6 @@ def __init__(self, interp, config):
477477
self.paster = PastePinnwand(
478478
self.config.pastebin_url,
479479
self.config.pastebin_expiry,
480-
self.config.pastebin_show_url,
481-
self.config.pastebin_removal_url,
482480
)
483481

484482
@property

doc/sphinx/source/configuration-options.rst

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,9 @@ pastebin_helper
9191
^^^^^^^^^^^^^^^
9292

9393
The name of a helper executable that should perform pastebin upload on bpython's
94-
behalf. If set, this overrides `pastebin_url`. It also overrides
95-
`pastebin_show_url`, as the helper is expected to return the full URL to the
96-
pastebin as the first word of its output. The data is supplied to the helper via
97-
STDIN.
94+
behalf. If set, this overrides `pastebin_url`. The helper is expected to return
95+
the full URL to the pastebin as the first word of its output. The data is
96+
supplied to the helper via STDIN.
9897

9998
An example helper program is ``pastebinit``, available for most systems. The
10099
following helper program can be used to create `gists
@@ -141,23 +140,11 @@ following helper program can be used to create `gists
141140
142141
.. versionadded:: 0.12
143142

144-
pastebin_show_url
145-
^^^^^^^^^^^^^^^^^
146-
The url under which the new paste can be reached. ``$paste_id`` will be replaced
147-
by the ID of the new paste (default: https://bpaste.net/show/$paste_id/).
148-
149-
pastebin_removal_url
150-
^^^^^^^^^^^^^^^^^^^^
151-
The url under which a paste can be removed. ``$removal_id`` will be replaced by
152-
the removal ID of the paste (default: https://bpaste.net/remova/$removal_id/).
153-
154-
.. versionadded:: 0.14
155-
156143
pastebin_url
157144
^^^^^^^^^^^^
158145
The pastebin url to post to (without a trailing slash). This pastebin has to be
159-
a pastebin which uses provides a similar interface to ``bpaste.net``'s JSON
160-
interface (default: https://bpaste.net/json/new).
146+
a pastebin which provides a similar interface to ``bpaste.net``'s JSON
147+
interface (default: https://bpaste.net).
161148

162149
save_append_py
163150
^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)