##// END OF EJS Templates
add expiry days feature to pastebin magic
Eyenpi -
Show More
@@ -249,7 +249,7 b' class CodeMagics(Magics):'
249 """Upload code to dpaste.com, returning the URL.
249 """Upload code to dpaste.com, returning the URL.
250
250
251 Usage:\\
251 Usage:\\
252 %pastebin [-d "Custom description"] 1-7
252 %pastebin [-d "Custom description"][-e 24] 1-7
253
253
254 The argument can be an input history range, a filename, or the name of a
254 The argument can be an input history range, a filename, or the name of a
255 string or macro.
255 string or macro.
@@ -258,8 +258,10 b' class CodeMagics(Magics):'
258
258
259 -d: Pass a custom description. The default will say
259 -d: Pass a custom description. The default will say
260 "Pasted from IPython".
260 "Pasted from IPython".
261 -e: Pass number of days for the link to be expired.
262 The default will be 7 days.
261 """
263 """
262 opts, args = self.parse_options(parameter_s, 'd:')
264 opts, args = self.parse_options(parameter_s, 'd:e:')
263
265
264 try:
266 try:
265 code = self.shell.find_user_code(args)
267 code = self.shell.find_user_code(args)
@@ -267,11 +269,23 b' class CodeMagics(Magics):'
267 print(e.args[0])
269 print(e.args[0])
268 return
270 return
269
271
272 expiry_days = 7
273 if "e" in opts:
274 try:
275 expiry_days = int(opts.get("e", 7))
276 except ValueError as e:
277 print(e.args[0])
278 return
279 if expiry_days < 1 or expiry_days > 365:
280 print("Expiry days should be in range of 1 to 365.")
281 return
282
270 post_data = urlencode(
283 post_data = urlencode(
271 {
284 {
272 "title": opts.get("d", "Pasted from IPython"),
285 "title": opts.get("d", "Pasted from IPython"),
273 "syntax": "python",
286 "syntax": "python",
274 "content": code,
287 "content": code,
288 "expiry_days": expiry_days
275 }
289 }
276 ).encode("utf-8")
290 ).encode("utf-8")
277
291
General Comments 0
You need to be logged in to leave comments. Login now