diff options
author | Saiyang Gou <gousaiyang@163.com> | 2021-04-23 10:19:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-23 10:19:08 (GMT) |
commit | 927b841c215a1ca36c9b3203eadc67ce05b1ed07 (patch) | |
tree | dd5ff8d45bb64842451574b82eaac25a7b5dfd59 /Lib/test/audit-tests.py | |
parent | 32980fb669a6857276da18895fcc0cb6f6fbb544 (diff) | |
download | cpython-927b841c215a1ca36c9b3203eadc67ce05b1ed07.zip cpython-927b841c215a1ca36c9b3203eadc67ce05b1ed07.tar.gz cpython-927b841c215a1ca36c9b3203eadc67ce05b1ed07.tar.bz2 |
bpo-37363: Add audit events to the `http.client` module (GH-21321)
Add audit events to the `http.client` module
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Diffstat (limited to 'Lib/test/audit-tests.py')
-rw-r--r-- | Lib/test/audit-tests.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/audit-tests.py b/Lib/test/audit-tests.py index 8e66594..2addf97 100644 --- a/Lib/test/audit-tests.py +++ b/Lib/test/audit-tests.py @@ -341,6 +341,24 @@ def test_gc(): gc.get_referents(y) +def test_http_client(): + import http.client + + def hook(event, args): + if event.startswith("http.client."): + print(event, *args[1:]) + + sys.addaudithook(hook) + + conn = http.client.HTTPConnection('www.python.org') + try: + conn.request('GET', '/') + except OSError: + print('http.client.send', '[cannot send]') + finally: + conn.close() + + if __name__ == "__main__": from test.support import suppress_msvcrt_asserts |