Show More
@@ -20,7 +20,7 b' import re' | |||
|
20 | 20 | import sys |
|
21 | 21 | import ast |
|
22 | 22 | from itertools import chain |
|
23 | from urllib.request import urlopen | |
|
23 | from urllib.request import Request, urlopen | |
|
24 | 24 | from urllib.parse import urlencode |
|
25 | 25 | |
|
26 | 26 | # Our own packages |
@@ -28,6 +28,7 b' from IPython.core.error import TryNext, StdinNotImplementedError, UsageError' | |||
|
28 | 28 | from IPython.core.macro import Macro |
|
29 | 29 | from IPython.core.magic import Magics, magics_class, line_magic |
|
30 | 30 | from IPython.core.oinspect import find_file, find_source_lines |
|
31 | from IPython.core.release import version | |
|
31 | 32 | from IPython.testing.skipdoctest import skip_doctest |
|
32 | 33 | from IPython.utils.contexts import preserve_keys |
|
33 | 34 | from IPython.utils.path import get_py_filename |
@@ -244,7 +245,7 b' class CodeMagics(Magics):' | |||
|
244 | 245 | |
|
245 | 246 | @line_magic |
|
246 | 247 | def pastebin(self, parameter_s=''): |
|
247 |
"""Upload code to dpaste |
|
|
248 | """Upload code to dpaste.com, returning the URL. | |
|
248 | 249 | |
|
249 | 250 | Usage:\\ |
|
250 | 251 | %pastebin [-d "Custom description"] 1-7 |
@@ -254,7 +255,7 b' class CodeMagics(Magics):' | |||
|
254 | 255 | |
|
255 | 256 | Options: |
|
256 | 257 | |
|
257 |
-d: Pass a custom description |
|
|
258 | -d: Pass a custom description. The default will say | |
|
258 | 259 | "Pasted from IPython". |
|
259 | 260 | """ |
|
260 | 261 | opts, args = self.parse_options(parameter_s, 'd:') |
@@ -265,13 +266,19 b' class CodeMagics(Magics):' | |||
|
265 | 266 | print(e.args[0]) |
|
266 | 267 | return |
|
267 | 268 | |
|
268 |
post_data = urlencode( |
|
|
269 | "title": opts.get('d', "Pasted from IPython"), | |
|
270 | "syntax": "python3", | |
|
271 | "content": code | |
|
272 | }).encode('utf-8') | |
|
273 | ||
|
274 | response = urlopen("http://dpaste.com/api/v2/", post_data) | |
|
269 | post_data = urlencode( | |
|
270 | { | |
|
271 | "title": opts.get("d", "Pasted from IPython"), | |
|
272 | "syntax": "python", | |
|
273 | "content": code, | |
|
274 | } | |
|
275 | ).encode("utf-8") | |
|
276 | ||
|
277 | request = Request( | |
|
278 | "http://dpaste.com/api/v2/", | |
|
279 | headers={"User-Agent": "IPython v{}".format(version)}, | |
|
280 | ) | |
|
281 | response = urlopen(request, post_data) | |
|
275 | 282 | return response.headers.get('Location') |
|
276 | 283 | |
|
277 | 284 | @line_magic |
General Comments 0
You need to be logged in to leave comments.
Login now