@@ -31,16 +31,22 @@ always available.
31
31
When an auditing event is raised through the :func: `sys.audit ` function, each
32
32
hook will be called in the order it was added with the event name and the
33
33
tuple of arguments. Native hooks added by :c:func: `PySys_AddAuditHook ` are
34
- called first, followed by hooks added in the current interpreter.
34
+ called first, followed by hooks added in the current interpreter. Hooks
35
+ can then log the event, raise an exception to abort the operation,
36
+ or terminate the process entirely.
35
37
36
38
.. audit-event :: sys.addaudithook "" sys.addaudithook
37
39
38
- Raise an auditing event ``sys.addaudithook `` with no arguments. If any
40
+ Calling :func: `sys.addaudithook ` will itself raise an auditing event
41
+ named ``sys.addaudithook `` with no arguments. If any
39
42
existing hooks raise an exception derived from :class: `RuntimeError `, the
40
43
new hook will not be added and the exception suppressed. As a result,
41
44
callers cannot assume that their hook has been added unless they control
42
45
all existing hooks.
43
46
47
+ See the :ref: `audit events table <audit-events >` for all events raised by
48
+ CPython, and :pep: `578 ` for the original design discussion.
49
+
44
50
.. versionadded :: 3.8
45
51
46
52
.. versionchanged :: 3.8.1
@@ -79,14 +85,23 @@ always available.
79
85
80
86
.. index :: single: auditing
81
87
82
- Raise an auditing event with any active hooks. The event name is a string
83
- identifying the event and its associated schema, which is the number and
84
- types of arguments. The schema for a given event is considered public and
85
- stable API and should not be modified between releases.
86
-
87
- This function will raise the first exception raised by any hook. In general,
88
- these errors should not be handled and should terminate the process as
89
- quickly as possible.
88
+ Raise an auditing event and trigger any active auditing hooks.
89
+ *event * is a string identifying the event, and *args * may contain
90
+ optional arguments with more information about the event. The
91
+ number and types of arguments for a given event are considered a
92
+ public and stable API and should not be modified between releases.
93
+
94
+ For example, one auditing event is named ``os.chdir ``. This event has
95
+ one argument called *path * that will contain the requested new
96
+ working directory.
97
+
98
+ :func: `sys.audit ` will call the existing auditing hooks, passing
99
+ the event name and arguments, and will re-raise the first exception
100
+ from any hook. In general, if an exception is raised, it should not
101
+ be handled and the process should be terminated as quickly as
102
+ possible. This allows hook implementations to decide how to respond
103
+ to particular events: they can merely log the event or abort the
104
+ operation by raising an exception.
90
105
91
106
Hooks are added using the :func: `sys.addaudithook ` or
92
107
:c:func: `PySys_AddAuditHook ` functions.
0 commit comments