diff --git a/IPython/core/magics/code.py b/IPython/core/magics/code.py index d16a569..8a718ae 100644 --- a/IPython/core/magics/code.py +++ b/IPython/core/magics/code.py @@ -20,6 +20,8 @@ import re import sys import ast from itertools import chain +from urllib.request import urlopen +from urllib.parse import urlencode # Our own packages from IPython.core.error import TryNext, StdinNotImplementedError, UsageError @@ -244,7 +246,7 @@ class CodeMagics(Magics): @line_magic def pastebin(self, parameter_s=''): - """Upload code to Github's Gist paste bin, returning the URL. + """Upload code to dpaste's paste bin, returning the URL. Usage:\\ %pastebin [-d "Custom description"] 1-7 @@ -265,25 +267,14 @@ class CodeMagics(Magics): print(e.args[0]) return - # Deferred import - try: - from urllib.request import urlopen # Py 3 - except ImportError: - from urllib2 import urlopen - import json - post_data = json.dumps({ - "description": opts.get('d', "Pasted from IPython"), - "public": True, - "files": { - "file1.py": { - "content": code - } - } + post_data = urlencode({ + "title": opts.get('d', "Pasted from IPython"), + "syntax": "python3", + "content": code }).encode('utf-8') - response = urlopen("https://api.github.com/gists", post_data) - response_data = json.loads(response.read().decode('utf-8')) - return response_data['html_url'] + response = urlopen("http://dpaste.com/api/v2/", post_data) + return response.headers.get('Location') @line_magic def loadpy(self, arg_s):