Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.10] gh-121957: Emit audit events for python -i and python -m asyncio #122119

Merged
merged 1 commit into from
Jul 22, 2024
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
9 changes: 9 additions & 0 deletions Doc/library/asyncio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Additionally, there are **low-level** APIs for
* :ref:`bridge <asyncio-futures>` callback-based libraries and code
with async/await syntax.

.. _asyncio-cli:

.. rubric:: asyncio REPL

You can experiment with an ``asyncio`` concurrent context in the REPL:

.. code-block:: pycon
Expand All @@ -68,6 +72,11 @@ You can experiment with an ``asyncio`` concurrent context in the REPL:
>>> await asyncio.sleep(10, result='hello')
'hello'

.. audit-event:: cpython.run_stdin "" ""

.. versionchanged:: 3.10.15 (also 3.9.20, and 3.8.20)
Emits audit events.

.. We use the "rubric" directive here to avoid creating
the "Reference" subsection in the TOC.

Expand Down
5 changes: 5 additions & 0 deletions Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,11 @@ conflict.
This variable can also be modified by Python code using :data:`os.environ`
to force inspect mode on program termination.

.. audit-event:: cpython.run_stdin "" ""

.. versionchanged:: 3.10.15 (also 3.9.20, and 3.8.20)
Emits audit events.


.. envvar:: PYTHONUNBUFFERED

Expand Down
2 changes: 2 additions & 0 deletions Lib/asyncio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def run(self):


if __name__ == '__main__':
sys.audit("cpython.run_stdin")

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed missing audit events around interactive use of Python, now also
properly firing for ``python -i``, as well as for ``python -m asyncio``. The
event in question is ``cpython.run_stdin``.
4 changes: 4 additions & 0 deletions Modules/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,10 @@ pymain_repl(PyConfig *config, int *exitcode)
return;
}

if (PySys_Audit("cpython.run_stdin", NULL) < 0) {
return;
}

PyCompilerFlags cf = _PyCompilerFlags_INIT;
int res = PyRun_AnyFileFlags(stdin, "<stdin>", &cf);
*exitcode = (res != 0);
Expand Down
Loading