Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 67 additions & 40 deletions Doc/library/dbm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ the Oracle Berkeley DB.
.. versionchanged:: 3.11
*file* accepts a :term:`path-like object`.

The object returned by :func:`~dbm.open` supports the same basic functionality as a
:class:`dict`; keys and their corresponding values can be stored, retrieved, and
deleted, and the :keyword:`in` operator and the :meth:`!keys` method are
available, as well as :meth:`!get` and :meth:`!setdefault` methods.
The object returned by :func:`~dbm.open` supports the basic
functionality of mutable :term:`mappings <mapping>`;
keys and their corresponding values can be stored, retrieved, and
deleted, and iteration, the :keyword:`in` operator and methods :meth:`!keys`,
:meth:`!get`, :meth:`!setdefault` and :meth:`!clear` are available.
The :meth:`!keys` method returns a list instead of a view object.
The :meth:`!setdefault` method requires two arguments.

Key and values are always stored as :class:`bytes`. This means that when
strings are used they are implicitly converted to the default encoding before
Expand All @@ -114,6 +117,10 @@ will automatically close them when done.
Deleting a key from a read-only database raises a database module specific exception
instead of :exc:`KeyError`.

.. versionchanged:: 3.13
:meth:`!clear` methods are now available for all :mod:`dbm` backends.


The following example records some hostnames and a corresponding title, and
then prints out the contents of the database::

Expand Down Expand Up @@ -173,9 +180,6 @@ or any other SQLite browser, including the SQLite CLI.
.. function:: open(filename, /, flag="r", mode=0o666)

Open an SQLite database.
The returned object behaves like a :term:`mapping`,
implements a :meth:`!close` method,
and supports a "closing" context manager via the :keyword:`with` keyword.

:param filename:
The path to the database to be opened.
Expand All @@ -192,6 +196,17 @@ or any other SQLite browser, including the SQLite CLI.
The Unix file access mode of the file (default: octal ``0o666``),
used only when the database has to be created.

The returned database object behaves similar to a mutable :term:`mapping`,
but the :meth:`!keys` method returns a list, and
the :meth:`!setdefault` method requires two arguments.
It also supports a "closing" context manager via the :keyword:`with` keyword.

The following methods are also provided:

.. method:: sqlite3.close()

Close the SQLite database.

.. method:: sqlite3.reorganize()

If you have carried out a lot of deletions and would like to shrink the space
Expand All @@ -204,6 +219,7 @@ or any other SQLite browser, including the SQLite CLI.

.. versionadded:: next


:mod:`dbm.gnu` --- GNU database manager
---------------------------------------

Expand Down Expand Up @@ -232,6 +248,11 @@ functionality like crash tolerance.
raised for general mapping errors like specifying an incorrect key.


.. data:: open_flags

A string of characters the *flag* parameter of :meth:`~dbm.gnu.open` supports.


.. function:: open(filename, flag="r", mode=0o666, /)

Open a GDBM database and return a :class:`!gdbm` object.
Expand Down Expand Up @@ -270,14 +291,25 @@ functionality like crash tolerance.
.. versionchanged:: 3.11
*filename* accepts a :term:`path-like object`.

.. data:: open_flags
:class:`!gdbm` objects behave similar to mutable :term:`mappings <mapping>`,
but methods :meth:`!items`, :meth:`!values`, :meth:`!pop`, :meth:`!popitem`,
and :meth:`!update` are not supported,
the :meth:`!keys` method returns a list, and
the :meth:`!setdefault` method requires two arguments.
It also supports a "closing" context manager via the :keyword:`with` keyword.

.. versionchanged:: 3.2
Added the :meth:`!get` and :meth:`!setdefault` methods.

A string of characters the *flag* parameter of :meth:`~dbm.gnu.open` supports.
.. versionchanged:: 3.13
Added the :meth:`!clear` method.

:class:`!gdbm` objects behave similar to :term:`mappings <mapping>`,
but :meth:`!items` and :meth:`!values` methods are not supported.
The following methods are also provided:

.. method:: gdbm.close()

Close the GDBM database.

.. method:: gdbm.firstkey()

It's possible to loop over every key in the database using this method and the
Expand Down Expand Up @@ -313,16 +345,6 @@ functionality like crash tolerance.
When the database has been opened in fast mode, this method forces any
unwritten data to be written to the disk.

.. method:: gdbm.close()

Close the GDBM database.

.. method:: gdbm.clear()

Remove all items from the GDBM database.

.. versionadded:: 3.13


:mod:`dbm.ndbm` --- New Database Manager
----------------------------------------
Expand Down Expand Up @@ -383,22 +405,27 @@ This module can be used with the "classic" NDBM interface or the
:param int mode:
|mode_param_doc|

:class:`!ndbm` objects behave similar to :term:`mappings <mapping>`,
but :meth:`!items` and :meth:`!values` methods are not supported.
The following methods are also provided:

.. versionchanged:: 3.11
Accepts :term:`path-like object` for filename.

.. method:: ndbm.close()
:class:`!ndbm` objects behave similar to mutable :term:`mappings <mapping>`,
but methods :meth:`!items`, :meth:`!values`, :meth:`!pop`, :meth:`!popitem`,
and :meth:`!update` are not supported,
the :meth:`!keys` method returns a list, and
the :meth:`!setdefault` method requires two arguments.
It also supports a "closing" context manager via the :keyword:`with` keyword.

Close the NDBM database.
.. versionchanged:: 3.2
Added the :meth:`!get` and :meth:`!setdefault` methods.

.. method:: ndbm.clear()
.. versionchanged:: 3.13
Added the :meth:`!clear` method.

Remove all items from the NDBM database.
The following method is also provided:

.. versionadded:: 3.13
.. method:: ndbm.close()

Close the NDBM database.


:mod:`dbm.dumb` --- Portable DBM implementation
Expand Down Expand Up @@ -436,9 +463,6 @@ The :mod:`!dbm.dumb` module defines the following:
.. function:: open(filename, flag="c", mode=0o666)

Open a :mod:`!dbm.dumb` database.
The returned database object behaves similar to a :term:`mapping`,
in addition to providing :meth:`~dumbdbm.sync` and :meth:`~dumbdbm.close`
methods.

:param filename:
The basename of the database file (without extensions).
Expand Down Expand Up @@ -477,14 +501,12 @@ The :mod:`!dbm.dumb` module defines the following:
.. versionchanged:: 3.11
*filename* accepts a :term:`path-like object`.

In addition to the methods provided by the
:class:`collections.abc.MutableMapping` class,
the following methods are provided:
The returned database object behaves similar to a mutable :term:`mapping`,
but the :meth:`!keys` and :meth:`!items` methods return lists, and
the :meth:`!setdefault` method requires two arguments.
It also supports a "closing" context manager via the :keyword:`with` keyword.

.. method:: dumbdbm.sync()

Synchronize the on-disk directory and data files. This method is called
by the :meth:`shelve.Shelf.sync` method.
The following methods are also provided:

.. method:: dumbdbm.close()

Expand All @@ -501,3 +523,8 @@ The :mod:`!dbm.dumb` module defines the following:
that this factor changes for each :mod:`dbm` submodule.

.. versionadded:: next

.. method:: dumbdbm.sync()

Synchronize the on-disk directory and data files. This method is called
by the :meth:`shelve.Shelf.sync` method.
6 changes: 3 additions & 3 deletions Doc/library/resource.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ this module for those platforms.

Sets new limits of consumption of *resource*. The *limits* argument must be a
tuple ``(soft, hard)`` of two integers describing the new limits. A value of
:data:`~resource.RLIM_INFINITY` can be used to request a limit that is
:const:`~resource.RLIM_INFINITY` can be used to request a limit that is
unlimited.

Raises :exc:`ValueError` if an invalid resource is specified, if the new soft
limit exceeds the hard limit, or if a process tries to raise its hard limit.
Specifying a limit of :data:`~resource.RLIM_INFINITY` when the hard or
Specifying a limit of :const:`~resource.RLIM_INFINITY` when the hard or
system limit for that resource is not unlimited will result in a
:exc:`ValueError`. A process with the effective UID of super-user can
request any valid limit value, including unlimited, but :exc:`ValueError`
Expand All @@ -93,7 +93,7 @@ this module for those platforms.
``setrlimit`` may also raise :exc:`error` if the underlying system call
fails.

VxWorks only supports setting :data:`RLIMIT_NOFILE`.
VxWorks only supports setting :const:`RLIMIT_NOFILE`.

.. audit-event:: resource.setrlimit resource,limits resource.setrlimit

Expand Down
5 changes: 3 additions & 2 deletions Doc/library/ssl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1898,8 +1898,9 @@ to speed up repeated connections from the same clients.
.. attribute:: SSLContext.sslsocket_class

The return type of :meth:`SSLContext.wrap_socket`, defaults to
:class:`SSLSocket`. The attribute can be overridden on instance of class
in order to return a custom subclass of :class:`SSLSocket`.
:class:`SSLSocket`. The attribute can be assigned to on instances of
:class:`SSLContext` in order to return a custom subclass of
:class:`SSLSocket`.

.. versionadded:: 3.7

Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ dbm
(Contributed by Raymond Hettinger and Erlend E. Aasland in :gh:`100414`.)

* Allow removing all items from the database through
the new :meth:`.gdbm.clear` and :meth:`.ndbm.clear` methods.
the new :meth:`!clear` methods of the GDBM and NDBM database objects.
(Contributed by Donghee Na in :gh:`107122`.)


Expand Down
13 changes: 1 addition & 12 deletions Lib/_pydatetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,6 @@ def _need_normalize_century():
_normalize_century = True
return _normalize_century

_supports_c99 = None
def _can_support_c99():
global _supports_c99
if _supports_c99 is None:
try:
_supports_c99 = (
_time.strftime("%F", (1900, 1, 1, 0, 0, 0, 0, 1, 0)) == "1900-01-01")
except ValueError:
_supports_c99 = False
return _supports_c99

# Correctly substitute for %z and %Z escapes in strftime formats.
def _wrap_strftime(object, format, timetuple):
# Don't call utcoffset() or tzname() unless actually needed.
Expand Down Expand Up @@ -283,7 +272,7 @@ def _wrap_strftime(object, format, timetuple):
newformat.append(Zreplace)
# Note that datetime(1000, 1, 1).strftime('%G') == '1000' so
# year 1000 for %G can go on the fast path.
elif ((ch in 'YG' or ch in 'FC' and _can_support_c99()) and
elif ((ch in 'YG' or ch in 'FC') and
object.year < 1000 and _need_normalize_century()):
if ch == 'G':
year = int(_time.strftime("%G", timetuple))
Expand Down
38 changes: 22 additions & 16 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,7 @@ def test_bool(self):
self.assertTrue(self.theclass.min)
self.assertTrue(self.theclass.max)

def test_strftime_y2k(self):
def check_strftime_y2k(self, specifier):
# Test that years less than 1000 are 0-padded; note that the beginning
# of an ISO 8601 year may fall in an ISO week of the year before, and
# therefore needs an offset of -1 when formatting with '%G'.
Expand All @@ -1821,22 +1821,28 @@ def test_strftime_y2k(self):
(1000, 0),
(1970, 0),
)
specifiers = 'YG'
if _time.strftime('%F', (1900, 1, 1, 0, 0, 0, 0, 1, 0)) == '1900-01-01':
specifiers += 'FC'
for year, g_offset in dataset:
for specifier in specifiers:
with self.subTest(year=year, specifier=specifier):
d = self.theclass(year, 1, 1)
if specifier == 'G':
year += g_offset
if specifier == 'C':
expected = f"{year // 100:02d}"
else:
expected = f"{year:04d}"
if specifier == 'F':
expected += f"-01-01"
self.assertEqual(d.strftime(f"%{specifier}"), expected)
with self.subTest(year=year, specifier=specifier):
d = self.theclass(year, 1, 1)
if specifier == 'G':
year += g_offset
if specifier == 'C':
expected = f"{year // 100:02d}"
else:
expected = f"{year:04d}"
if specifier == 'F':
expected += f"-01-01"
self.assertEqual(d.strftime(f"%{specifier}"), expected)

def test_strftime_y2k(self):
self.check_strftime_y2k('Y')
self.check_strftime_y2k('G')

def test_strftime_y2k_c99(self):
# CPython requires C11; specifiers new in C99 must work.
# (Other implementations may want to disable this test.)
self.check_strftime_y2k('F')
self.check_strftime_y2k('C')

def test_replace(self):
cls = self.theclass
Expand Down
21 changes: 14 additions & 7 deletions Lib/test/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,33 +116,40 @@ def test_fsize_not_too_big(self):
self.addCleanup(resource.setrlimit, resource.RLIMIT_FSIZE, (cur, max))

def expected(cur):
return (min(cur, resource.RLIM_INFINITY), max)
# The glibc wrapper functions use a 64-bit rlim_t data type,
# even on 32-bit platforms. If a program tried to set a resource
# limit to a value larger than can be represented in a 32-bit
# unsigned long, then the glibc setrlimit() wrapper function
# silently converted the limit value to RLIM_INFINITY.
if sys.maxsize < 2**32 <= cur <= resource.RLIM_INFINITY:
return [(resource.RLIM_INFINITY, max), (cur, max)]
return [(min(cur, resource.RLIM_INFINITY), max)]

resource.setrlimit(resource.RLIMIT_FSIZE, (2**31-5, max))
self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), (2**31-5, max))
resource.setrlimit(resource.RLIMIT_FSIZE, (2**31, max))
self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**31))
self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**31))
resource.setrlimit(resource.RLIMIT_FSIZE, (2**32-5, max))
self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**32-5))
self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**32-5))

try:
resource.setrlimit(resource.RLIMIT_FSIZE, (2**32, max))
except OverflowError:
pass
else:
self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**32))
self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**32))

resource.setrlimit(resource.RLIMIT_FSIZE, (2**63-5, max))
self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**63-5))
self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**63-5))
try:
resource.setrlimit(resource.RLIMIT_FSIZE, (2**63, max))
except ValueError:
# There is a hard limit on macOS.
pass
else:
self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**63))
self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**63))
resource.setrlimit(resource.RLIMIT_FSIZE, (2**64-5, max))
self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**64-5))
self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**64-5))

@unittest.skipIf(sys.platform == "vxworks",
"setting RLIMIT_FSIZE is not supported on VxWorks")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Check the ``strftime()`` behavior at runtime instead of at the compile time
to support cross-compiling.
Remove the internal macro ``_Py_NORMALIZE_CENTURY``.
Loading
Loading