##// END OF EJS Templates
Merge pull request #13056 from eyenpi/fix-dpaste-magic...
Blazej Michalik -
r26665:b3355a94 merge
parent child Browse files
Show More
@@ -0,0 +1,7 b''
1 Pastebin magic expiry days option
2 =================================
3
4 The Pastebin magic now has ``-e`` option to determine
5 the number of days for paste expiration. For example
6 the paste that created with ``%pastebin -e 20 1`` magic will
7 be available for next 20 days.
@@ -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,16 +269,27 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 try:
274 expiry_days = int(opts.get("e", 7))
275 except ValueError as e:
276 print(e.args[0].capitalize())
277 return
278 if expiry_days < 1 or expiry_days > 365:
279 print("Expiry days should be in range of 1 to 365")
280 return
281
270 post_data = urlencode(
282 post_data = urlencode(
271 {
283 {
272 "title": opts.get("d", "Pasted from IPython"),
284 "title": opts.get("d", "Pasted from IPython"),
273 "syntax": "python",
285 "syntax": "python",
274 "content": code,
286 "content": code,
287 "expiry_days": expiry_days,
275 }
288 }
276 ).encode("utf-8")
289 ).encode("utf-8")
277
290
278 request = Request(
291 request = Request(
279 "http://dpaste.com/api/v2/",
292 "https://dpaste.com/api/v2/",
280 headers={"User-Agent": "IPython v{}".format(version)},
293 headers={"User-Agent": "IPython v{}".format(version)},
281 )
294 )
282 response = urlopen(request, post_data)
295 response = urlopen(request, post_data)
General Comments 0
You need to be logged in to leave comments. Login now