Skip to content

Commit

Permalink
Merge branch 'main' into clean_suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Natural-selection1 authored Jan 3, 2025
2 parents 93f3478 + fa985be commit 34e9a8b
Show file tree
Hide file tree
Showing 18 changed files with 4,877 additions and 3,297 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
# reproducible: to get the same tools versions (autoconf, aclocal, ...)
runs-on: ubuntu-24.04
container:
image: ghcr.io/python/autoconf:2024.11.11.11786316759
image: ghcr.io/python/autoconf:2025.01.02.12581854023
timeout-minutes: 60
needs: check_source
if: needs.check_source.outputs.run_tests == 'true'
Expand All @@ -63,7 +63,7 @@ jobs:
run: echo "IMAGE_VERSION=${ImageVersion}" >> "$GITHUB_ENV"
- name: Check Autoconf and aclocal versions
run: |
grep "Generated by GNU Autoconf 2.71" configure
grep "Generated by GNU Autoconf 2.72" configure
grep "aclocal 1.16.5" aclocal.m4
grep -q "runstatedir" configure
grep -q "PKG_PROG_PKG_CONFIG" aclocal.m4
Expand Down
27 changes: 26 additions & 1 deletion Doc/library/calendar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,32 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is

:class:`TextCalendar` instances have the following methods:


.. method:: formatday(theday, weekday, width)

Return a string representing a single day formatted with the given *width*.
If *theday* is ``0``, return a string of spaces of
the specified width, representing an empty day. The *weekday* parameter
is unused.

.. method:: formatweek(theweek, w=0)

Return a single week in a string with no newline. If *w* is provided, it
specifies the width of the date columns, which are centered. Depends
on the first weekday as specified in the constructor or set by the
:meth:`setfirstweekday` method.

.. method:: formatweekday(weekday, width)

Return a string representing the name of a single weekday formatted to
the specified *width*. The *weekday* parameter is an integer representing
the day of the week, where ``0`` is Monday and ``6`` is Sunday.

.. method:: formatweekheader(width)

Return a string containing the header row of weekday names, formatted
with the given *width* for each column. The names depend on the locale
settings and are padded to the specified width.

.. method:: formatmonth(theyear, themonth, w=0, l=0)

Expand All @@ -154,6 +173,12 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
on the first weekday as specified in the constructor or set by the
:meth:`setfirstweekday` method.

.. method:: formatmonthname(theyear, themonth, width=0, withyear=True)

Return a string representing the month's name centered within the
specified *width*. If *withyear* is ``True``, include the year in the
output. The *theyear* and *themonth* parameters specify the year
and month for the name to be formatted respectively.

.. method:: prmonth(theyear, themonth, w=0, l=0)

Expand Down Expand Up @@ -445,7 +470,7 @@ The :mod:`calendar` module exports the following data attributes:

A sequence that represents the months of the year in the current locale. This
follows normal convention of January being month number 1, so it has a length of
13 and ``month_name[0]`` is the empty string.
13 and ``month_name[0]`` is the empty string.

>>> import calendar
>>> list(calendar.month_name)
Expand Down
3 changes: 3 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,9 @@ Changes in the Python API
Build changes
=============

* GNU Autoconf 2.72 is now required to generate :file:`!configure`.
(Contributed by Erlend Aasland in :gh:`115765`.)

PEP 761: Discontinuation of PGP signatures
------------------------------------------

Expand Down
6 changes: 6 additions & 0 deletions Include/cpython/pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ PyAPI_FUNC(void) _PyErr_ChainExceptions1(PyObject *);

/* In exceptions.c */

PyAPI_FUNC(int) _PyUnicodeError_GetParams(
PyObject *self,
PyObject **obj, Py_ssize_t *objlen,
Py_ssize_t *start, Py_ssize_t *end,
int as_bytes);

PyAPI_FUNC(PyObject*) PyUnstable_Exc_PrepReraiseStar(
PyObject *orig,
PyObject *excs);
Expand Down
10 changes: 7 additions & 3 deletions Lib/asyncio/selector_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,13 @@ def _accept_connection(
logger.debug("%r got a new connection from %r: %r",
server, addr, conn)
conn.setblocking(False)
except (BlockingIOError, InterruptedError, ConnectionAbortedError):
# Early exit because the socket accept buffer is empty.
return None
except ConnectionAbortedError:
# Discard connections that were aborted before accept().
continue
except (BlockingIOError, InterruptedError):
# Early exit because of a signal or
# the socket accept buffer is empty.
return
except OSError as exc:
# There's nowhere to send the error, so just log it.
if exc.errno in (errno.EMFILE, errno.ENFILE,
Expand Down
25 changes: 25 additions & 0 deletions Lib/test/test_asyncio/test_selector_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,31 @@ def test_accept_connection_multiple(self):
self.loop.run_until_complete(asyncio.sleep(0))
self.assertEqual(sock.accept.call_count, backlog)

def test_accept_connection_skip_connectionabortederror(self):
sock = mock.Mock()

def mock_sock_accept():
# mock accept(2) returning -ECONNABORTED every-other
# time that it's called. This applies most to OpenBSD
# whose sockets generate this errno more reproducibly than
# Linux and other OS.
if sock.accept.call_count % 2 == 0:
raise ConnectionAbortedError
return (mock.Mock(), mock.Mock())

sock.accept.side_effect = mock_sock_accept
backlog = 100
# test that _accept_connection's loop calls sock.accept
# all 100 times, continuing past ConnectionAbortedError
# instead of unnecessarily returning early
mock_obj = mock.patch.object
with mock_obj(self.loop, '_accept_connection2') as accept2_mock:
self.loop._accept_connection(
mock.Mock(), sock, backlog=backlog)
# as in test_accept_connection_multiple avoid task pending
# warnings by using asyncio.sleep(0)
self.loop.run_until_complete(asyncio.sleep(0))
self.assertEqual(sock.accept.call_count, backlog)

class SelectorTransportTests(test_utils.TestCase):

Expand Down
8 changes: 2 additions & 6 deletions Lib/test/test_sys_settrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import difflib
import gc
from functools import wraps
import asyncio
from test.support import import_helper, requires_subprocess
from test.support import import_helper, requires_subprocess, run_no_yield_async_fn
import contextlib
import os
import tempfile
Expand All @@ -19,8 +18,6 @@
except ImportError:
_testinternalcapi = None

support.requires_working_socket(module=True)

class tracecontext:
"""Context manager that traces its enter and exit."""
def __init__(self, output, value):
Expand Down Expand Up @@ -2067,10 +2064,9 @@ def run_async_test(self, func, jumpFrom, jumpTo, expected, error=None,
stack.enter_context(self.assertRaisesRegex(*error))
if warning is not None:
stack.enter_context(self.assertWarnsRegex(*warning))
asyncio.run(func(output))
run_no_yield_async_fn(func, output)

sys.settrace(None)
asyncio._set_event_loop_policy(None)
self.compare_jump_output(expected, output)

def jump_test(jumpFrom, jumpTo, expected, error=None, event='line', warning=None):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Remove ``Py_STRFTIME_C99_SUPPORT`` conditions in favor of requiring C99
:manpage:`strftime(3)` specifier support at build time. When cross-compiling,
there is no build time check and support is assumed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GNU Autoconf 2.72 is now required to generate :file:`!configure`.
Patch by Erlend Aasland.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Correct behavior of
:func:`!asyncio.selector_events.BaseSelectorEventLoop._accept_connection`
in handling :exc:`ConnectionAbortedError` in a loop. This improves
performance on OpenBSD.
6 changes: 0 additions & 6 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1912,9 +1912,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
}
#ifdef Py_NORMALIZE_CENTURY
else if (ch == 'Y' || ch == 'G'
#ifdef Py_STRFTIME_C99_SUPPORT
|| ch == 'F' || ch == 'C'
#endif
) {
/* 0-pad year with century as necessary */
PyObject *item = PySequence_GetItem(timetuple, 0);
Expand Down Expand Up @@ -1952,15 +1950,11 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
* +6 to accommodate dashes, 2-digit month and day for %F. */
char buf[SIZEOF_LONG * 5 / 2 + 2 + 6];
Py_ssize_t n = PyOS_snprintf(buf, sizeof(buf),
#ifdef Py_STRFTIME_C99_SUPPORT
ch == 'F' ? "%04ld-%%m-%%d" :
#endif
"%04ld", year_long);
#ifdef Py_STRFTIME_C99_SUPPORT
if (ch == 'C') {
n -= 2;
}
#endif
if (_PyUnicodeWriter_WriteSubstring(&writer, format, start, end) < 0) {
goto Error;
}
Expand Down
Loading

0 comments on commit 34e9a8b

Please sign in to comment.