From 54d3529358e8425fc793f78ac9b1e115f79d2e95 2021-03-26 23:36:59 From: Paul Bissex Date: 2021-03-26 23:36:59 Subject: [PATCH] Corrected old "python3" syntax key to "python"; added UA header per dpaste TOS --- diff --git a/IPython/core/magics/code.py b/IPython/core/magics/code.py index 8e231a5..a87bebe 100644 --- a/IPython/core/magics/code.py +++ b/IPython/core/magics/code.py @@ -20,7 +20,7 @@ import re import sys import ast from itertools import chain -from urllib.request import urlopen +from urllib.request import Request, urlopen from urllib.parse import urlencode from pathlib import Path @@ -29,6 +29,7 @@ from IPython.core.error import TryNext, StdinNotImplementedError, UsageError from IPython.core.macro import Macro from IPython.core.magic import Magics, magics_class, line_magic from IPython.core.oinspect import find_file, find_source_lines +from IPython.core.release import version from IPython.testing.skipdoctest import skip_doctest from IPython.utils.contexts import preserve_keys from IPython.utils.path import get_py_filename @@ -255,7 +256,7 @@ class CodeMagics(Magics): Options: - -d: Pass a custom description for the gist. The default will say + -d: Pass a custom description. The default will say "Pasted from IPython". """ opts, args = self.parse_options(parameter_s, 'd:') @@ -268,11 +269,13 @@ class CodeMagics(Magics): post_data = urlencode({ "title": opts.get('d', "Pasted from IPython"), - "syntax": "python3", + "syntax": "python", "content": code }).encode('utf-8') - response = urlopen("http://dpaste.com/api/v2/", post_data) + request = Request("http://dpaste.com/api/v2/", + headers={"User-Agent": "IPython v{}".format(version)}) + response = urlopen(request, post_data) return response.headers.get('Location') @line_magic