Skip to content

Commit

Permalink
Merge pull request #11183 from meeseeksmachine/auto-backport-of-pr-11…
Browse files Browse the repository at this point in the history
…182-on-6.x

Backport PR #11182 on branch 6.x
  • Loading branch information
takluyver committed Jun 10, 2018
2 parents 2571564 + c74fedc commit 974ad2b
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions IPython/core/magics/code.py
Expand Up @@ -20,6 +20,8 @@
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
Expand Down Expand Up @@ -244,7 +246,7 @@ def save(self, parameter_s=''):

@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
Expand All @@ -265,25 +267,14 @@ def pastebin(self, parameter_s=''):
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):
Expand Down

0 comments on commit 974ad2b

Please sign in to comment.