mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-36842: Implement PEP 578 (GH-12613)
Adds sys.audit, sys.addaudithook, io.open_code, and associated C APIs.
This commit is contained in:
parent
e788057a91
commit
b82e17e626
70 changed files with 3565 additions and 1816 deletions
|
@ -151,6 +151,45 @@ class Availability(Directive):
|
|||
return [pnode]
|
||||
|
||||
|
||||
# Support for documenting audit event
|
||||
|
||||
class AuditEvent(Directive):
|
||||
|
||||
has_content = True
|
||||
required_arguments = 1
|
||||
optional_arguments = 1
|
||||
final_argument_whitespace = True
|
||||
|
||||
_label = [
|
||||
"Raises an :ref:`auditing event <auditing>` {name} with no arguments.",
|
||||
"Raises an :ref:`auditing event <auditing>` {name} with argument {args}.",
|
||||
"Raises an :ref:`auditing event <auditing>` {name} with arguments {args}.",
|
||||
]
|
||||
|
||||
def run(self):
|
||||
if len(self.arguments) >= 2 and self.arguments[1]:
|
||||
args = [
|
||||
"``{}``".format(a.strip())
|
||||
for a in self.arguments[1].strip("'\"").split()
|
||||
if a.strip()
|
||||
]
|
||||
else:
|
||||
args = []
|
||||
|
||||
label = translators['sphinx'].gettext(self._label[min(2, len(args))])
|
||||
text = label.format(name="``{}``".format(self.arguments[0]),
|
||||
args=", ".join(args))
|
||||
|
||||
pnode = nodes.paragraph(text, classes=["audit-hook"])
|
||||
if self.content:
|
||||
self.state.nested_parse(self.content, self.content_offset, pnode)
|
||||
else:
|
||||
n, m = self.state.inline_text(text, self.lineno)
|
||||
pnode.extend(n + m)
|
||||
|
||||
return [pnode]
|
||||
|
||||
|
||||
# Support for documenting decorators
|
||||
|
||||
class PyDecoratorMixin(object):
|
||||
|
@ -424,6 +463,7 @@ def setup(app):
|
|||
app.add_role('source', source_role)
|
||||
app.add_directive('impl-detail', ImplementationDetail)
|
||||
app.add_directive('availability', Availability)
|
||||
app.add_directive('audit-event', AuditEvent)
|
||||
app.add_directive('deprecated-removed', DeprecatedRemoved)
|
||||
app.add_builder(PydocTopicsBuilder)
|
||||
app.add_builder(suspicious.CheckSuspiciousMarkupBuilder)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue