[3.14] gh-69370: Fix "python -m inspect --details" for unencodable paths (GH-155246) (GH-156606)
It failed with UnicodeEncodeError if the path of the module contains
characters unencodable in the encoding of sys.stdout, e.g. undecodable
bytes of a file name. Such characters are now escaped with backslashes,
unless stdout uses an error handler which can handle them.
(cherry picked from commit abf7a184bd94da4d1a6b54503a27ede1957b48b7)
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>