Upload code to dpaste.com, returning the URL. Usage:\\ %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. If no arguments are given, uploads the history of this session
(self, parameter_s='')
| 252 | |
| 253 | @line_magic |
| 254 | def pastebin(self, parameter_s=''): |
| 255 | """Upload code to dpaste.com, returning the URL. |
| 256 | |
| 257 | Usage:\\ |
| 258 | %pastebin [-d "Custom description"][-e 24] 1-7 |
| 259 | |
| 260 | The argument can be an input history range, a filename, or the name of a |
| 261 | string or macro. |
| 262 | |
| 263 | If no arguments are given, uploads the history of this session up to |
| 264 | this point. |
| 265 | |
| 266 | Options: |
| 267 | |
| 268 | -d: Pass a custom description. The default will say |
| 269 | "Pasted from IPython". |
| 270 | -e: Pass number of days for the link to be expired. |
| 271 | The default will be 7 days. |
| 272 | """ |
| 273 | opts, args = self.parse_options(parameter_s, "d:e:") |
| 274 | |
| 275 | try: |
| 276 | code = self.shell.find_user_code(args) |
| 277 | except (ValueError, TypeError) as e: |
| 278 | print(e.args[0]) |
| 279 | return |
| 280 | |
| 281 | expiry_days = 7 |
| 282 | try: |
| 283 | expiry_days = int(opts.get("e", 7)) |
| 284 | except ValueError as e: |
| 285 | print(e.args[0].capitalize()) |
| 286 | return |
| 287 | if expiry_days < 1 or expiry_days > 365: |
| 288 | print("Expiry days should be in range of 1 to 365") |
| 289 | return |
| 290 | |
| 291 | post_data = urlencode( |
| 292 | { |
| 293 | "title": opts.get("d", "Pasted from IPython"), |
| 294 | "syntax": "python", |
| 295 | "content": code, |
| 296 | "expiry_days": expiry_days, |
| 297 | } |
| 298 | ).encode("utf-8") |
| 299 | |
| 300 | request = Request( |
| 301 | "https://dpaste.com/api/v2/", |
| 302 | headers={"User-Agent": "IPython v{}".format(version)}, |
| 303 | ) |
| 304 | response = urlopen(request, post_data) |
| 305 | return response.headers.get('Location') |
| 306 | |
| 307 | @line_magic |
| 308 | def loadpy(self, arg_s): |
nothing calls this directly
no test coverage detected