Show More
@@ -20,6 +20,8 b' import re' | |||
|
20 | 20 | import sys |
|
21 | 21 | import ast |
|
22 | 22 | from itertools import chain |
|
23 | from urllib.request import urlopen | |
|
24 | from urllib.parse import urlencode | |
|
23 | 25 | |
|
24 | 26 | # Our own packages |
|
25 | 27 | from IPython.core.error import TryNext, StdinNotImplementedError, UsageError |
@@ -244,7 +246,7 b' class CodeMagics(Magics):' | |||
|
244 | 246 | |
|
245 | 247 | @line_magic |
|
246 | 248 | def pastebin(self, parameter_s=''): |
|
247 |
"""Upload code to |
|
|
249 | """Upload code to dpaste's paste bin, returning the URL. | |
|
248 | 250 | |
|
249 | 251 | Usage:\\ |
|
250 | 252 | %pastebin [-d "Custom description"] 1-7 |
@@ -265,25 +267,14 b' class CodeMagics(Magics):' | |||
|
265 | 267 | print(e.args[0]) |
|
266 | 268 | return |
|
267 | 269 | |
|
268 | # Deferred import | |
|
269 | try: | |
|
270 | from urllib.request import urlopen # Py 3 | |
|
271 | except ImportError: | |
|
272 | from urllib2 import urlopen | |
|
273 | import json | |
|
274 | post_data = json.dumps({ | |
|
275 | "description": opts.get('d', "Pasted from IPython"), | |
|
276 | "public": True, | |
|
277 | "files": { | |
|
278 | "file1.py": { | |
|
270 | post_data = urlencode({ | |
|
271 | "title": opts.get('d', "Pasted from IPython"), | |
|
272 | "syntax": "python3", | |
|
279 | 273 |
|
|
280 | } | |
|
281 | } | |
|
282 | 274 | }).encode('utf-8') |
|
283 | 275 | |
|
284 |
response = urlopen("http |
|
|
285 | response_data = json.loads(response.read().decode('utf-8')) | |
|
286 | return response_data['html_url'] | |
|
276 | response = urlopen("http://dpaste.com/api/v2/", post_data) | |
|
277 | return response.headers.get('Location') | |
|
287 | 278 | |
|
288 | 279 | @line_magic |
|
289 | 280 | def loadpy(self, arg_s): |
General Comments 0
You need to be logged in to leave comments.
Login now