Compare commits

...

4 Commits

Author SHA1 Message Date
Gregory P. Smith 51c68cf466
[3.11] gh-98930: improve the docstring of signal.strsignal (GH-99290) (#99449)
Improves the docstring on signal.strsignal to make it explain when it returns a message, None, or when it raises ValueError.

Closes GH-98930

Co-authored-by: Gregory P. Smith <greg@krypto.org>.
(cherry picked from commit 88385b8564)

Co-authored-by: ram vikram singh <ramvikrams243@gmail.com>
2022-11-13 12:21:19 -08:00
Miss Islington (bot) bf76d9bd4d
gh-99275: Fix `SystemError` in `ctypes` during `__initsubclass__` (GH-99283)
(cherry picked from commit 343eb0f94b)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2022-11-13 11:51:26 -08:00
Miss Islington (bot) 72d356e358
gh-99418: Make urllib.parse.urlparse enforce that a scheme must begin with an alphabetical ASCII character. (GH-99421)
Prevent urllib.parse.urlparse from accepting schemes that don't begin with an alphabetical ASCII character.

RFC 3986 defines a scheme like this: `scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )`
RFC 2234 defines an ALPHA like this: `ALPHA = %x41-5A / %x61-7A`

The WHATWG URL spec defines a scheme like this:
`"A URL-scheme string must be one ASCII alpha, followed by zero or more of ASCII alphanumeric, U+002B (+), U+002D (-), and U+002E (.)."`
(cherry picked from commit 439b9cfaf4)

Co-authored-by: Ben Kallus <49924171+kenballus@users.noreply.github.com>
2022-11-13 11:00:25 -08:00
Erlend E. Aasland eac1a63cdb
[3.11] gh-98707: configure --with-system-libmpdec and --with-system-expat no longer include vendored headers (GH-98711) (#99391)
(cherry picked from commit 6abec1caff)

Co-authored-by: Miro Hrončok <miro@hroncok.cz>
2022-11-13 19:47:31 +01:00
13 changed files with 58 additions and 18 deletions

View File

@ -362,9 +362,9 @@ The :mod:`signal` module defines the following functions:
.. function:: strsignal(signalnum)
Return the system description of the signal *signalnum*, such as
"Interrupt", "Segmentation fault", etc. Returns :const:`None` if the signal
is not recognized.
Returns the description of signal *signalnum*, such as "Interrupt"
for :const:`SIGINT`. Returns :const:`None` if *signalnum* has no
description. Raises :exc:`ValueError` if *signalnum* is invalid.
.. versionadded:: 3.8

View File

@ -54,6 +54,15 @@ class X(Structure):
x.char = b'a\0b\0'
self.assertEqual(bytes(x), b'a\x00###')
def test_gh99275(self):
class BrokenStructure(Structure):
def __init_subclass__(cls, **kwargs):
cls._fields_ = [] # This line will fail, `stgdict` is not ready
with self.assertRaisesRegex(TypeError,
'ctypes state is not initialized'):
class Subclass(BrokenStructure): ...
# __set__ and __get__ should raise a TypeError in case their self
# argument is not a ctype instance.
def test___set__(self):

View File

@ -668,6 +668,24 @@ def test_attributes_bad_port(self):
with self.assertRaises(ValueError):
p.port
def test_attributes_bad_scheme(self):
"""Check handling of invalid schemes."""
for bytes in (False, True):
for parse in (urllib.parse.urlsplit, urllib.parse.urlparse):
for scheme in (".", "+", "-", "0", "http&", "६http"):
with self.subTest(bytes=bytes, parse=parse, scheme=scheme):
url = scheme + "://www.example.net"
if bytes:
if url.isascii():
url = url.encode("ascii")
else:
continue
p = parse(url)
if bytes:
self.assertEqual(p.scheme, b"")
else:
self.assertEqual(p.scheme, "")
def test_attributes_without_netloc(self):
# This example is straight from RFC 3261. It looks like it
# should allow the username, hostname, and port to be filled

View File

@ -460,7 +460,7 @@ def urlsplit(url, scheme='', allow_fragments=True):
allow_fragments = bool(allow_fragments)
netloc = query = fragment = ''
i = url.find(':')
if i > 0:
if i > 0 and url[0].isascii() and url[0].isalpha():
for c in url[:i]:
if c not in scheme_chars:
break

View File

@ -2528,12 +2528,12 @@ Python/thread.o: @THREADHEADERS@ $(srcdir)/Python/condvar.h
MODULE_CMATH_DEPS=$(srcdir)/Modules/_math.h
MODULE_MATH_DEPS=$(srcdir)/Modules/_math.h
MODULE_PYEXPAT_DEPS=$(LIBEXPAT_HEADERS) @LIBEXPAT_INTERNAL@
MODULE_PYEXPAT_DEPS=@LIBEXPAT_INTERNAL@
MODULE_UNICODEDATA_DEPS=$(srcdir)/Modules/unicodedata_db.h $(srcdir)/Modules/unicodename_db.h
MODULE__BLAKE2_DEPS=$(srcdir)/Modules/_blake2/impl/blake2-config.h $(srcdir)/Modules/_blake2/impl/blake2-impl.h $(srcdir)/Modules/_blake2/impl/blake2.h $(srcdir)/Modules/_blake2/impl/blake2b-load-sse2.h $(srcdir)/Modules/_blake2/impl/blake2b-load-sse41.h $(srcdir)/Modules/_blake2/impl/blake2b-ref.c $(srcdir)/Modules/_blake2/impl/blake2b-round.h $(srcdir)/Modules/_blake2/impl/blake2b.c $(srcdir)/Modules/_blake2/impl/blake2s-load-sse2.h $(srcdir)/Modules/_blake2/impl/blake2s-load-sse41.h $(srcdir)/Modules/_blake2/impl/blake2s-load-xop.h $(srcdir)/Modules/_blake2/impl/blake2s-ref.c $(srcdir)/Modules/_blake2/impl/blake2s-round.h $(srcdir)/Modules/_blake2/impl/blake2s.c $(srcdir)/Modules/_blake2/blake2module.h $(srcdir)/Modules/hashlib.h
MODULE__CTYPES_DEPS=$(srcdir)/Modules/_ctypes/ctypes.h
MODULE__DECIMAL_DEPS=$(srcdir)/Modules/_decimal/docstrings.h $(LIBMPDEC_HEADERS) @LIBMPDEC_INTERNAL@
MODULE__ELEMENTTREE_DEPS=$(srcdir)/Modules/pyexpat.c $(LIBEXPAT_HEADERS) @LIBEXPAT_INTERNAL@
MODULE__DECIMAL_DEPS=$(srcdir)/Modules/_decimal/docstrings.h @LIBMPDEC_INTERNAL@
MODULE__ELEMENTTREE_DEPS=$(srcdir)/Modules/pyexpat.c @LIBEXPAT_INTERNAL@
MODULE__HASHLIB_DEPS=$(srcdir)/Modules/hashlib.h
MODULE__IO_DEPS=$(srcdir)/Modules/_io/_iomodule.h
MODULE__MD5_DEPS=$(srcdir)/Modules/hashlib.h

View File

@ -0,0 +1,4 @@
Don't use vendored ``libmpdec`` headers if :option:`--with-system-libmpdec`
is passed to :program:`configure`.
Don't use vendored ``libexpat`` headers if :option:`--with-system-expat`
is passed to :program:`!configure`.

View File

@ -0,0 +1,2 @@
Fix ``SystemError`` in :mod:`ctypes` when exception was not set during
``__initsubclass__``.

View File

@ -0,0 +1,2 @@
Fix bug in :func:`urllib.parse.urlparse` that causes URL schemes that begin
with a digit, a plus sign, or a minus sign to be parsed incorrectly.

View File

@ -430,8 +430,11 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
}
stgdict = PyType_stgdict(type);
if (!stgdict)
if (!stgdict) {
PyErr_SetString(PyExc_TypeError,
"ctypes state is not initialized");
return -1;
}
/* If this structure/union is already marked final we cannot assign
_fields_ anymore. */

View File

@ -205,8 +205,9 @@ PyDoc_STRVAR(signal_strsignal__doc__,
"\n"
"Return the system description of the given signal.\n"
"\n"
"The return values can be such as \"Interrupt\", \"Segmentation fault\", etc.\n"
"Returns None if the signal is not recognized.");
"Returns the description of signal *signalnum*, such as \"Interrupt\"\n"
"for :const:`SIGINT`. Returns :const:`None` if *signalnum* has no\n"
"description. Raises :exc:`ValueError` if *signalnum* is invalid.");
#define SIGNAL_STRSIGNAL_METHODDEF \
{"strsignal", (PyCFunction)signal_strsignal, METH_O, signal_strsignal__doc__},
@ -698,4 +699,4 @@ exit:
#ifndef SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF
#define SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF
#endif /* !defined(SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF) */
/*[clinic end generated code: output=6ca1b70310eecdba input=a9049054013a1b77]*/
/*[clinic end generated code: output=9b3f9f1ae2ac2b94 input=a9049054013a1b77]*/

View File

@ -627,13 +627,14 @@ signal.strsignal
Return the system description of the given signal.
The return values can be such as "Interrupt", "Segmentation fault", etc.
Returns None if the signal is not recognized.
Returns the description of signal *signalnum*, such as "Interrupt"
for :const:`SIGINT`. Returns :const:`None` if *signalnum* has no
description. Raises :exc:`ValueError` if *signalnum* is invalid.
[clinic start generated code]*/
static PyObject *
signal_strsignal_impl(PyObject *module, int signalnum)
/*[clinic end generated code: output=44e12e1e3b666261 input=b77914b03f856c74]*/
/*[clinic end generated code: output=44e12e1e3b666261 input=238b335847778bc0]*/
{
const char *res;

4
configure generated vendored
View File

@ -12110,7 +12110,7 @@ else
LIBEXPAT_CFLAGS="-I\$(srcdir)/Modules/expat"
LIBEXPAT_LDFLAGS="-lm \$(LIBEXPAT_A)"
LIBEXPAT_INTERNAL="\$(LIBEXPAT_A)"
LIBEXPAT_INTERNAL="\$(LIBEXPAT_HEADERS) \$(LIBEXPAT_A)"
fi
@ -12184,7 +12184,7 @@ else
LIBMPDEC_CFLAGS="-I\$(srcdir)/Modules/_decimal/libmpdec"
LIBMPDEC_LDFLAGS="-lm \$(LIBMPDEC_A)"
LIBMPDEC_INTERNAL="\$(LIBMPDEC_A)"
LIBMPDEC_INTERNAL="\$(LIBMPDEC_HEADERS) \$(LIBMPDEC_A)"
if test "x$with_pydebug" = xyes; then :

View File

@ -3610,7 +3610,7 @@ AS_VAR_IF([with_system_expat], [yes], [
], [
LIBEXPAT_CFLAGS="-I\$(srcdir)/Modules/expat"
LIBEXPAT_LDFLAGS="-lm \$(LIBEXPAT_A)"
LIBEXPAT_INTERNAL="\$(LIBEXPAT_A)"
LIBEXPAT_INTERNAL="\$(LIBEXPAT_HEADERS) \$(LIBEXPAT_A)"
])
AC_SUBST([LIBEXPAT_CFLAGS])
@ -3666,7 +3666,7 @@ AS_VAR_IF([with_system_libmpdec], [yes], [
], [
LIBMPDEC_CFLAGS="-I\$(srcdir)/Modules/_decimal/libmpdec"
LIBMPDEC_LDFLAGS="-lm \$(LIBMPDEC_A)"
LIBMPDEC_INTERNAL="\$(LIBMPDEC_A)"
LIBMPDEC_INTERNAL="\$(LIBMPDEC_HEADERS) \$(LIBMPDEC_A)"
dnl Disable forced inlining in debug builds, see GH-94847
AS_VAR_IF([with_pydebug], [yes], [