##// END OF EJS Templates
Initial implementation of %pastebin magic command.
Thomas Kluyver -
Show More
@@ -2072,6 +2072,26 b' Currently the magic system has the following functions:\\n"""'
2072 f.write(cmds.encode("utf-8"))
2072 f.write(cmds.encode("utf-8"))
2073 print 'The following commands were written to file `%s`:' % fname
2073 print 'The following commands were written to file `%s`:' % fname
2074 print cmds
2074 print cmds
2075
2076 def magic_pastebin(self, parameter_s = ''):
2077 """Upload code to the 'Lodge it' paste bin, returning the URL."""
2078 pbserver = ServerProxy('http://paste.pocoo.org/xmlrpc/')
2079 code = self.extract_input_lines(parameter_s)
2080 if not code:
2081 try:
2082 codeobj = eval(parameter_s, self.shell.user_ns)
2083 except Exception:
2084 codeobj = None
2085 if isinstance(codeobj, str):
2086 code = codeobj
2087 elif isinstance(codeobj, Macro):
2088 code = codeobj.value
2089 else:
2090 print parameter_s, ("was not recognised as a history range, nor"
2091 " as a string or macro.")
2092 return
2093 id = pbserver.pastes.newPaste("python", code)
2094 return "http://paste.pocoo.org/show/" + id
2075
2095
2076 def _edit_macro(self,mname,macro):
2096 def _edit_macro(self,mname,macro):
2077 """open an editor with the macro data in a file"""
2097 """open an editor with the macro data in a file"""
General Comments 0
You need to be logged in to leave comments. Login now