Show More
@@ -21,6 +21,7 b' import bdb' | |||||
21 | import inspect |
|
21 | import inspect | |
22 | import imp |
|
22 | import imp | |
23 | import io |
|
23 | import io | |
|
24 | import json | |||
24 | import os |
|
25 | import os | |
25 | import sys |
|
26 | import sys | |
26 | import shutil |
|
27 | import shutil | |
@@ -30,7 +31,7 b' import gc' | |||||
30 | from StringIO import StringIO |
|
31 | from StringIO import StringIO | |
31 | from getopt import getopt,GetoptError |
|
32 | from getopt import getopt,GetoptError | |
32 | from pprint import pformat |
|
33 | from pprint import pformat | |
33 |
from |
|
34 | from urllib2 import urlopen | |
34 |
|
35 | |||
35 | # cProfile was added in Python2.5 |
|
36 | # cProfile was added in Python2.5 | |
36 | try: |
|
37 | try: | |
@@ -2231,15 +2232,40 b' Currently the magic system has the following functions:\\n"""' | |||||
2231 | print cmds |
|
2232 | print cmds | |
2232 |
|
2233 | |||
2233 | def magic_pastebin(self, parameter_s = ''): |
|
2234 | def magic_pastebin(self, parameter_s = ''): | |
2234 |
"""Upload code to |
|
2235 | """Upload code to Github's Gist paste bin, returning the URL. | |
|
2236 | ||||
|
2237 | Usage:\\ | |||
|
2238 | %pastebin [-d "Custom description"] 1-7 | |||
|
2239 | ||||
|
2240 | The argument can be an input history range, a filename, or the name of a | |||
|
2241 | string or macro. | |||
|
2242 | ||||
|
2243 | Options: | |||
|
2244 | ||||
|
2245 | -d: Pass a custom description for the gist. The default will say | |||
|
2246 | "Pasted from IPython". | |||
|
2247 | """ | |||
|
2248 | opts, args = self.parse_options(parameter_s, 'd:') | |||
|
2249 | ||||
2235 | try: |
|
2250 | try: | |
2236 |
code = self.shell.find_user_code( |
|
2251 | code = self.shell.find_user_code(args) | |
2237 | except (ValueError, TypeError) as e: |
|
2252 | except (ValueError, TypeError) as e: | |
2238 | print e.args[0] |
|
2253 | print e.args[0] | |
2239 | return |
|
2254 | return | |
2240 | pbserver = ServerProxy('http://paste.pocoo.org/xmlrpc/') |
|
2255 | ||
2241 | id = pbserver.pastes.newPaste("python", code) |
|
2256 | post_data = json.dumps({ | |
2242 | return "http://paste.pocoo.org/show/" + id |
|
2257 | "description": opts.get('d', "Pasted from IPython"), | |
|
2258 | "public": True, | |||
|
2259 | "files": { | |||
|
2260 | "file1.py": { | |||
|
2261 | "content": code | |||
|
2262 | } | |||
|
2263 | } | |||
|
2264 | }).encode('utf-8') | |||
|
2265 | ||||
|
2266 | response = urlopen("https://api.github.com/gists", post_data) | |||
|
2267 | response_data = json.loads(response.read().decode('utf-8')) | |||
|
2268 | return response_data['html_url'] | |||
2243 |
|
2269 | |||
2244 | def magic_loadpy(self, arg_s): |
|
2270 | def magic_loadpy(self, arg_s): | |
2245 | """Load a .py python script into the GUI console. |
|
2271 | """Load a .py python script into the GUI console. |
General Comments 0
You need to be logged in to leave comments.
Login now