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