Skip to content

Pinnwand api v1 #800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
6 changes: 1 addition & 5 deletions bpython/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")

Expand Down
24 changes: 9 additions & 15 deletions bpython/paste.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 1 addition & 4 deletions bpython/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 5 additions & 18 deletions doc/sphinx/source/configuration-options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
^^^^^^^^^^^^^^
Expand Down