aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/asyncio/format_helpers.py
diff options
context:
space:
mode:
authorPierre Ossman (ThinLinc team) <ossman@cendio.se>2024-02-28 02:39:08 +0100
committerGitHub <noreply@github.com>2024-02-27 17:39:08 -0800
commit5a1559d9493dd298a08c4be32b52295aa3eb89e5 (patch)
tree013e044debb168ed58b68e7c7d75aeec3a9ae626 /Lib/asyncio/format_helpers.py
parenta355f60b032306651ca27bc53bbb82eb5106ff71 (diff)
downloadcpython-5a1559d9493dd298a08c4be32b52295aa3eb89e5.tar.gz
cpython-5a1559d9493dd298a08c4be32b52295aa3eb89e5.zip
gh-112997: Don't log arguments in asyncio unless debugging (#115667)
Nothing else in Python generally logs the contents of variables, so this can be very unexpected for developers and could leak sensitive information in to terminals and log files.
Diffstat (limited to 'Lib/asyncio/format_helpers.py')
-rw-r--r--Lib/asyncio/format_helpers.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/Lib/asyncio/format_helpers.py b/Lib/asyncio/format_helpers.py
index 27d11fd4fa9..93737b7708a 100644
--- a/Lib/asyncio/format_helpers.py
+++ b/Lib/asyncio/format_helpers.py
@@ -19,19 +19,26 @@ def _get_function_source(func):
return None
-def _format_callback_source(func, args):
- func_repr = _format_callback(func, args, None)
+def _format_callback_source(func, args, *, debug=False):
+ func_repr = _format_callback(func, args, None, debug=debug)
source = _get_function_source(func)
if source:
func_repr += f' at {source[0]}:{source[1]}'
return func_repr
-def _format_args_and_kwargs(args, kwargs):
+def _format_args_and_kwargs(args, kwargs, *, debug=False):
"""Format function arguments and keyword arguments.
Special case for a single parameter: ('hello',) is formatted as ('hello').
+
+ Note that this function only returns argument details when
+ debug=True is specified, as arguments may contain sensitive
+ information.
"""
+ if not debug:
+ return '()'
+
# use reprlib to limit the length of the output
items = []
if args:
@@ -41,10 +48,11 @@ def _format_args_and_kwargs(args, kwargs):
return '({})'.format(', '.join(items))
-def _format_callback(func, args, kwargs, suffix=''):
+def _format_callback(func, args, kwargs, *, debug=False, suffix=''):
if isinstance(func, functools.partial):
- suffix = _format_args_and_kwargs(args, kwargs) + suffix
- return _format_callback(func.func, func.args, func.keywords, suffix)
+ suffix = _format_args_and_kwargs(args, kwargs, debug=debug) + suffix
+ return _format_callback(func.func, func.args, func.keywords,
+ debug=debug, suffix=suffix)
if hasattr(func, '__qualname__') and func.__qualname__:
func_repr = func.__qualname__
@@ -53,7 +61,7 @@ def _format_callback(func, args, kwargs, suffix=''):
else:
func_repr = repr(func)
- func_repr += _format_args_and_kwargs(args, kwargs)
+ func_repr += _format_args_and_kwargs(args, kwargs, debug=debug)
if suffix:
func_repr += suffix
return func_repr