diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst
index 3af01b132419a5..f76b1013dfbc66 100644
--- a/Doc/library/calendar.rst
+++ b/Doc/library/calendar.rst
@@ -710,8 +710,7 @@ The following options are accepted:
.. option:: month
The month of the specified :option:`year` to print the calendar for.
- Must be a number between 1 and 12,
- and may only be used in text mode.
+ Must be a number between 1 and 12.
Defaults to printing a calendar for the full year.
diff --git a/Doc/library/html.parser.rst b/Doc/library/html.parser.rst
index dd67fc34e856f1..341a8337ba2ceb 100644
--- a/Doc/library/html.parser.rst
+++ b/Doc/library/html.parser.rst
@@ -15,14 +15,18 @@
This module defines a class :class:`HTMLParser` which serves as the basis for
parsing text files formatted in HTML (HyperText Mark-up Language) and XHTML.
-.. class:: HTMLParser(*, convert_charrefs=True)
+.. class:: HTMLParser(*, convert_charrefs=True, scripting=False)
Create a parser instance able to parse invalid markup.
- If *convert_charrefs* is ``True`` (the default), all character
- references (except the ones in ``script``/``style`` elements) are
+ If *convert_charrefs* is true (the default), all character
+ references (except the ones in elements like ``script`` and ``style``) are
automatically converted to the corresponding Unicode characters.
+ If *scripting* is false (the default), the content of the ``noscript``
+ element is parsed normally; if it's true, it's returned as is without
+ being parsed.
+
An :class:`.HTMLParser` instance is fed HTML data and calls handler methods
when start tags, end tags, text, comments, and other markup elements are
encountered. The user should subclass :class:`.HTMLParser` and override its
@@ -37,6 +41,9 @@ parsing text files formatted in HTML (HyperText Mark-up Language) and XHTML.
.. versionchanged:: 3.5
The default value for argument *convert_charrefs* is now ``True``.
+ .. versionchanged:: 3.14.1
+ Added the *scripting* parameter.
+
Example HTML Parser Application
-------------------------------
@@ -161,15 +168,15 @@ implementations do nothing (except for :meth:`~HTMLParser.handle_startendtag`):
.. method:: HTMLParser.handle_data(data)
This method is called to process arbitrary data (e.g. text nodes and the
- content of ```` and ````).
+ content of elements like ``script`` and ``style``).
.. method:: HTMLParser.handle_entityref(name)
This method is called to process a named character reference of the form
``&name;`` (e.g. ``>``), where *name* is a general entity reference
- (e.g. ``'gt'``). This method is never called if *convert_charrefs* is
- ``True``.
+ (e.g. ``'gt'``).
+ This method is only called if *convert_charrefs* is false.
.. method:: HTMLParser.handle_charref(name)
@@ -177,8 +184,8 @@ implementations do nothing (except for :meth:`~HTMLParser.handle_startendtag`):
This method is called to process decimal and hexadecimal numeric character
references of the form :samp:`{NNN};` and :samp:`{NNN};`. For example, the decimal
equivalent for ``>`` is ``>``, whereas the hexadecimal is ``>``;
- in this case the method will receive ``'62'`` or ``'x3E'``. This method
- is never called if *convert_charrefs* is ``True``.
+ in this case the method will receive ``'62'`` or ``'x3E'``.
+ This method is only called if *convert_charrefs* is false.
.. method:: HTMLParser.handle_comment(data)
@@ -292,8 +299,8 @@ Parsing an element with a few attributes and a title:
Data : Python
End tag : h1
-The content of ``script`` and ``style`` elements is returned as is, without
-further parsing:
+The content of elements like ``script`` and ``style`` is returned as is,
+without further parsing:
.. doctest::
@@ -304,10 +311,10 @@ further parsing:
End tag : style
>>> parser.feed('')
+ ... 'alert("hello! ☺");')
Start tag: script
attr: ('type', 'text/javascript')
- Data : alert("hello!");
+ Data : alert("hello! ☺");
End tag : script
Parsing comments:
@@ -336,7 +343,7 @@ correct char (note: these 3 references are all equivalent to ``'>'``):
Feeding incomplete chunks to :meth:`~HTMLParser.feed` works, but
:meth:`~HTMLParser.handle_data` might be called more than once
-(unless *convert_charrefs* is set to ``True``):
+if *convert_charrefs* is false:
.. doctest::
diff --git a/Doc/library/math.integer.rst b/Doc/library/math.integer.rst
new file mode 100644
index 00000000000000..6a9fe74c5e861b
--- /dev/null
+++ b/Doc/library/math.integer.rst
@@ -0,0 +1,85 @@
+:mod:`math.integer` --- integer-specific mathematics functions
+==============================================================
+
+.. module:: math.integer
+ :synopsis: Integer-specific mathematics functions.
+
+.. versionadded:: next
+
+--------------
+
+This module provides access to the mathematical functions defined for integer arguments.
+These functions accept integers and objects that implement the
+:meth:`~object.__index__` method which is used to convert the object to an integer
+number.
+
+The following functions are provided by this module. All return values are
+computed exactly and are integers.
+
+
+.. function:: comb(n, k, /)
+
+ Return the number of ways to choose *k* items from *n* items without repetition
+ and without order.
+
+ Evaluates to ``n! / (k! * (n - k)!)`` when ``k <= n`` and evaluates
+ to zero when ``k > n``.
+
+ Also called the binomial coefficient because it is equivalent
+ to the coefficient of k-th term in polynomial expansion of
+ ``(1 + x)ⁿ``.
+
+ Raises :exc:`ValueError` if either of the arguments are negative.
+
+
+.. function:: factorial(n, /)
+
+ Return factorial of the nonnegative integer *n*.
+
+
+.. function:: gcd(*integers)
+
+ Return the greatest common divisor of the specified integer arguments.
+ If any of the arguments is nonzero, then the returned value is the largest
+ positive integer that is a divisor of all arguments. If all arguments
+ are zero, then the returned value is ``0``. ``gcd()`` without arguments
+ returns ``0``.
+
+
+.. function:: isqrt(n, /)
+
+ Return the integer square root of the nonnegative integer *n*. This is the
+ floor of the exact square root of *n*, or equivalently the greatest integer
+ *a* such that *a*\ ² |nbsp| ≤ |nbsp| *n*.
+
+ For some applications, it may be more convenient to have the least integer
+ *a* such that *n* |nbsp| ≤ |nbsp| *a*\ ², or in other words the ceiling of
+ the exact square root of *n*. For positive *n*, this can be computed using
+ ``a = 1 + isqrt(n - 1)``.
+
+
+ .. |nbsp| unicode:: 0xA0
+ :trim:
+
+
+.. function:: lcm(*integers)
+
+ Return the least common multiple of the specified integer arguments.
+ If all arguments are nonzero, then the returned value is the smallest
+ positive integer that is a multiple of all arguments. If any of the arguments
+ is zero, then the returned value is ``0``. ``lcm()`` without arguments
+ returns ``1``.
+
+
+.. function:: perm(n, k=None, /)
+
+ Return the number of ways to choose *k* items from *n* items
+ without repetition and with order.
+
+ Evaluates to ``n! / (n - k)!`` when ``k <= n`` and evaluates
+ to zero when ``k > n``.
+
+ If *k* is not specified or is ``None``, then *k* defaults to *n*
+ and the function returns ``n!``.
+
+ Raises :exc:`ValueError` if either of the arguments are negative.
diff --git a/Doc/library/math.rst b/Doc/library/math.rst
index 5eb82a10a8c7db..54c98346b2798b 100644
--- a/Doc/library/math.rst
+++ b/Doc/library/math.rst
@@ -27,15 +27,6 @@ noted otherwise, all return values are floats.
==================================================== ============================================
-**Number-theoretic functions**
---------------------------------------------------------------------------------------------------
-:func:`comb(n, k) ` Number of ways to choose *k* items from *n* items without repetition and without order
-:func:`factorial(n) ` *n* factorial
-:func:`gcd(*integers) ` Greatest common divisor of the integer arguments
-:func:`isqrt(n) ` Integer square root of a nonnegative integer *n*
-:func:`lcm(*integers) ` Least common multiple of the integer arguments
-:func:`perm(n, k) ` Number of ways to choose *k* items from *n* items without repetition and with order
-
**Floating point arithmetic**
--------------------------------------------------------------------------------------------------
:func:`ceil(x) ` Ceiling of *x*, the smallest integer greater than or equal to *x*
@@ -126,92 +117,6 @@ noted otherwise, all return values are floats.
==================================================== ============================================
-Number-theoretic functions
---------------------------
-
-.. function:: comb(n, k)
-
- Return the number of ways to choose *k* items from *n* items without repetition
- and without order.
-
- Evaluates to ``n! / (k! * (n - k)!)`` when ``k <= n`` and evaluates
- to zero when ``k > n``.
-
- Also called the binomial coefficient because it is equivalent
- to the coefficient of k-th term in polynomial expansion of
- ``(1 + x)ⁿ``.
-
- Raises :exc:`TypeError` if either of the arguments are not integers.
- Raises :exc:`ValueError` if either of the arguments are negative.
-
- .. versionadded:: 3.8
-
-
-.. function:: factorial(n)
-
- Return factorial of the nonnegative integer *n*.
-
- .. versionchanged:: 3.10
- Floats with integral values (like ``5.0``) are no longer accepted.
-
-
-.. function:: gcd(*integers)
-
- Return the greatest common divisor of the specified integer arguments.
- If any of the arguments is nonzero, then the returned value is the largest
- positive integer that is a divisor of all arguments. If all arguments
- are zero, then the returned value is ``0``. ``gcd()`` without arguments
- returns ``0``.
-
- .. versionadded:: 3.5
-
- .. versionchanged:: 3.9
- Added support for an arbitrary number of arguments. Formerly, only two
- arguments were supported.
-
-
-.. function:: isqrt(n)
-
- Return the integer square root of the nonnegative integer *n*. This is the
- floor of the exact square root of *n*, or equivalently the greatest integer
- *a* such that *a*\ ² |nbsp| ≤ |nbsp| *n*.
-
- For some applications, it may be more convenient to have the least integer
- *a* such that *n* |nbsp| ≤ |nbsp| *a*\ ², or in other words the ceiling of
- the exact square root of *n*. For positive *n*, this can be computed using
- ``a = 1 + isqrt(n - 1)``.
-
- .. versionadded:: 3.8
-
-
-.. function:: lcm(*integers)
-
- Return the least common multiple of the specified integer arguments.
- If all arguments are nonzero, then the returned value is the smallest
- positive integer that is a multiple of all arguments. If any of the arguments
- is zero, then the returned value is ``0``. ``lcm()`` without arguments
- returns ``1``.
-
- .. versionadded:: 3.9
-
-
-.. function:: perm(n, k=None)
-
- Return the number of ways to choose *k* items from *n* items
- without repetition and with order.
-
- Evaluates to ``n! / (n - k)!`` when ``k <= n`` and evaluates
- to zero when ``k > n``.
-
- If *k* is not specified or is ``None``, then *k* defaults to *n*
- and the function returns ``n!``.
-
- Raises :exc:`TypeError` if either of the arguments are not integers.
- Raises :exc:`ValueError` if either of the arguments are negative.
-
- .. versionadded:: 3.8
-
-
Floating point arithmetic
-------------------------
@@ -812,6 +717,75 @@ Special functions
.. versionadded:: 3.2
+Number-theoretic functions
+--------------------------
+
+For backward compatibility, the :mod:`math` module provides also aliases of
+the following functions from the :mod:`math.integer` module:
+
+.. list-table::
+
+ * - .. function:: comb(n, k)
+ :no-typesetting:
+
+ :func:`comb(n, k) `
+ - Number of ways to choose *k* items from *n* items without repetition
+ and without order
+
+ * - .. function:: factorial(n)
+ :no-typesetting:
+
+ :func:`factorial(n) `
+ - *n* factorial
+
+ * - .. function:: gcd(*integers)
+ :no-typesetting:
+
+ :func:`gcd(*integers) `
+ - Greatest common divisor of the integer arguments
+
+ * - .. function:: isqrt(n)
+ :no-typesetting:
+
+ :func:`isqrt(n) `
+ - Integer square root of a nonnegative integer *n*
+
+ * - .. function:: lcm(*integers)
+ :no-typesetting:
+
+ :func:`lcm(*integers) `
+ - Least common multiple of the integer arguments
+
+ * - .. function:: perm(n, k)
+ :no-typesetting:
+
+ :func:`perm(n, k) `
+ - Number of ways to choose *k* items from *n* items without repetition
+ and with order
+
+.. versionadded:: 3.5
+ The :func:`gcd` function.
+
+.. versionadded:: 3.8
+ The :func:`comb`, :func:`perm` and :func:`isqrt` functions.
+
+.. versionadded:: 3.9
+ The :func:`lcm` function.
+
+.. versionchanged:: 3.9
+ Added support for an arbitrary number of arguments in the :func:`gcd`
+ function.
+ Formerly, only two arguments were supported.
+
+.. versionchanged:: 3.10
+ Floats with integral values (like ``5.0``) are no longer accepted in the
+ :func:`factorial` function.
+
+.. deprecated:: next
+ These aliases are :term:`soft deprecated` in favor of the
+ :mod:`math.integer` functions.
+
+
Constants
---------
@@ -894,5 +868,5 @@ Constants
Module :mod:`cmath`
Complex number versions of many of these functions.
-.. |nbsp| unicode:: 0xA0
- :trim:
+ Module :mod:`math.integer`
+ Integer-specific mathematics functions.
diff --git a/Doc/library/numeric.rst b/Doc/library/numeric.rst
index 7c76a479d73b26..a2109a29bfb6cc 100644
--- a/Doc/library/numeric.rst
+++ b/Doc/library/numeric.rst
@@ -19,6 +19,7 @@ The following modules are documented in this chapter:
numbers.rst
math.rst
+ math.integer.rst
cmath.rst
decimal.rst
fractions.rst
diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst
index 903645fb40bb14..f70345dd2b8d62 100644
--- a/Doc/whatsnew/3.15.rst
+++ b/Doc/whatsnew/3.15.rst
@@ -311,7 +311,12 @@ Other language changes
New modules
===========
-* None yet.
+math.integer
+------------
+
+This module provides access to the mathematical functions for integer
+arguments (:pep:`791`).
+(Contributed by Serhiy Storchaka in :gh:`81313`.)
Improved modules
@@ -331,6 +336,10 @@ calendar
dark mode and have been migrated to the HTML5 standard for improved accessibility.
(Contributed by Jiahao Li and Hugo van Kemenade in :gh:`137634`.)
+* The :mod:`calendar`'s :ref:`command-line ` HTML output now
+ accepts the year-month option: ``python -m calendar -t html 2009 06``.
+ (Contributed by Pål Grønås Drange in :gh:`140212`.)
+
collections
-----------
diff --git a/Include/internal/pycore_import.h b/Include/internal/pycore_import.h
index 13fbff4eb65cb2..d64a18bb09e08f 100644
--- a/Include/internal/pycore_import.h
+++ b/Include/internal/pycore_import.h
@@ -17,7 +17,8 @@ extern int _PyImport_IsInitialized(PyInterpreterState *);
// Export for 'pyexpat' shared extension
PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module);
-extern int _PyImport_SetModuleString(const char *name, PyObject* module);
+// Export for 'math' shared extension
+PyAPI_FUNC(int) _PyImport_SetModuleString(const char *name, PyObject* module);
extern void _PyImport_AcquireLock(PyInterpreterState *interp);
extern void _PyImport_ReleaseLock(PyInterpreterState *interp);
diff --git a/Lib/calendar.py b/Lib/calendar.py
index ed6b74b248042e..d80c3fd9524776 100644
--- a/Lib/calendar.py
+++ b/Lib/calendar.py
@@ -574,9 +574,9 @@ def formatyear(self, theyear, width=3):
a('')
return ''.join(v)
- def formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None):
+ def _format_html_page(self, theyear, content, css, encoding):
"""
- Return a formatted year as a complete HTML page.
+ Return a complete HTML page with the given content.
"""
if encoding is None:
encoding = 'utf-8'
@@ -597,11 +597,25 @@ def formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None):
a(f'\n')
a('\n')
a('\n')
- a(self.formatyear(theyear, width))
+ a(content)
a('\n')
a('