Skip to content

Commit c1e834d

Browse files
authored
[3.12] gh-121957: Emit audit events for python -i and python -m asyncio (GH-122117)
1 parent 6e9b3f7 commit c1e834d

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

Doc/library/asyncio.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ Additionally, there are **low-level** APIs for
5656
* :ref:`bridge <asyncio-futures>` callback-based libraries and code
5757
with async/await syntax.
5858

59+
.. include:: ../includes/wasm-notavail.rst
60+
5961
.. _asyncio-cli:
6062

63+
.. rubric:: asyncio REPL
64+
6165
You can experiment with an ``asyncio`` concurrent context in the REPL:
6266

6367
.. code-block:: pycon
@@ -70,7 +74,10 @@ You can experiment with an ``asyncio`` concurrent context in the REPL:
7074
>>> await asyncio.sleep(10, result='hello')
7175
'hello'
7276
73-
.. include:: ../includes/wasm-notavail.rst
77+
.. audit-event:: cpython.run_stdin "" ""
78+
79+
.. versionchanged:: 3.12.5 (also 3.11.10, 3.10.15, 3.9.20, and 3.8.20)
80+
Emits audit events.
7481

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

Doc/using/cmdline.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,11 @@ conflict.
720720
This variable can also be modified by Python code using :data:`os.environ`
721721
to force inspect mode on program termination.
722722

723+
.. audit-event:: cpython.run_stdin "" ""
724+
725+
.. versionchanged:: 3.12.5 (also 3.11.10, 3.10.15, 3.9.20, and 3.8.20)
726+
Emits audit events.
727+
723728

724729
.. envvar:: PYTHONUNBUFFERED
725730

Lib/asyncio/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ def run(self):
8989

9090

9191
if __name__ == '__main__':
92+
sys.audit("cpython.run_stdin")
93+
9294
loop = asyncio.new_event_loop()
9395
asyncio.set_event_loop(loop)
9496

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed missing audit events around interactive use of Python, now also
2+
properly firing for ``python -i``, as well as for ``python -m asyncio``. The
3+
event in question is ``cpython.run_stdin``.

Modules/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,10 @@ pymain_repl(PyConfig *config, int *exitcode)
540540
return;
541541
}
542542

543+
if (PySys_Audit("cpython.run_stdin", NULL) < 0) {
544+
return;
545+
}
546+
543547
PyCompilerFlags cf = _PyCompilerFlags_INIT;
544548
int res = PyRun_AnyFileFlags(stdin, "<stdin>", &cf);
545549
*exitcode = (res != 0);

0 commit comments

Comments
 (0)