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
50 changes: 40 additions & 10 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,13 @@ process and user.
the groups of which the specified username is a member, plus the specified
group id.

.. availability:: Unix, not WASI, not Android.
.. availability:: Unix, not WASI.

.. versionadded:: 3.2

.. versionchanged:: 3.16
Support for Android now exists.


.. function:: putenv(key, value, /)

Expand Down Expand Up @@ -610,21 +613,30 @@ process and user.

Set the current process's effective group id.

.. availability:: Unix, not WASI, not Android.
.. availability:: Unix, not WASI.

.. versionchanged:: 3.16
Support for Android now exists.


.. function:: seteuid(euid, /)

Set the current process's effective user id.

.. availability:: Unix, not WASI, not Android.
.. availability:: Unix, not WASI.

.. versionchanged:: 3.16
Support for Android now exists.


.. function:: setgid(gid, /)

Set the current process' group id.

.. availability:: Unix, not WASI, not Android.
.. availability:: Unix, not WASI.

.. versionchanged:: 3.16
Support for Android now exists.


.. function:: setgroups(groups, /)
Expand Down Expand Up @@ -718,32 +730,44 @@ process and user.

Set the current process's real and effective group ids.

.. availability:: Unix, not WASI, not Android.
.. availability:: Unix, not WASI.

.. versionchanged:: 3.16
Support for Android now exists.


.. function:: setresgid(rgid, egid, sgid, /)

Set the current process's real, effective, and saved group ids.

.. availability:: Unix, not WASI, not Android, not macOS, not iOS.
.. availability:: Unix, not WASI, not macOS, not iOS.

.. versionadded:: 3.2

.. versionchanged:: 3.16
Support for Android now exists.


.. function:: setresuid(ruid, euid, suid, /)

Set the current process's real, effective, and saved user ids.

.. availability:: Unix, not WASI, not Android, not macOS, not iOS.
.. availability:: Unix, not WASI, not macOS, not iOS.

.. versionadded:: 3.2

.. versionchanged:: 3.16
Support for Android now exists.


.. function:: setreuid(ruid, euid, /)

Set the current process's real and effective user ids.

.. availability:: Unix, not WASI, not Android.
.. availability:: Unix, not WASI.

.. versionchanged:: 3.16
Support for Android now exists.


.. function:: getsid(pid, /)
Expand All @@ -766,7 +790,10 @@ process and user.

Set the current process's user id.

.. availability:: Unix, not WASI, not Android.
.. availability:: Unix, not WASI.

.. versionchanged:: 3.16
Support for Android now exists.


.. placed in this section since it relates to errno.... a little weak
Expand Down Expand Up @@ -2324,11 +2351,14 @@ features:

Change the root directory of the current process to *path*.

.. availability:: Unix, not WASI, not Android.
.. availability:: Unix, not WASI.

.. versionchanged:: 3.6
Accepts a :term:`path-like object`.

.. versionchanged:: 3.16
Support for Android now exists.


.. function:: fchdir(fd)

Expand Down
5 changes: 4 additions & 1 deletion Doc/library/socket.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1372,10 +1372,13 @@ The :mod:`!socket` module also offers various network-related services:

.. audit-event:: socket.sethostname name socket.sethostname

.. availability:: Unix, not Android.
.. availability:: Unix.

.. versionadded:: 3.3

.. versionchanged:: 3.16
Support for Android now exists.


.. function:: if_nameindex()

Expand Down
10 changes: 10 additions & 0 deletions Doc/using/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,16 @@ See :source:`Platforms/Apple/iOS/README.md`.

Specify the name for the framework (default: ``Python``).

An iOS build configured without ``--enable-framework`` produces a static
``libpython``, for embedding directly in an app binary. Such a build cannot
load extension modules at runtime, and so does not support binary wheels; it
requires ``MODULE_BUILDTYPE=static`` and :option:`--disable-test-modules`, and
rejects :option:`--enable-shared`. See
:source:`Platforms/Apple/iOS/README.md` for the full list of limitations.

.. versionadded:: 3.16
iOS builds may be configured without a framework.


Cross Compiling Options
-----------------------
Expand Down
7 changes: 7 additions & 0 deletions Doc/using/ios.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ should ensure these stub binaries are on your path.
Installing Python on iOS
========================

The official iOS release artefact is a framework build, distributed as an
``XCFramework``; this is the configuration described in the rest of this
document, and the only one that supports binary extension modules. Static
builds, where ``libpython`` and every extension module are linked directly into
the app binary, are also possible, with limitations; see
:source:`Platforms/Apple/iOS/README.md` for details.

Tools for building iOS apps
---------------------------

Expand Down
17 changes: 17 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,14 @@ os
process via a pidfd. Available on Linux 5.6+.
(Contributed by Maurycy Pawłowski-Wieroński in :gh:`149464`.)

* The following functions are now available on Android:
:func:`os.chroot`, :func:`os.initgroups`, :func:`os.setegid`,
:func:`os.seteuid`, :func:`os.setgid`, :func:`os.setregid`,
:func:`os.setresgid`, :func:`os.setresuid`, :func:`os.setreuid`,
and :func:`os.setuid`. Calling them without sufficient privileges
now raises :exc:`PermissionError` instead of the functions being unavailable.
(Contributed by Md Arif in :gh:`152936`.)


pydoc
-----
Expand Down Expand Up @@ -513,6 +521,15 @@ shlex
(Contributed by Jay Berry in :gh:`148846`.)


socket
------

* The :func:`socket.sethostname` function is now available on Android.
Calling it without sufficient privileges now raises :exc:`PermissionError`
instead of the function being unavailable.
(Contributed by Md Arif in :gh:`152936`.)


sqlite3
-------

Expand Down
7 changes: 6 additions & 1 deletion Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
import signal
import socket
import typing
import asyncio
import inspect
import weakref
import builtins
Expand All @@ -102,6 +101,8 @@
from types import CodeType
from warnings import deprecated

lazy import asyncio

try:
import _pyrepl.utils
except ModuleNotFoundError:
Expand Down Expand Up @@ -902,6 +903,10 @@ def _hold_exceptions(self, exceptions):
self._chained_exception_index = 0

def _get_asyncio_task(self):
# If asyncio has never been imported there cannot be a running task,
# so skip the import rather than pay for it on every interaction.
if 'asyncio' not in sys.modules:
return None
try:
task = asyncio.current_task()
except RuntimeError:
Expand Down
4 changes: 3 additions & 1 deletion Lib/tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2196,7 +2196,9 @@ def getmember(self, name):
than once in the archive, its last occurrence is assumed to be the
most up-to-date version.
"""
tarinfo = self._getmember(name.rstrip('/'))
tarinfo = self._getmember(name)
if tarinfo is None and name.endswith('/'):
tarinfo = self._getmember(name.rstrip('/'))
if tarinfo is None:
raise KeyError("filename %r not found" % name)
return tarinfo
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_os/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def test_getresgid(self):
@unittest.skipUnless(hasattr(posix, 'setresuid'),
'test needs posix.setresuid()')
def test_setresuid(self):
# Android blocks this function for non-root users regardless of the arguments.
if support.is_android and os.getuid() != 0:
self.assertRaises(PermissionError, posix.setresuid, -1, -1, -1)
return
current_user_ids = posix.getresuid()
self.assertIsNone(posix.setresuid(*current_user_ids))
# -1 means don't change that value.
Expand All @@ -124,6 +128,10 @@ def test_setresuid_exception(self):
@unittest.skipUnless(hasattr(posix, 'setresgid'),
'test needs posix.setresgid()')
def test_setresgid(self):
# Android blocks this function for non-root users regardless of the arguments.
if support.is_android and os.getuid() != 0:
self.assertRaises(PermissionError, posix.setresgid, -1, -1, -1)
return
current_group_ids = posix.getresgid()
self.assertIsNone(posix.setresgid(*current_group_ids))
# -1 means don't change that value.
Expand Down
38 changes: 38 additions & 0 deletions Lib/test/test_readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,44 @@ def test_write_read_limited_history(self):
# Readline seems to report an additional history element.
self.assertIn(readline.get_current_history_length(), (2, 3))

def test_write_read_zero_length_history(self):
previous_length = readline.get_history_length()
self.addCleanup(readline.set_history_length, previous_length)

readline.clear_history()
readline.add_history("first line")
readline.set_history_length(0)
readline.write_history_file(TESTFN)
self.addCleanup(os.remove, TESTFN)

readline.clear_history()
# libedit cannot read an empty history file, only one that still
# has its header line. How many items remain is not checked:
# libedit's own history_truncate_file() ignores a length of 0.
readline.read_history_file(TESTFN)

@unittest.skipUnless(hasattr(readline, "append_history_file"),
"append_history not available")
def test_append_limited_history(self):
previous_length = readline.get_history_length()
self.addCleanup(readline.set_history_length, previous_length)

readline.clear_history()
readline.add_history("first line")
readline.add_history("second line")
readline.write_history_file(TESTFN)
self.addCleanup(os.remove, TESTFN)

readline.add_history("third line")
readline.set_history_length(2)
readline.append_history_file(1, TESTFN)

readline.clear_history()
readline.read_history_file(TESTFN)
self.assertEqual(readline.get_history_item(1), "second line")
self.assertEqual(readline.get_history_item(2), "third line")
self.assertEqual(readline.get_history_item(3), None)


class TestReadline(unittest.TestCase):

Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,19 @@ def test_add_dir_getmember(self):
self.add_dir_and_getmember('bar')
self.add_dir_and_getmember('a'*101)

def test_extract_name_with_trailing_slash(self):
# gh-127636: './mydir/' is deliberately a regular-file member
# (REGTYPE, not DIRTYPE) whose stored name ends in a slash. It
# extracts as a file. Do not "fix" this by setting DIRTYPE; the
# trailing-slash name on a non-directory is what is being tested.
with tarfile.open(tmpname, 'w') as tar:
tar.addfile(tarfile.TarInfo('./mydir/'))
with os_helper.temp_dir() as tmpdir, tarfile.open(tmpname) as tar:
names = tar.getnames()
self.assertEqual(names, ['./mydir/'])
tar.extract(names[0], tmpdir, filter='fully_trusted')
self.assertTrue(os.path.isfile(os.path.join(tmpdir, 'mydir')))

@unittest.skipUnless(hasattr(os, "getuid") and hasattr(os, "getgid"),
"Missing getuid or getgid implementation")
def add_dir_and_getmember(self, name):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
iOS builds may now be configured without a framework, producing a static
``libpython`` for embedding in an app binary. Such a build cannot load extension
modules at runtime, and requires ``MODULE_BUILDTYPE=static`` and
``--disable-test-modules`` to be requested explicitly. A shared iOS build must
still be a framework build.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix :meth:`tarfile.TarFile.extract` to accept archive member names with a
trailing forward slash, including those returned by
:meth:`tarfile.TarFile.getnames`. Contributed by Xiao Yuan.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:func:`os.chroot`, :func:`os.initgroups`, :func:`os.setegid`,
:func:`os.seteuid`, :func:`os.setgid`, :func:`os.setregid`,
:func:`os.setresgid`, :func:`os.setresuid`, :func:`os.setreuid`,
:func:`os.setuid`, and :func:`socket.sethostname` are now available on
Android. Calling them without sufficient privileges now raises
:exc:`PermissionError` instead of the functions being unavailable.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Speed up :mod:`pdb` startup by only importing :mod:`asyncio` when the program
being debugged has already imported it.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Fix :func:`readline.write_history_file` and
:func:`readline.append_history_file` producing a history file that
:func:`readline.read_history_file` could not load when a limit was set with
:func:`readline.set_history_length` and Python was built against
``libedit``. This works around `NetBSD PR 60322
<https://gnats.netbsd.org/60322>`_.
Loading
Loading