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 | |
@@ -255,7 +256,7 b' class CodeMagics(Magics):' | |||||
255 |
|
256 | |||
256 | Options: |
|
257 | Options: | |
257 |
|
258 | |||
258 |
-d: Pass a custom description |
|
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:') | |
@@ -268,11 +269,13 b' class CodeMagics(Magics):' | |||||
268 |
|
269 | |||
269 | post_data = urlencode({ |
|
270 | post_data = urlencode({ | |
270 | "title": opts.get('d', "Pasted from IPython"), |
|
271 | "title": opts.get('d', "Pasted from IPython"), | |
271 |
"syntax": "python |
|
272 | "syntax": "python", | |
272 | "content": code |
|
273 | "content": code | |
273 | }).encode('utf-8') |
|
274 | }).encode('utf-8') | |
274 |
|
275 | |||
275 |
re |
|
276 | request = Request("http://dpaste.com/api/v2/", | |
|
277 | headers={"User-Agent": "IPython v{}".format(version)}) | |||
|
278 | response = urlopen(request, post_data) | |||
276 | return response.headers.get('Location') |
|
279 | return response.headers.get('Location') | |
277 |
|
280 | |||
278 | @line_magic |
|
281 | @line_magic |
General Comments 0
You need to be logged in to leave comments.
Login now