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

Audit Hook doc typos and confusion #83073

Closed
terryjreedy opened this issue Nov 22, 2019 · 6 comments
Closed

Audit Hook doc typos and confusion #83073

terryjreedy opened this issue Nov 22, 2019 · 6 comments
Labels
3.8 only security fixes 3.9 only security fixes docs Documentation in the Doc dir interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@terryjreedy
Copy link
Member

BPO 38892
Nosy @terryjreedy, @tiran, @zooba, @miss-islington
PRs
  • bpo-38892: Improve docs for audit event #17361
  • [3.8] bpo-38892: Improve docs for audit event (GH-17361) #17391
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-11-26.17:12:35.884>
    created_at = <Date 2019-11-22.02:32:59.747>
    labels = ['interpreter-core', 'type-bug', '3.8', '3.9', 'docs']
    title = 'Audit Hook doc typos and confusion'
    updated_at = <Date 2019-11-26.17:14:54.934>
    user = 'https://github.com/terryjreedy'

    bugs.python.org fields:

    activity = <Date 2019-11-26.17:14:54.934>
    actor = 'miss-islington'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2019-11-26.17:12:35.884>
    closer = 'steve.dower'
    components = ['Documentation', 'Interpreter Core']
    creation = <Date 2019-11-22.02:32:59.747>
    creator = 'terry.reedy'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 38892
    keywords = ['patch']
    message_count = 6.0
    messages = ['357240', '357341', '357357', '357513', '357515', '357516']
    nosy_count = 5.0
    nosy_names = ['terry.reedy', 'christian.heimes', 'docs@python', 'steve.dower', 'miss-islington']
    pr_nums = ['17361', '17391']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue38892'
    versions = ['Python 3.8', 'Python 3.9']

    @terryjreedy
    Copy link
    Member Author

    Some suggestions for
    https://docs.python.org/3.9/c-api/sys.html#c.PySys_AddAuditHook
    https://docs.python.org/3.9/library/sys.html#sys.addaudithook

    "Adds to the collection of active auditing hooks"
    "Adds the callable hook to the collection of active auditing hooks"

    Change 'Adds' to 'Add' or maybe 'Append' (see near below).
    Insert 'the callable hook' in PySys version.
    Change 'collection' to 'sequence' or 'list' (and change verb to 'append') since order is important.

    PySys version:

    I think the 'userData' explanation should be closer to the top.

    Grammar: "Functions in the runtime and standard library that raise events include the details in each function’s documentation and listed in the audit events table." is not a proper sentence. Its 'skeleton' is "Functions ... include the details ... and listed ... .

    Either change 'include the details' to 'are detailed' and 'listed' to 'are listed' or split into two sentences:

    "Functions in the runtime and standard library that raise events are listed in the audit events table. Details are in each function’s documentation.

    Both, again:

    "raises a auditing event". 'a' should be 'an'. To me, this is slightly confusing because Python raises exceptions, but auditing events are not exceptions and do not normally abort execution. Perhaps "This call is a 'sys.addaudithook' event with no arguments that triggers an audit call."

    https://docs.python.org/3.9/c-api/sys.html#c.PySys_Audit
    https://docs.python.org/3.9/library/sys.html#sys.audit

    Change 'Raises' to 'Raise'.

    https://docs.python.org/3.8/library/audit_events.html

    On pydev, Steve said "(though some won't be raised until 3.8.1... we should probably mark those, or at least update that page to warn that events may have been added over time)."

    @terryjreedy terryjreedy added 3.8 only security fixes 3.9 only security fixes labels Nov 22, 2019
    @terryjreedy terryjreedy added docs Documentation in the Doc dir interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Nov 22, 2019
    @zooba
    Copy link
    Member

    zooba commented Nov 22, 2019

    Thanks Terry, this is great!

    Agree with everything apart from not liking "raise" - I think "raise an event" is totally fine usage, and certainly better than "triggers an audit call" (since it may not, if nobody's listening). Plus PEP-578 is full of "raise", and we're not going to go edit all of that :)

    @terryjreedy
    Copy link
    Member Author

    I agree on consistency. I will make a PR for you to review.

    Do you think a minimal code example might help? Running ...

    import sys
    
    def hook(name, args):
        if name.startswith('compile'):
            print(name, args)
    
    sys.addaudithook(hook)
    compile('a = 1', '<dummy>', 'exec')

    # prints

    compile (b'a = 1', '<dummy>')

    My own interest is learning about the socket connecting an IDLE GUI process and the user code run process. The following in the two startup files:

    def hook(name, args):
        if name.startswith('socket'):
            print('I', name, args)  # I/R in the IDLE/run processes.
    sys.addaudithook(hook)

    results in:

    I socket.gethostname ()
    R socket.gethostname ()
    I socket.bind (<socket.socket fd=796, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0>, ('127.0.0.1', 0))
    R socket.bind (<socket.socket fd=796, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0>, ('127.0.0.1', 0))
    R socket.connect (<socket.socket fd=816, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0>, ('127.0.0.1', 62119))
    I socket.__new__ (<socket.socket fd=-1, family=AddressFamily.AF_UNSPEC, type=0, proto=0>, 2, 1, 0)
    R socket.__new__ (<socket.socket fd=-1, family=AddressFamily.AF_UNSPEC, type=0, proto=0>, 2, 1, 0)

    To go further, I might wrap socket.socket.send/recv with functions that call sys.audit.

    @zooba
    Copy link
    Member

    zooba commented Nov 26, 2019

    New changeset e563a15 by Steve Dower (Terry Jan Reedy) in branch 'master':
    bpo-38892: Improve docs for audit event (GH-17361)
    e563a15

    @zooba
    Copy link
    Member

    zooba commented Nov 26, 2019

    Thanks Terry!

    @zooba zooba closed this as completed Nov 26, 2019
    @miss-islington
    Copy link
    Contributor

    New changeset 86d9933 by Miss Islington (bot) in branch '3.8':
    bpo-38892: Improve docs for audit event (GH-17361)
    86d9933

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes 3.9 only security fixes docs Documentation in the Doc dir interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants