Skip to content

Commit d542a9b

Browse files
authored
[3.11] gh-121957: Emit audit events for python -i and python -m asyncio (GH-122118)
1 parent 1b0e63c commit d542a9b

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.11.10 (also 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
@@ -697,6 +697,11 @@ conflict.
697697
This variable can also be modified by Python code using :data:`os.environ`
698698
to force inspect mode on program termination.
699699

700+
.. audit-event:: cpython.run_stdin "" ""
701+
702+
.. versionchanged:: 3.11.10 (also 3.10.15, 3.9.20, and 3.8.20)
703+
Emits audit events.
704+
700705

701706
.. envvar:: PYTHONUNBUFFERED
702707

Lib/asyncio/__main__.py

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

9191

9292
if __name__ == '__main__':
93+
sys.audit("cpython.run_stdin")
94+
9395
loop = asyncio.new_event_loop()
9496
asyncio.set_event_loop(loop)
9597

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
@@ -531,6 +531,10 @@ pymain_repl(PyConfig *config, int *exitcode)
531531
return;
532532
}
533533

534+
if (PySys_Audit("cpython.run_stdin", NULL) < 0) {
535+
return;
536+
}
537+
534538
PyCompilerFlags cf = _PyCompilerFlags_INIT;
535539
int res = PyRun_AnyFileFlags(stdin, "<stdin>", &cf);
536540
*exitcode = (res != 0);

0 commit comments

Comments
 (0)