From 694d3c63052f9db3870fade2c34432bc916589d1 2021-07-13 10:50:14 From: Eyenpi Date: 2021-07-13 10:50:14 Subject: [PATCH] add expiry days feature to pastebin magic --- diff --git a/IPython/core/magics/code.py b/IPython/core/magics/code.py index e5b2ce1..962f70b 100644 --- a/IPython/core/magics/code.py +++ b/IPython/core/magics/code.py @@ -249,7 +249,7 @@ class CodeMagics(Magics): """Upload code to dpaste.com, returning the URL. Usage:\\ - %pastebin [-d "Custom description"] 1-7 + %pastebin [-d "Custom description"][-e 24] 1-7 The argument can be an input history range, a filename, or the name of a string or macro. @@ -258,8 +258,10 @@ class CodeMagics(Magics): -d: Pass a custom description. The default will say "Pasted from IPython". + -e: Pass number of days for the link to be expired. + The default will be 7 days. """ - opts, args = self.parse_options(parameter_s, 'd:') + opts, args = self.parse_options(parameter_s, 'd:e:') try: code = self.shell.find_user_code(args) @@ -267,11 +269,23 @@ class CodeMagics(Magics): print(e.args[0]) return + expiry_days = 7 + if "e" in opts: + try: + expiry_days = int(opts.get("e", 7)) + except ValueError as e: + print(e.args[0]) + return + if expiry_days < 1 or expiry_days > 365: + print("Expiry days should be in range of 1 to 365.") + return + post_data = urlencode( { "title": opts.get("d", "Pasted from IPython"), "syntax": "python", "content": code, + "expiry_days": expiry_days } ).encode("utf-8")