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. |
@@ -248,7 +248,7 b' class CodeMagics(Magics):' | |||
|
248 | 248 | """Upload code to dpaste.com, returning the URL. |
|
249 | 249 | |
|
250 | 250 | Usage:\\ |
|
251 | %pastebin [-d "Custom description"] 1-7 | |
|
251 | %pastebin [-d "Custom description"][-e 24] 1-7 | |
|
252 | 252 | |
|
253 | 253 | The argument can be an input history range, a filename, or the name of a |
|
254 | 254 | string or macro. |
@@ -257,8 +257,10 b' class CodeMagics(Magics):' | |||
|
257 | 257 | |
|
258 | 258 | -d: Pass a custom description. The default will say |
|
259 | 259 | "Pasted from IPython". |
|
260 | -e: Pass number of days for the link to be expired. | |
|
261 | The default will be 7 days. | |
|
260 | 262 | """ |
|
261 |
opts, args = self.parse_options(parameter_s, |
|
|
263 | opts, args = self.parse_options(parameter_s, "d:e:") | |
|
262 | 264 | |
|
263 | 265 | try: |
|
264 | 266 | code = self.shell.find_user_code(args) |
@@ -266,16 +268,27 b' class CodeMagics(Magics):' | |||
|
266 | 268 | print(e.args[0]) |
|
267 | 269 | return |
|
268 | 270 | |
|
271 | expiry_days = 7 | |
|
272 | try: | |
|
273 | expiry_days = int(opts.get("e", 7)) | |
|
274 | except ValueError as e: | |
|
275 | print(e.args[0].capitalize()) | |
|
276 | return | |
|
277 | if expiry_days < 1 or expiry_days > 365: | |
|
278 | print("Expiry days should be in range of 1 to 365") | |
|
279 | return | |
|
280 | ||
|
269 | 281 | post_data = urlencode( |
|
270 | 282 | { |
|
271 | 283 | "title": opts.get("d", "Pasted from IPython"), |
|
272 | 284 | "syntax": "python", |
|
273 | 285 | "content": code, |
|
286 | "expiry_days": expiry_days, | |
|
274 | 287 | } |
|
275 | 288 | ).encode("utf-8") |
|
276 | 289 | |
|
277 | 290 | request = Request( |
|
278 | "http://dpaste.com/api/v2/", | |
|
291 | "https://dpaste.com/api/v2/", | |
|
279 | 292 | headers={"User-Agent": "IPython v{}".format(version)}, |
|
280 | 293 | ) |
|
281 | 294 | response = urlopen(request, post_data) |
General Comments 0
You need to be logged in to leave comments.
Login now