##// END OF EJS Templates
Merge pull request #12712 from pbx/dpaste-api-correction...
Matthias Bussonnier -
r26400:b0383f72 merge
parent child Browse files
Show More
@@ -20,7 +20,7 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
23 from urllib.request import Request, urlopen
24 from urllib.parse import urlencode
24 from urllib.parse import urlencode
25 from pathlib import Path
25 from pathlib import Path
26
26
@@ -29,6 +29,7 b' from IPython.core.error import TryNext, StdinNotImplementedError, UsageError'
29 from IPython.core.macro import Macro
29 from IPython.core.macro import Macro
30 from IPython.core.magic import Magics, magics_class, line_magic
30 from IPython.core.magic import Magics, magics_class, line_magic
31 from IPython.core.oinspect import find_file, find_source_lines
31 from IPython.core.oinspect import find_file, find_source_lines
32 from IPython.core.release import version
32 from IPython.testing.skipdoctest import skip_doctest
33 from IPython.testing.skipdoctest import skip_doctest
33 from IPython.utils.contexts import preserve_keys
34 from IPython.utils.contexts import preserve_keys
34 from IPython.utils.path import get_py_filename
35 from IPython.utils.path import get_py_filename
@@ -245,7 +246,7 b' class CodeMagics(Magics):'
245
246
246 @line_magic
247 @line_magic
247 def pastebin(self, parameter_s=''):
248 def pastebin(self, parameter_s=''):
248 """Upload code to dpaste's paste bin, returning the URL.
249 """Upload code to dpaste.com, returning the URL.
249
250
250 Usage:\\
251 Usage:\\
251 %pastebin [-d "Custom description"] 1-7
252 %pastebin [-d "Custom description"] 1-7
@@ -255,7 +256,7 b' class CodeMagics(Magics):'
255
256
256 Options:
257 Options:
257
258
258 -d: Pass a custom description for the gist. The default will say
259 -d: Pass a custom description. The default will say
259 "Pasted from IPython".
260 "Pasted from IPython".
260 """
261 """
261 opts, args = self.parse_options(parameter_s, 'd:')
262 opts, args = self.parse_options(parameter_s, 'd:')
@@ -266,13 +267,19 b' class CodeMagics(Magics):'
266 print(e.args[0])
267 print(e.args[0])
267 return
268 return
268
269
269 post_data = urlencode({
270 post_data = urlencode(
270 "title": opts.get('d', "Pasted from IPython"),
271 {
271 "syntax": "python3",
272 "title": opts.get("d", "Pasted from IPython"),
272 "content": code
273 "syntax": "python",
273 }).encode('utf-8')
274 "content": code,
274
275 }
275 response = urlopen("http://dpaste.com/api/v2/", post_data)
276 ).encode("utf-8")
277
278 request = Request(
279 "http://dpaste.com/api/v2/",
280 headers={"User-Agent": "IPython v{}".format(version)},
281 )
282 response = urlopen(request, post_data)
276 return response.headers.get('Location')
283 return response.headers.get('Location')
277
284
278 @line_magic
285 @line_magic
General Comments 0
You need to be logged in to leave comments. Login now